Message ID | 20230808062932.150588-2-miquel.raynal@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2332638vqr; Tue, 8 Aug 2023 12:02:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgJuhlJDpGQMaa3M9+D71gqYOXdbMyYPwhh4z8Mx/mx/CGOc38ycRtiBPPxMDtbXITqdQ1 X-Received: by 2002:a5d:684d:0:b0:317:6513:da83 with SMTP id o13-20020a5d684d000000b003176513da83mr262031wrw.43.1691521339785; Tue, 08 Aug 2023 12:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691521339; cv=none; d=google.com; s=arc-20160816; b=vM/IsDh8f/WMDFW2S+5gR1mizwV49beAgvONnwEO5Q6sDqlzBKuP6jVQ1RKdyH97g/ phW5icRW+NuVCyY3EudVOmdk8DeuVLh2GKf2+XKC8HZ0VZGGBUM2m9vDPU8sLvWxTWaw 86Sf+7XdZtq5PEiLwPbCtIZt+7Z0tGDER/d67fRK4bMoyeVYE5Kxb5i9LPsoL0kZOJ8J ciRPI841wsOqaRYtnctSP6SvNuAYWc1X77Qd49+jr7QAuLZ2PGAnavRiAlL4qPP21ZuK vroEw8evdWUiBlQE+9wac8JESlrjtEslfvDZ15Vjvx13mCuhYsSCBcXR2VumrqFoiiBR +MaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=un3Uwaotmlox+IhpuLnflkjcgnz89/YG1Do8CcofnC8=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=deFHTfKtsiK3fIUTO5dxK20yHHqrhqSjB5+h9NbX9KJBqr/dTUJwsBO5yebPElvhx9 ab5W4GwfgQc9pqzbsMw7MmCy/TyHW57iPDQ1jvCJ+oHrKAZRwHXq2B0QQGrGJGQ8gS7j ukXaN8LMcJs3m3ZUmx9vddG1UrEi5Py+HDwBSnvp3xyKuP3HTNKD1eMfRnBnldPdzDvq gh5jj+bBMoCGxb1xNiL+oHADkrgQ7Maau7u4E3wdC1zirSmsrOti0N/1eQg7nXrRtAbq dytE1EiOEaFNwa84erZGhsCqCEDH88I8G/9VfrX9+w+IGB7LpF3Ehryv/ABToVYt54qu u/4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=m09o8WMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r25-20020aa7c159000000b0051e16fd4d9asi7525619edp.223.2023.08.08.12.01.55; Tue, 08 Aug 2023 12:02:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=m09o8WMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234725AbjHHRdS (ORCPT <rfc822;aaronkmseo@gmail.com> + 99 others); Tue, 8 Aug 2023 13:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234756AbjHHRck (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 8 Aug 2023 13:32:40 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 343D6F980 for <linux-kernel@vger.kernel.org>; Tue, 8 Aug 2023 09:14:10 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::221]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 53A85D2E91 for <linux-kernel@vger.kernel.org>; Tue, 8 Aug 2023 06:29:41 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 8C7E8240002; Tue, 8 Aug 2023 06:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691476176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=un3Uwaotmlox+IhpuLnflkjcgnz89/YG1Do8CcofnC8=; b=m09o8WMveylXIA6+Wxh05/Wjd4mUGCqxw+Q6xeYqPZYiU3wK95n/gIcX20uwb8X9VB+Z3W JcvC8NIkpn4ka2KXwDwxSs14CzsLkexWtSHmDIGcmq+DKqEj17TtpnDv/FIAFGu52e3c1S efIYy+fPq4Swu5/ETkwBqP4O8+W1Q8KMUzQJn6qjZnCKbae8FzRfVfIfLtji1sx+uU0S5E bPQa80hjjd2hI5OZeITss+kviY7Q9O9BfHRAQKNG5CiRFh3JpZQg4DlY3vJhLXKTlEQNCJ c1b4CBWCLF02QxsC8xWdZAntPnM0EUZr9wa+JPTUqW+tcA4wRl0H7TWoqPfI8Q== From: Miquel Raynal <miquel.raynal@bootlin.com> To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Thomas Petazzoni <thomas.petazzoni@bootlin.com>, Robert Marko <robert.marko@sartura.hr>, Luka Perkov <luka.perkov@sartura.hr>, Michael Walle <michael@walle.cc>, <linux-kernel@vger.kernel.org>, Randy Dunlap <rdunlap@infradead.org>, Chen-Yu Tsai <wenst@chromium.org>, Daniel Golle <daniel@makrotopia.org>, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= <rafal@milecki.pl>, Miquel Raynal <miquel.raynal@bootlin.com> Subject: [PATCH v9 1/7] nvmem: core: Create all cells before adding the nvmem device Date: Tue, 8 Aug 2023 08:29:26 +0200 Message-Id: <20230808062932.150588-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808062932.150588-1-miquel.raynal@bootlin.com> References: <20230808062932.150588-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773683299655425408 X-GMAIL-MSGID: 1773688680145057343 |
Series |
NVMEM cells in sysfs
|
|
Commit Message
Miquel Raynal
Aug. 8, 2023, 6:29 a.m. UTC
Let's pack all the cells creation in one place, so they are all created
before we add the nvmem device.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/nvmem/core.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
Comments
On 08/08/2023 08:24, Miquel Raynal wrote: > Hi Srinivas, > > srinivas.kandagatla@linaro.org wrote on Tue, 8 Aug 2023 07:56:47 +0100: > >> On 08/08/2023 07:29, Miquel Raynal wrote: >>> Let's pack all the cells creation in one place, so they are all created >>> before we add the nvmem device. >>> >>> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> >>> --- >>> drivers/nvmem/core.c | 12 ++++++------ >>> 1 file changed, 6 insertions(+), 6 deletions(-) >>> >>> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c >>> index 3f8c7718412b..48659106a1e2 100644 >>> --- a/drivers/nvmem/core.c >>> +++ b/drivers/nvmem/core.c >>> @@ -998,12 +998,6 @@ 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; >>> - >>> rval = nvmem_add_cells_from_fixed_layout(nvmem); >>> if (rval) >>> goto err_remove_cells; >>> @@ -1012,6 +1006,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; >> >> All the error handling paths are now messed up with this patch, put_device() in error path will be called incorrectly from multiple places. > > I'm not sure what this means. Perhaps I should additionally call > device_del() after device_add was successful to mimic the > device_unregister() call from the remove path. Is that what you mean? This looks perfectly fine, no change required. This also fixes a bug of missing device_del() in err path. pl, Ignore my old comments. > > I also see the layout_np below should be freed before jumping in the > error section. you mean missing of_node_put()? --srini
Hi Srinivas, srinivas.kandagatla@linaro.org wrote on Fri, 11 Aug 2023 12:11:19 +0100: > On 08/08/2023 08:24, Miquel Raynal wrote: > > Hi Srinivas, > > > > srinivas.kandagatla@linaro.org wrote on Tue, 8 Aug 2023 07:56:47 +0100: > > > >> On 08/08/2023 07:29, Miquel Raynal wrote: > >>> Let's pack all the cells creation in one place, so they are all created > >>> before we add the nvmem device. > >>> > >>> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> > >>> --- > >>> drivers/nvmem/core.c | 12 ++++++------ > >>> 1 file changed, 6 insertions(+), 6 deletions(-) > >>> > >>> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > >>> index 3f8c7718412b..48659106a1e2 100644 > >>> --- a/drivers/nvmem/core.c > >>> +++ b/drivers/nvmem/core.c > >>> @@ -998,12 +998,6 @@ 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; > >>> - > >>> rval = nvmem_add_cells_from_fixed_layout(nvmem); > >>> if (rval) > >>> goto err_remove_cells; > >>> @@ -1012,6 +1006,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; > >> > >> All the error handling paths are now messed up with this patch, put_device() in error path will be called incorrectly from multiple places. > > > > I'm not sure what this means. Perhaps I should additionally call > > device_del() after device_add was successful to mimic the > > device_unregister() call from the remove path. Is that what you mean? > > > This looks perfectly fine, no change required. This also fixes a bug of missing device_del() in err path. > > pl, Ignore my old comments. nvmem_register() calls device_initialize() and later device_add(), which is exactly the content of device_register(). Upon error after device_add(), we currently call device_put(), whereas device_unregister would call both device_del() and device_put(). I would expect device_del() to be first called upon error before device_put() *after* device_add() has succeded, no? > > I also see the layout_np below should be freed before jumping in the > > error section. > > you mean missing of_node_put()? Yes, I need to call of_node_put() before jumping into the error path. Thanks, Miquèl
On 11/08/2023 13:11, Miquel Raynal wrote: >> >> > > nvmem_register() calls device_initialize() and later device_add(), > which is exactly the content of device_register(). Upon error > after device_add(), we currently call device_put(), whereas > device_unregister would call both device_del() and device_put(). > > I would expect device_del() to be first called upon error before > device_put() *after* device_add() has succeded, no? That is correct afaiu, if device_add is succeed we need to call device_del(). As the patch now moved the device_add to end of function we really do not need device_del() in err path. > >>> I also see the layout_np below should be freed before jumping in the >>> error section. >> >> you mean missing of_node_put()? > > Yes, I need to call of_node_put() before jumping into the error path. Are we not already doing it in nvmem_layout_get() and nvmem_add_cells_from_fixed_layout() ? > > Thanks, > Miquèl
Hi Srinivas, srinivas.kandagatla@linaro.org wrote on Fri, 11 Aug 2023 13:26:24 +0100: > On 11/08/2023 13:11, Miquel Raynal wrote: > > >> > >> > > > > nvmem_register() calls device_initialize() and later device_add(), > > which is exactly the content of device_register(). Upon error > > after device_add(), we currently call device_put(), whereas > > device_unregister would call both device_del() and device_put(). > > > > I would expect device_del() to be first called upon error before > > device_put() *after* device_add() has succeded, no? > > That is correct afaiu, if device_add is succeed we need to call device_del(). As the patch now moved the device_add to end of function we really do not need device_del() in err path. Right, I'm looking at the end of the series where I need to add device_del() in the error path because something gets added after device_add(). So we are aligned, thanks for the feedback. > >>> I also see the layout_np below should be freed before jumping in the > >>> error section. > >> > >> you mean missing of_node_put()? > > > > Yes, I need to call of_node_put() before jumping into the error path. > > Are we not already doing it in nvmem_layout_get() and nvmem_add_cells_from_fixed_layout() ? We perform the layout_get for two reasons: - knowing if there is a layout - using the layout Here we are in the first case, and we don't want to retain a reference from here. Only in the second case. Thanks, Miquèl
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 3f8c7718412b..48659106a1e2 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -998,12 +998,6 @@ 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; - rval = nvmem_add_cells_from_fixed_layout(nvmem); if (rval) goto err_remove_cells; @@ -1012,6 +1006,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;