* [PATCH] driver core: platform: document registration-failure requirement
@ 2021-12-22 8:52 Johan Hovold
2021-12-22 9:55 ` Johan Hovold
0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2021-12-22 8:52 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Rafał Miłecki, linux-kernel, Johan Hovold
Add an explicit comment to document that the reference initialised by
platform_device_register() needs to be released by a call to
platform_device_put() also when registration fails (cf.
device_register()).
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/base/platform.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 598acf93a360..38fdcbdba4a4 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -762,6 +762,10 @@ EXPORT_SYMBOL_GPL(platform_device_del);
/**
* platform_device_register - add a platform-level device
* @pdev: platform device we're adding
+ *
+ * NOTE: _Never_ directly free @pdev after calling this function, even if it
+ * returned an error! Always use platform_put_device() to give up the
+ * reference initialised in this function instead.
*/
int platform_device_register(struct platform_device *pdev)
{
--
2.32.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] driver core: platform: document registration-failure requirement
2021-12-22 8:52 [PATCH] driver core: platform: document registration-failure requirement Johan Hovold
@ 2021-12-22 9:55 ` Johan Hovold
0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2021-12-22 9:55 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Rafał Miłecki, linux-kernel
On Wed, Dec 22, 2021 at 09:52:29AM +0100, Johan Hovold wrote:
> Add an explicit comment to document that the reference initialised by
> platform_device_register() needs to be released by a call to
> platform_device_put() also when registration fails (cf.
> device_register()).
>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/base/platform.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 598acf93a360..38fdcbdba4a4 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -762,6 +762,10 @@ EXPORT_SYMBOL_GPL(platform_device_del);
> /**
> * platform_device_register - add a platform-level device
> * @pdev: platform device we're adding
> + *
> + * NOTE: _Never_ directly free @pdev after calling this function, even if it
> + * returned an error! Always use platform_put_device() to give up the
This should have been platform_device_put().
Greg, I'll send a v2 for you to consider since this documents the
current behaviour even if you wanted to look into ways to change this.
> + * reference initialised in this function instead.
> */
> int platform_device_register(struct platform_device *pdev)
> {
Johan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-22 9:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-22 8:52 [PATCH] driver core: platform: document registration-failure requirement Johan Hovold
2021-12-22 9:55 ` Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox