From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Hector Martin <marcan@marcan.st>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Maxime Ripard <mripard@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v2] nvmem: fix registration vs use race
Date: Tue, 3 Jan 2023 15:24:16 +0000 [thread overview]
Message-ID: <Y7RIoO39gSkhqQGm@shell.armlinux.org.uk> (raw)
In-Reply-To: <169464ed-34c2-08d3-efee-686c9a5eb15d@marcan.st>
On Wed, Jan 04, 2023 at 12:20:15AM +0900, Hector Martin wrote:
> On 03/01/2023 23.42, Russell King (Oracle) wrote:
> > 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) <rmk+kernel@armlinux.org.uk>
> > ---
> > v2: add fixes tag
> >
> > 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 321d7d63e068..6b89fb6fa582 100644
> > --- a/drivers/nvmem/core.c
> > +++ b/drivers/nvmem/core.c
> > @@ -835,22 +835,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_register(&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;
>
> You can't call put_device() on a device that hasn't gone through
> device_initialize() yet.
Right, which is what I just realised while writing the previous reply.
We need to use device_initialize() and device_add(), so we can call
put_device() on it.
Error paths are difficult to properly test. :(
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
prev parent reply other threads:[~2023-01-03 17:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-03 14:42 [PATCH v2] nvmem: fix registration vs use race Russell King (Oracle)
2023-01-03 15:20 ` Hector Martin
2023-01-03 15:24 ` Russell King (Oracle) [this message]
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=Y7RIoO39gSkhqQGm@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcan@marcan.st \
--cc=mripard@kernel.org \
--cc=srinivas.kandagatla@linaro.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;
as well as URLs for NNTP newsgroup(s).