From patchwork Tue Jan 3 16:59:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13087831 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 150F4C54EBD for ; Tue, 3 Jan 2023 18:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:Message-Id: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-Owner; bh=HaOxp+bKhRyUu08Oyo9L40C6jgCVNqgUyZ69bU2h8Po=; b=LRi0+UHMV6OyFY TMTr7CaDeXYpRxvLSefH9BgF83Z0Hteoznv03Si4FYwy7KSL47/nmzAPDz8agfHpX90lKvm7dfsO0 DPWuEEFIk5u5MeuQlJV+Xb/L9jLGewJOr9LQ/+2z2Z2yPPVWA+L4wh+F3HN9f56SqJvfzV5v7fkc/ KgzleJmxXsX5kz3V36+S/TO/VXQDmw2SJ8JyhvA7uSxuwHV+KabPEd5UvRXY39RM+iDug0aaXyaIe Joe0BTLSr3EY/0XDPASdSDEgj/7ddOib0rzdODqpI+PmXarydsvofQn+Rl6O5PBrrFNGk+8NIXTNb MkePcPlLXO7EKZ00cGwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pClwK-003qFN-SO; Tue, 03 Jan 2023 18:23:10 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCkdE-003Arc-Mb for linux-arm-kernel@lists.infradead.org; Tue, 03 Jan 2023 16:59:22 +0000 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 Message-Id: Date: Tue, 03 Jan 2023 16:59:16 +0000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230103_085920_893488_38616E63 X-CRM114-Status: GOOD ( 11.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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); - rval = ida_alloc(&nvmem_ida, GFP_KERNEL); + rval = ida_alloc(&nvmem_ida, GFP_KERNEL); if (rval < 0) { kfree(nvmem); return ERR_PTR(rval); From patchwork Tue Jan 3 16:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13087857 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E60CFC4708D for ; Tue, 3 Jan 2023 18:26:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:Message-Id: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-Owner; bh=zSU+jcXV4l2NvUlTQXMTS7CsxUCUZH3NHiVktuIUB4A=; b=a4KySmczxpYzFD BaOEf1jpyJ9kdbLWHH8ARrRPYatd5KqdRqJZC4qqyheXSZ9ILTXbOWXfyq+tpuj/sBVPgQFtDiE+X XBHXZi1EkjvA1h0TTOJhGD2LzUo4z6jg7xXuoUmXN9sv9FO6cFp3Lt+lXP7Xsn9I2bQ8H0WqGBNPS FKxmAtSmpKU6a3SOqkwnhH/8RLHHhFy7lzHawlU5lyOdUC7Dfi3NnoNhQDid5vfPuyPEnumFkfOXc OtG3tkT8aCUcAB/V+D9vglqvXa18EOb7i11rch+7CwcC71G5LvwFO6A40prvBIz6jpOPUs+FWRUY7 swmcidRiwmsPFbg5JkYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pClxV-003qgo-AM; Tue, 03 Jan 2023 18:24:23 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCkdK-003Aue-2o for linux-arm-kernel@lists.infradead.org; Tue, 03 Jan 2023 16:59:27 +0000 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 Message-Id: Date: Tue, 03 Jan 2023 16:59:22 +0000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230103_085926_232323_D5A15B53 X-CRM114-Status: GOOD ( 10.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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); } + nvmem->id = rval; + if (config->wp_gpio) nvmem->wp_gpio = 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); - nvmem->id = rval; nvmem->owner = config->owner; if (!nvmem->owner && config->dev->driver) nvmem->owner = config->dev->driver->owner; From patchwork Tue Jan 3 16:59:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13087858 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E4B0C3DA7D for ; Tue, 3 Jan 2023 18:27:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:Message-Id: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-Owner; bh=pyD1ys+iXoUNgbFDBYYut88slj/WyCPRV98ud4UHCw4=; b=ofg0tuP9BtBDMS r9JrEoIUM8r3pXnPr8NM80VwFQsh8IyglC46k2GQ/MfscX9NkpJuu7InXMPzMG3EnR8Xtca1jCXJd eHXp9jZT66oI88IMWdSlpRe5N7QdTRCXT3XsziDJ/wPzmiwJ+23Zeyii+7leK2v4MuBj7q0hNX31m cClCE5Aa6mrNtcrRgpe7EXdi2SV+f6eb0yKqyslp0S7fT8egJT/hflMovBIB6nkSzIsuYjfCmAwdK mK586kJQU9I1bUSgu9B92GpcxKWxOGWuE20AdBluBqp/cI7wF9dQN89drq+hXvrB5LJ2ubgx0ifEo f3CYpGnzIkPlffywio7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pClz0-003rPX-G0; Tue, 03 Jan 2023 18:25:55 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCkdN-003Awc-MY for linux-arm-kernel@lists.infradead.org; Tue, 03 Jan 2023 16:59:31 +0000 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 Message-Id: Date: Tue, 03 Jan 2023 16:59:27 +0000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230103_085929_834260_0B686A4B X-CRM114-Status: GOOD ( 11.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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) nvmem->id = rval; - if (config->wp_gpio) - nvmem->wp_gpio = config->wp_gpio; - else if (!config->ignore_wp) + if (!config->ignore_wp) nvmem->wp_gpio = 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; From patchwork Tue Jan 3 16:59:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13087861 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73D3BC4708D for ; Tue, 3 Jan 2023 18:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:Message-Id: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-Owner; bh=yWLVlkNXSuA9yzvOQ0/1d+G/8Pg1cP1nuRSwz11NRd0=; b=g+sQc4FqpE+qGe uv8UrgA5OFWWVAfthayt/6dpfgz7yhfIA1XMgeL+43l++q2Hkcpsr5FdYbz4v6ace1coHm5eSYuGv 0YixxwNki3DRa2KSctumGASk1W4I2r0+VwL0yWTgYf9RKfcprBa8MwXPjF4sSB8BmIR8nnvZP3Mub NYhtOpmnbpdOSgincW7ZZT2v0u0PpeUL9fGcKyuM5mgerTIzEg6ZEAkYnPxFED5ZUtUSVFCejWjUM n3qmEeVOymgPPhbh5toasuW+IAuffN+iIEN86frPt4YMfdNcm5fqT5Fou+Rs00QRUDsMJBhxkwPsR CbjapX9yG5ZXmIY95RKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCm2r-003tBa-5Q; Tue, 03 Jan 2023 18:29:54 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCkdT-003B0J-01 for linux-arm-kernel@lists.infradead.org; Tue, 03 Jan 2023 16:59:54 +0000 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 Message-Id: Date: Tue, 03 Jan 2023 16:59:32 +0000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230103_085951_960896_B708942A X-CRM114-Status: GOOD ( 13.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 nvmem_config *config) nvmem->id = rval; + nvmem->dev.type = &nvmem_provider_type; + nvmem->dev.bus = &nvmem_bus_type; + nvmem->dev.parent = config->dev; + + device_initialize(&nvmem->dev); + if (!config->ignore_wp) nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); - if (IS_ERR(nvmem->wp_gpio)) { - ida_free(&nvmem_ida, nvmem->id); - rval = PTR_ERR(nvmem->wp_gpio); - kfree(nvmem); - return ERR_PTR(rval); - } + if (IS_ERR(nvmem->wp_gpio)) + goto err_put_device; 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 = config->stride ?: 1; nvmem->word_size = config->word_size ?: 1; nvmem->size = config->size; - nvmem->dev.type = &nvmem_provider_type; - nvmem->dev.bus = &nvmem_bus_type; - nvmem->dev.parent = config->dev; nvmem->root_only = config->root_only; nvmem->priv = config->priv; nvmem->type = config->type; @@ -821,11 +820,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) break; } - if (rval) { - ida_free(&nvmem_ida, nvmem->id); - kfree(nvmem); - return ERR_PTR(rval); - } + if (rval) + goto err_put_device; nvmem->read_only = 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) dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); - rval = device_register(&nvmem->dev); + rval = device_add(&nvmem->dev); if (rval) goto err_put_device; From patchwork Tue Jan 3 16:59:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13087859 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 430E1C4708D for ; Tue, 3 Jan 2023 18:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:Message-Id: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-Owner; bh=97nq5l8QOrOErPZ9+Dl11RIrcPDGc/3hGZLOeXnDyuA=; b=p1v8wST1GcGj3r UUasbWLliZ40Mc1IZ1+hgFqzc757ghZZisq41olHGnzAuHr8xEkgMxBqL+3+e6PXsPElSO1ZoQ/ee OzTcBRSq9uL5brGUtwJWX6hm6FSo79+v8MjC4N7pg764Q7BvGkNh+HKusoMdL1qKSm+gxh25ujR/F AIV0+3/DEDxuUnruycFy20LgCHHi8RJKGZPC9qX0GrGccRHjpVDg36j5kzzAF/FB9Pe+rQ45hZeMA jqM4nAkYwiNOeuoXqqcXEu6Xa9GR5RhXibs+ZASW+S0Ft8mJUuOs7aTzD19M4UJGOMtdMHTzG/y/w v/qIDSZrGx5XE7tjkl+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCm0X-003s2n-2c; Tue, 03 Jan 2023 18:27:30 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCkdX-003B1I-Os for linux-arm-kernel@lists.infradead.org; Tue, 03 Jan 2023 16:59:53 +0000 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 Message-Id: Date: Tue, 03 Jan 2023 16:59:37 +0000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230103_085951_940608_3E7D4E9D X-CRM114-Status: GOOD ( 13.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 providers") 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 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) { @@ -862,6 +856,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; @@ -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);