From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAF45C636CD for ; Tue, 7 Feb 2023 09:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbjBGJdZ (ORCPT ); Tue, 7 Feb 2023 04:33:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231342AbjBGJdV (ORCPT ); Tue, 7 Feb 2023 04:33:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D03D1F900 for ; Tue, 7 Feb 2023 01:33:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AD2B661268 for ; Tue, 7 Feb 2023 09:33:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98A04C433D2; Tue, 7 Feb 2023 09:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675762398; bh=OdT3nRGnHot2mPmdQT7AdRE1giJFdZCCF7xPEIGOJuU=; h=Subject:To:Cc:From:Date:From; b=VT4qXu/NrL60rvBUpNhgWehY47QywUkA8epSSwu7bBBGJ9ShCxreg42FiKMI07Knh gH5vlZO4zaiRxy7AMewD5nFmVE6/q8eZD1YjLDCyTynFZ1nKLfJYrV1Rc6vBd/ev8h 3ZERAW9aoZwYlwl89SX/zAJXY5hLgKfHdh/qGnbQ= Subject: FAILED: patch "[PATCH] nvmem: core: fix registration vs use race" failed to apply to 5.4-stable tree To: rmk+kernel@armlinux.org.uk, gregkh@linuxfoundation.org, srinivas.kandagatla@linaro.org Cc: From: Date: Tue, 07 Feb 2023 10:33:10 +0100 Message-ID: <167576239023224@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch below does not apply to the 5.4-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . Possible dependencies: ab3428cfd9aa ("nvmem: core: fix registration vs use race") 560181d3ace6 ("nvmem: core: fix cleanup after dev_set_name()") 569653f022a2 ("nvmem: core: remove nvmem_config wp_gpio") 3bd747c7ea13 ("nvmem: core: initialise nvmem->id early") 5544e90c8126 ("nvmem: core: add error handling for dev_set_name") bd1244561fa2 ("nvmem: core: Fix memleak in nvmem_register()") f6c052afe6f8 ("nvmem: core: Fix a conflict between MTD and NVMEM on wp-gpios property") de0534df9347 ("nvmem: core: fix error handling while validating keepout regions") 1333a6779501 ("nvmem: core: allow specifying of_node") fd3bb8f54a88 ("nvmem: core: Add support for keepout regions") 1eb51d6a4fce ("nvmem: switch to simpler IDA interface") 731aa3fae813 ("nvmem: core: add support to auto devid") b96fc5416b09 ("nvmem: ensure sysfs writes handle write-protect pin") 844003052719 ("nvmem: core: remove nvmem_sysfs_get_groups()") 664f0549380c ("nvmem: core: use is_bin_visible for permissions") f60442ddc40c ("nvmem: core: use device_register and device_unregister") e6de179d7a88 ("nvmem: core: add root_only member to nvmem device struct") 3c91ef69a3e9 ("nvmem: check for NULL reg_read and reg_write before dereferencing") a9c3766cb19c ("nvmem: release the write-protect pin") f7d8d7dcd978 ("nvmem: fix memory leak in error path") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From ab3428cfd9aa2f3463ee4b2909b5bb2193bd0c4a Mon Sep 17 00:00:00 2001 From: "Russell King (Oracle)" Date: Fri, 27 Jan 2023 10:40:11 +0000 Subject: [PATCH] nvmem: core: fix registration vs use race The i.MX6 CPU frequency driver sometimes fails to register at boot time due to nvmem_cell_read_u32() sporadically returning -ENOENT. This happens because there is a window where __nvmem_device_get() in of_nvmem_cell_get() is able to return the nvmem device, but as cells have been setup, nvmem_find_cell_entry_by_node() returns NULL. The occurs because the nvmem core registration code violates one of the fundamental principles of kernel programming: do not publish data structures before their setup is complete. Fix this by making nvmem core code conform with this principle. Fixes: eace75cfdcf7 ("nvmem: Add a simple NVMEM framework for nvmem providers") Cc: stable@vger.kernel.org Signed-off-by: Russell King (Oracle) Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20230127104015.23839-7-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index ac77a019aed7..e92c6f1aadbb 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -832,22 +832,16 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->dev.groups = nvmem_dev_groups; #endif - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); - - rval = device_add(&nvmem->dev); - if (rval) - goto err_put_device; - if (nvmem->nkeepout) { rval = nvmem_validate_keepouts(nvmem); if (rval) - goto err_device_del; + goto err_put_device; } if (config->compat) { rval = nvmem_sysfs_setup_compat(nvmem, config); if (rval) - goto err_device_del; + goto err_put_device; } if (config->cells) { @@ -864,6 +858,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; + dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); + + rval = device_add(&nvmem->dev); + if (rval) + goto err_remove_cells; + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); return nvmem; @@ -873,8 +873,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); -err_device_del: - device_del(&nvmem->dev); err_put_device: put_device(&nvmem->dev);