public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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>,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: Re: [PATCH v9 1/7] nvmem: core: Create all cells before adding the nvmem device
Date: Fri, 11 Aug 2023 14:11:22 +0200	[thread overview]
Message-ID: <20230811141122.7921df1d@xps-13> (raw)
In-Reply-To: <05aea50f-6692-962e-abe7-765197815f03@linaro.org>

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

  reply	other threads:[~2023-08-11 12:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08  6:29 [PATCH v9 0/7] NVMEM cells in sysfs Miquel Raynal
2023-08-08  6:29 ` [PATCH v9 1/7] nvmem: core: Create all cells before adding the nvmem device Miquel Raynal
2023-08-08  6:37   ` Michael Walle
2023-08-08  6:56   ` Srinivas Kandagatla
2023-08-08  7:24     ` Miquel Raynal
2023-08-11 11:11       ` Srinivas Kandagatla
2023-08-11 12:11         ` Miquel Raynal [this message]
2023-08-11 12:26           ` Srinivas Kandagatla
2023-08-11 12:38             ` Miquel Raynal
2023-08-08  6:29 ` [PATCH v9 2/7] nvmem: core: Return NULL when no nvmem layout is found Miquel Raynal
2023-08-08  6:38   ` Michael Walle
2023-08-08  6:29 ` [PATCH v9 3/7] nvmem: core: Do not open-code existing functions Miquel Raynal
2023-08-08  6:41   ` Michael Walle
2023-08-08  6:29 ` [PATCH v9 4/7] nvmem: core: Notify when a new layout is registered Miquel Raynal
2023-08-08  6:29 ` [PATCH v9 5/7] nvmem: core: Rework layouts to become platform devices Miquel Raynal
2023-08-08  6:29 ` [PATCH v9 6/7] ABI: sysfs-nvmem-cells: Expose cells through sysfs Miquel Raynal
2023-08-08  6:29 ` [PATCH v9 7/7] nvmem: core: " Miquel Raynal
2023-08-14 10:01 ` (subset) [PATCH v9 0/7] NVMEM cells in sysfs Srinivas Kandagatla
2023-08-17  9:06   ` Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230811141122.7921df1d@xps-13 \
    --to=miquel.raynal@bootlin.com \
    --cc=daniel@makrotopia.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luka.perkov@sartura.hr \
    --cc=michael@walle.cc \
    --cc=rafal@milecki.pl \
    --cc=rdunlap@infradead.org \
    --cc=robert.marko@sartura.hr \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=wenst@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox