From nobody Tue Sep 16 12:32:14 2025 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 E5170C3DA7D for ; Tue, 3 Jan 2023 16:59:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233758AbjACQ7Y (ORCPT ); Tue, 3 Jan 2023 11:59:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230373AbjACQ7V (ORCPT ); Tue, 3 Jan 2023 11:59:21 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F244CC5B for ; Tue, 3 Jan 2023 08:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4rZt+/ZOnctX5K9vzjEgIu7kKeqecmK58ZccPLFcCgE=; b=jrKPRdfl9oSkIlnbr1BQ99/P85 92wmbko73cvAHWp+40eG6orzloOXrLKx4XVkXXl3NwiReUBgRMloLinJqmxLYq5zA9lzKlGj/rU2Y CLmBjhZJdROUmEmFk8mHMtadVyL2FBXhJFKuikxuOrOPdvBqrSJX8uU99bvKpnvwLTXLWjmvt64EQ MEcHO/Awk5nhKCkqRHGCEc/0tUYWHrqlmhX48+9gld8Q+Qqmvwghw7/5wi8deuT9KpHUOyBq+H6Vw Smd87KHfplLNrwTj8xuN1GVvUDyDx628W3Mt6t+bKpuEIod5QSxsUdEztdcSKGhdGWh9oYZ0NjY1F S9jLhkNA==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:32780 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pCkdB-0005bv-TH; Tue, 03 Jan 2023 16:59:17 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1pCkdA-004huk-Ta; Tue, 03 Jan 2023 16:59:16 +0000 In-Reply-To: References: From: "Russell King (Oracle)" To: Srinivas Kandagatla Cc: Bartosz Golaszewski , Gaosheng Cui , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxime Ripard , Hector Martin Subject: [PATCH v3 1/5] nvmem: core: remove spurious white space Bartosz Golaszewski ,Gaosheng Cui ,Greg Kroah-Hartman ,linux-arm-kernel@lists.infradead.org,linux-kernel@vger.kernel.org,Maxime Ripard , Hector Martin MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Tue, 03 Jan 2023 16:59:16 +0000 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove a spurious white space in for the ida_alloc() call. Signed-off-by: Russell King (Oracle) --- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 321d7d63e068..bf11e0c36d60 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -764,7 +764,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) if (!nvmem) return ERR_PTR(-ENOMEM); =20 - rval =3D ida_alloc(&nvmem_ida, GFP_KERNEL); + rval =3D ida_alloc(&nvmem_ida, GFP_KERNEL); if (rval < 0) { kfree(nvmem); return ERR_PTR(rval); --=20 2.30.2 From nobody Tue Sep 16 12:32:14 2025 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 35CDCC3DA7D for ; Tue, 3 Jan 2023 16:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233805AbjACQ7b (ORCPT ); Tue, 3 Jan 2023 11:59:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230373AbjACQ71 (ORCPT ); Tue, 3 Jan 2023 11:59:27 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AD5012AE8 for ; Tue, 3 Jan 2023 08:59:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZS5H2asUTLZlbBEYJrrAV+i8ORfv/vUr4mwUuUH/Xa4=; b=u0FP7KO7xgXz/q1vqsICXY31OM nDIij8oKF/E3R0qNscFrCaRYqUMysaVqsCwQTNOmKL3Cgvk57s7EqYOGNkVugAMnYh9T5khmIqofQ 7W4tMPkyYz4TU3oqGZd6LhN2u/U7cd/xa2j2CnCUDBQqJXU7KEJ7JaHSnPp19GK3ohsCAPW24A/hb MU//WZZowbzKQdORkN0AH03mo+D6PEHyntsfZHr6/3pLYT8eV/u+gkwanHt7pNWK010jCMdwo3Qw/ 3Qh6bCteN03nxKE82MSpUS7X52sjCaMS3leR5xxk5uHaIrFoN7qMJVkYAIus25xDtwPhAVdKxI4q5 yuF63Fgg==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:32796 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pCkdG-0005c7-Vh; Tue, 03 Jan 2023 16:59:22 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1pCkdG-004huq-0l; Tue, 03 Jan 2023 16:59:22 +0000 In-Reply-To: References: From: "Russell King (Oracle)" To: Srinivas Kandagatla Cc: Bartosz Golaszewski , Gaosheng Cui , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxime Ripard , Hector Martin Subject: [PATCH v3 2/5] nvmem: core: initialise nvmem->id early Bartosz Golaszewski ,Gaosheng Cui ,Greg Kroah-Hartman ,linux-arm-kernel@lists.infradead.org,linux-kernel@vger.kernel.org,Maxime Ripard , Hector Martin MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Tue, 03 Jan 2023 16:59:22 +0000 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The error path for wp_gpio attempts to free the IDA nvmem->id, but this has yet to be assigned, so will always be zero - leaking the ID allocated by ida_alloc(). Fix this by moving the initialisation of nvmem->id earlier. Fixes: f7d8d7dcd978 ("nvmem: fix memory leak in error path") Signed-off-by: Russell King (Oracle) --- drivers/nvmem/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index bf11e0c36d60..c1a40d9c3825 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -770,6 +770,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) return ERR_PTR(rval); } =20 + nvmem->id =3D rval; + if (config->wp_gpio) nvmem->wp_gpio =3D config->wp_gpio; else if (!config->ignore_wp) @@ -785,7 +787,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); =20 - nvmem->id =3D rval; nvmem->owner =3D config->owner; if (!nvmem->owner && config->dev->driver) nvmem->owner =3D config->dev->driver->owner; --=20 2.30.2 From nobody Tue Sep 16 12:32:14 2025 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 B9C2EC3DA7D for ; Tue, 3 Jan 2023 16:59:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237883AbjACQ7e (ORCPT ); Tue, 3 Jan 2023 11:59:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230373AbjACQ7b (ORCPT ); Tue, 3 Jan 2023 11:59:31 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51FB011C2C for ; Tue, 3 Jan 2023 08:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KxDyg/GasjWDjvCU9MW5uVhbKubIVJtCyCcgRXieImg=; b=Y16nKBoLPskcCMgvh0caSjOwkI fT2US/T+l9T2zro22ZrHvU0n/XqIqaClSz9ehNxn66ilkEHexwN/08jCD4rv+X0+PMmMOudqsvzqt wPSMUtDR0bCJAhtkky77qHqBKdFdgSxFr4pxku+cEUk+vchFfyd45AmjL/EJopEd2meFmX/NnEof7 DNYahTLddJ/OYOvIb0uqvet4RqWrQ9/TRYs1v9Assw45wjUzcZqqtTtojRNbY23pVJP2Ck77+Z10U +S92GpzCJ78UcwN+qxsiUpeNwGBV2bMRA2IaCyBiU4LMW0QHzTVLz3v5bmegzY1l9GsupzZr7nlbS jxciwatQ==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:33942 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pCkdM-0005cJ-2W; Tue, 03 Jan 2023 16:59:27 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1pCkdL-004huw-4D; Tue, 03 Jan 2023 16:59:27 +0000 In-Reply-To: References: From: "Russell King (Oracle)" To: Srinivas Kandagatla Cc: Bartosz Golaszewski , Gaosheng Cui , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxime Ripard , Hector Martin Subject: [PATCH v3 3/5] nvmem: core: remove nvmem_config wp_gpio Bartosz Golaszewski ,Gaosheng Cui ,Greg Kroah-Hartman ,linux-arm-kernel@lists.infradead.org,linux-kernel@vger.kernel.org,Maxime Ripard , Hector Martin MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Tue, 03 Jan 2023 16:59:27 +0000 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No one provides wp_gpio, so let's remove it to avoid issues with the nvmem core putting this gpio. Signed-off-by: Russell King (Oracle) --- drivers/nvmem/core.c | 4 +--- include/linux/nvmem-provider.h | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index c1a40d9c3825..843e2f5696e6 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -772,9 +772,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) =20 nvmem->id =3D rval; =20 - if (config->wp_gpio) - nvmem->wp_gpio =3D config->wp_gpio; - else if (!config->ignore_wp) + if (!config->ignore_wp) nvmem->wp_gpio =3D gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); if (IS_ERR(nvmem->wp_gpio)) { diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 50caa117cb62..bb15c9234e21 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -70,7 +70,6 @@ struct nvmem_keepout { * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. * @priv: User context passed to read/write callbacks. - * @wp-gpio: Write protect pin * @ignore_wp: Write Protect pin is managed by the provider. * * Note: A default "nvmem" name will be assigned to the device if @@ -85,7 +84,6 @@ struct nvmem_config { const char *name; int id; struct module *owner; - struct gpio_desc *wp_gpio; const struct nvmem_cell_info *cells; int ncells; const struct nvmem_keepout *keepout; --=20 2.30.2 From nobody Tue Sep 16 12:32:14 2025 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 03E94C3DA7D for ; Tue, 3 Jan 2023 16:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238072AbjACQ7q (ORCPT ); Tue, 3 Jan 2023 11:59:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233799AbjACQ7j (ORCPT ); Tue, 3 Jan 2023 11:59:39 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 817E412D31 for ; Tue, 3 Jan 2023 08:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xnsILhgbGTIfPEYE6RKFK2VhHpdsOwIbKPY7NWU3suM=; b=Xxsb8olBBhvLNZjhVcaGkPpsE3 INNuU2k9vTPJQd0uwpxcT+rA/as81eG4YHMSitNy9JKCJcM28XaOPGpK7bwTAm/GsrsY4UQLN39sF 2reuK5a+r66lSmYH5g9nRB2fFHhljxk0VpRYuxiOZbu0EgWxVNQuHshovLtCAvrutJE5KJ2IpJddT PZnMiP5zbNTsi5ARuHv6v1JkmdM5ZNKeZSy/ZwpBdhSoF3oBYLngWPhsvfQBXdNEl1aRxHd9ruU/y Mg1l8TUr4/2cOGubhE5BXDCPjLEJpOw+6c13e0YrrcJKweVsiC6Y3Ky0+gonwD9NZ3EJXR+I3Q0HF KnQ9d8lA==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:33956 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pCkdR-0005cY-87; Tue, 03 Jan 2023 16:59:32 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1pCkdQ-004hv8-7U; Tue, 03 Jan 2023 16:59:32 +0000 In-Reply-To: References: From: "Russell King (Oracle)" To: Srinivas Kandagatla Cc: Bartosz Golaszewski , Gaosheng Cui , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxime Ripard , Hector Martin Subject: [PATCH v3 4/5] nvmem: core: fix cleanup after dev_set_name() Bartosz Golaszewski ,Gaosheng Cui ,Greg Kroah-Hartman ,linux-arm-kernel@lists.infradead.org,linux-kernel@vger.kernel.org,Maxime Ripard , Hector Martin MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Tue, 03 Jan 2023 16:59:32 +0000 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If dev_set_name() fails, we leak nvmem->wp_gpio as the cleanup does not put this. While a minimal fix for this would be to add the gpiod_put() call, we can do better if we split device_register(), and use the tested nvmem_release() cleanup code by initialising the device early, and putting the device. This results in a slightly larger fix, but results in clear code. Note: this patch depends on "nvmem: core: initialise nvmem->id early" and "nvmem: core: remove nvmem_config wp_gpio". Fixes: 5544e90c8126 ("nvmem: core: add error handling for dev_set_name") Signed-off-by: Russell King (Oracle) --- drivers/nvmem/core.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 843e2f5696e6..19497f555e07 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -772,15 +772,17 @@ struct nvmem_device *nvmem_register(const struct nvme= m_config *config) =20 nvmem->id =3D rval; =20 + nvmem->dev.type =3D &nvmem_provider_type; + nvmem->dev.bus =3D &nvmem_bus_type; + nvmem->dev.parent =3D config->dev; + + device_initialize(&nvmem->dev); + if (!config->ignore_wp) nvmem->wp_gpio =3D gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); - if (IS_ERR(nvmem->wp_gpio)) { - ida_free(&nvmem_ida, nvmem->id); - rval =3D PTR_ERR(nvmem->wp_gpio); - kfree(nvmem); - return ERR_PTR(rval); - } + if (IS_ERR(nvmem->wp_gpio)) + goto err_put_device; =20 kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); @@ -791,9 +793,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) nvmem->stride =3D config->stride ?: 1; nvmem->word_size =3D config->word_size ?: 1; nvmem->size =3D config->size; - nvmem->dev.type =3D &nvmem_provider_type; - nvmem->dev.bus =3D &nvmem_bus_type; - nvmem->dev.parent =3D config->dev; nvmem->root_only =3D config->root_only; nvmem->priv =3D config->priv; nvmem->type =3D config->type; @@ -821,11 +820,8 @@ struct nvmem_device *nvmem_register(const struct nvmem= _config *config) break; } =20 - if (rval) { - ida_free(&nvmem_ida, nvmem->id); - kfree(nvmem); - return ERR_PTR(rval); - } + if (rval) + goto err_put_device; =20 nvmem->read_only =3D device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write; @@ -836,7 +832,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) =20 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); =20 - rval =3D device_register(&nvmem->dev); + rval =3D device_add(&nvmem->dev); if (rval) goto err_put_device; =20 --=20 2.30.2 From nobody Tue Sep 16 12:32:14 2025 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 85107C3DA7D for ; Tue, 3 Jan 2023 16:59:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238238AbjACQ7v (ORCPT ); Tue, 3 Jan 2023 11:59:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238168AbjACQ7n (ORCPT ); Tue, 3 Jan 2023 11:59:43 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1F1E13CF0 for ; Tue, 3 Jan 2023 08:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=iEP3KCcIVyEejeSlu7Gu5rS787gtmtbFIPKVaN+x0Fw=; b=yGhj8cyLqUStiPXDvK+FYSdLrS 4tdfWIP2WcJbFrsoAOeeBhVrgKOMKab9o0ATNWRK9ciyb9lzFOISRcmbEgqDqzmz8riba+nKBrGXF BCjlakQhprzZkbomupUCzBgim1YRRMHlQvLxlbjOKG63wAWPUWR7CMgGb8v70s+Fl0KQ3irrdYuut zgUWkPElWw4eR1vBunO66WG3fPfJTjqo3UDDEDeWS5NhaMCVu2Vhgb8BVQTRr6xA48S/98K1jnjZY e/fS+RKEFRi8qNUjS5FcrJSnlCG8daTqSg31D9Ig+ew5qZjSVFyJUGsnxxIf897Obxd/kA2pEe5f3 1kBBGKyA==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:39580 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pCkdW-0005cj-Be; Tue, 03 Jan 2023 16:59:38 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1pCkdV-004hwd-Cx; Tue, 03 Jan 2023 16:59:37 +0000 In-Reply-To: References: From: "Russell King (Oracle)" To: Srinivas Kandagatla Cc: Bartosz Golaszewski , Gaosheng Cui , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxime Ripard , Hector Martin Subject: [PATCH v3 5/5] nvmem: core: fix registration vs use race Bartosz Golaszewski ,Gaosheng Cui ,Greg Kroah-Hartman ,linux-arm-kernel@lists.infradead.org,linux-kernel@vger.kernel.org,Maxime Ripard , Hector Martin MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Tue, 03 Jan 2023 16:59:37 +0000 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 provide= rs") Signed-off-by: Russell King (Oracle) --- drivers/nvmem/core.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 19497f555e07..082cda7ac199 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -830,22 +830,16 @@ struct nvmem_device *nvmem_register(const struct nvme= m_config *config) nvmem->dev.groups =3D nvmem_dev_groups; #endif =20 - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); - - rval =3D device_add(&nvmem->dev); - if (rval) - goto err_put_device; - if (nvmem->nkeepout) { rval =3D nvmem_validate_keepouts(nvmem); if (rval) - goto err_device_del; + goto err_put_device; } =20 if (config->compat) { rval =3D nvmem_sysfs_setup_compat(nvmem, config); if (rval) - goto err_device_del; + goto err_put_device; } =20 if (config->cells) { @@ -862,6 +856,12 @@ struct nvmem_device *nvmem_register(const struct nvmem= _config *config) if (rval) goto err_remove_cells; =20 + dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); + + rval =3D device_add(&nvmem->dev); + if (rval) + goto err_remove_cells; + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); =20 return nvmem; @@ -871,8 +871,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); =20 --=20 2.30.2