From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Rafał Miłecki" <rafal@milecki.pl>
Cc: "Johan Hovold" <johan@kernel.org>,
"Rafał Miłecki" <zajec5@gmail.com>,
"Srinivas Kandagatla" <srinivas.kandagatla@linaro.org>,
"Andrey Smirnov" <andrew.smirnov@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nvmem: fix unregistering device in nvmem_register() error path
Date: Wed, 22 Dec 2021 10:30:06 +0100 [thread overview]
Message-ID: <YcLwHqvyJMQNsxdY@kroah.com> (raw)
In-Reply-To: <c5b76d10-c270-21e5-e528-9aa20b1384ef@milecki.pl>
On Wed, Dec 22, 2021 at 10:16:20AM +0100, Rafał Miłecki wrote:
> On 22.12.2021 10:08, Johan Hovold wrote:
> > On Wed, Dec 22, 2021 at 10:00:03AM +0100, Rafał Miłecki wrote:
> > > On 22.12.2021 09:38, Johan Hovold wrote:
> >
> > > > It seems Rafał is mistaken here too; you certainly need to call
> > > > platform_device_put() if platform_device_register() fail, even if many
> > > > current users do appear to get this wrong.
> > >
> > > Yes I was! Gosh I made up that "platform_device_put()" name and only
> > > now I realized it actually exists!
> > >
> > > I stand by saying this design is really misleading. Even though
> > > platform_device_put() was obviously a bad example.
> > >
> > > Please remember I'm just a minor kernel developer however in my humble
> > > opinion behaviour of device_register() and platform_device_register()
> > > should be changed.
> > >
> > > If any function fails I expect:
> > > 1. That function to clean up its mess if any
> > > 2. Me to be responsible to clean up my mess if any
> > >
> > > This is how "most" code (whatever it means) works.
> > > 1. If POSIX snprintf() fails I'm not expected to call *printf_put() sth
> > > 2. If POSIX bind() fails I'm not expected to call bind_put() sth
> > > 3. (...)
> > >
> > > I'm not sure if those are the best examples but you should get my point.
> >
> > Yes, and we all agree that it's not the best interface. But it exists,
> > and changing it now risks introducing worse problem than a minor, mostly
> > theoretical, memleak.
>
> Thanks for confirming that, I was wondering if it's just my mind that
> doesn't find this design clear enough.
>
> Now, assuming this design isn't perfect and some purists would like it
> cleaned up:
>
> Would that make sense to introduce something like
> 1. device_register2() / device_add2()
> and
> 2. platform_device_register2() / platform_device_add2()
>
> that would *not* require calling *_put() on failure? Then start
> converting existing drivers to those new (clearner?) helpers?
See my other response, but no, this is not a good idea.
device_register() is correct as-is, but platform_device_register()
isn't.
thanks,
greg k-h
next prev parent reply other threads:[~2021-12-22 9:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-21 15:45 [PATCH] nvmem: fix unregistering device in nvmem_register() error path Rafał Miłecki
2021-12-21 16:06 ` Greg Kroah-Hartman
2021-12-21 17:46 ` Rafał Miłecki
2021-12-22 7:44 ` Greg Kroah-Hartman
2021-12-22 8:38 ` Johan Hovold
2021-12-22 8:56 ` Greg Kroah-Hartman
2021-12-22 9:02 ` Rafał Miłecki
2021-12-22 9:03 ` Johan Hovold
2021-12-22 9:24 ` Johan Hovold
2021-12-22 9:34 ` Greg Kroah-Hartman
2021-12-22 9:00 ` Rafał Miłecki
2021-12-22 9:08 ` Johan Hovold
2021-12-22 9:16 ` Rafał Miłecki
2021-12-22 9:26 ` Johan Hovold
2021-12-22 9:46 ` Rafał Miłecki
2021-12-22 9:30 ` Greg Kroah-Hartman [this message]
2021-12-22 9:29 ` Greg Kroah-Hartman
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=YcLwHqvyJMQNsxdY@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=andrew.smirnov@gmail.com \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafal@milecki.pl \
--cc=srinivas.kandagatla@linaro.org \
--cc=zajec5@gmail.com \
/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