* [PATCH] of/platform: Avoid compilation warning
@ 2020-05-14 17:07 Miquel Raynal
2020-05-27 18:35 ` Rob Herring
0 siblings, 1 reply; 3+ messages in thread
From: Miquel Raynal @ 2020-05-14 17:07 UTC (permalink / raw)
To: Rob Herring, Mark Rutland, devicetree
Cc: Thomas Petazzoni, linux-kernel, Miquel Raynal
The of_find_device_by_node() helper has its dummy counterpart for when
CONFIG_OF is not enabled. However, it is clearly stated in the kernel
documentation that it "takes a reference to the embedded struct device
which needs to be dropped after use". Which means the of_dev_put()
helper might have to be called afterwards. Unfortunately, there is no
of_dev_put() dummy function if OF_CONFIG is not enabled which seems
odd in this case. The of_dev_put() helper is pretty simple, it just
checks the validity of the single argument and calls put_device() on
it. One can just call put_device() directly to avoid any build issue
but I find much more accurate in this case to create the dummy
helper.
With this helper, a file using of_find_device_by_node() can also call
of_dev_put() without triggering the following:
error: implicit declaration of function ‘of_dev_put’; did you mean ‘of_node_put’? [-Werror=implicit-function-declaration]
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
include/linux/of_platform.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 84a966623e78..84d9e60e517e 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -54,11 +54,13 @@ extern struct platform_device *of_device_alloc(struct device_node *np,
struct device *parent);
#ifdef CONFIG_OF
extern struct platform_device *of_find_device_by_node(struct device_node *np);
+extern void of_dev_put(struct platform_device *dev);
#else
static inline struct platform_device *of_find_device_by_node(struct device_node *np)
{
return NULL;
}
+static inline void of_dev_put(struct platform_device *dev) { }
#endif
/* Platform devices and busses creation */
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] of/platform: Avoid compilation warning
2020-05-14 17:07 [PATCH] of/platform: Avoid compilation warning Miquel Raynal
@ 2020-05-27 18:35 ` Rob Herring
2020-05-28 11:03 ` Miquel Raynal
0 siblings, 1 reply; 3+ messages in thread
From: Rob Herring @ 2020-05-27 18:35 UTC (permalink / raw)
To: Miquel Raynal; +Cc: Mark Rutland, devicetree, Thomas Petazzoni, linux-kernel
On Thu, May 14, 2020 at 07:07:07PM +0200, Miquel Raynal wrote:
> The of_find_device_by_node() helper has its dummy counterpart for when
> CONFIG_OF is not enabled. However, it is clearly stated in the kernel
> documentation that it "takes a reference to the embedded struct device
> which needs to be dropped after use". Which means the of_dev_put()
> helper might have to be called afterwards. Unfortunately, there is no
> of_dev_put() dummy function if OF_CONFIG is not enabled which seems
> odd in this case. The of_dev_put() helper is pretty simple, it just
> checks the validity of the single argument and calls put_device() on
> it. One can just call put_device() directly to avoid any build issue
> but I find much more accurate in this case to create the dummy
> helper.
>
> With this helper, a file using of_find_device_by_node() can also call
> of_dev_put() without triggering the following:
IMO, you should use platform_device_put() instead. It has the NULL check
too.
I imagine of_dev_put() is left over from when OF devices were not
platform devices.
> error: implicit declaration of function ‘of_dev_put’; did you mean ‘of_node_put’? [-Werror=implicit-function-declaration]
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
> include/linux/of_platform.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
> index 84a966623e78..84d9e60e517e 100644
> --- a/include/linux/of_platform.h
> +++ b/include/linux/of_platform.h
> @@ -54,11 +54,13 @@ extern struct platform_device *of_device_alloc(struct device_node *np,
> struct device *parent);
> #ifdef CONFIG_OF
> extern struct platform_device *of_find_device_by_node(struct device_node *np);
> +extern void of_dev_put(struct platform_device *dev);
> #else
> static inline struct platform_device *of_find_device_by_node(struct device_node *np)
> {
> return NULL;
> }
> +static inline void of_dev_put(struct platform_device *dev) { }
> #endif
>
> /* Platform devices and busses creation */
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] of/platform: Avoid compilation warning
2020-05-27 18:35 ` Rob Herring
@ 2020-05-28 11:03 ` Miquel Raynal
0 siblings, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2020-05-28 11:03 UTC (permalink / raw)
To: Rob Herring; +Cc: Mark Rutland, devicetree, Thomas Petazzoni, linux-kernel
Hi Rob,
Rob Herring <robh@kernel.org> wrote on Wed, 27 May 2020 12:35:55 -0600:
> On Thu, May 14, 2020 at 07:07:07PM +0200, Miquel Raynal wrote:
> > The of_find_device_by_node() helper has its dummy counterpart for when
> > CONFIG_OF is not enabled. However, it is clearly stated in the kernel
> > documentation that it "takes a reference to the embedded struct device
> > which needs to be dropped after use". Which means the of_dev_put()
> > helper might have to be called afterwards. Unfortunately, there is no
> > of_dev_put() dummy function if OF_CONFIG is not enabled which seems
> > odd in this case. The of_dev_put() helper is pretty simple, it just
> > checks the validity of the single argument and calls put_device() on
> > it. One can just call put_device() directly to avoid any build issue
> > but I find much more accurate in this case to create the dummy
> > helper.
> >
> > With this helper, a file using of_find_device_by_node() can also call
> > of_dev_put() without triggering the following:
>
> IMO, you should use platform_device_put() instead. It has the NULL check
> too.
>
> I imagine of_dev_put() is left over from when OF devices were not
> platform devices.
Ok, makes sense. Perhaps we should entirely get rid of it, I don't see
a lot of users left. Or at least update the comment I was mentioning.
Cheers,
Miquèl
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-28 11:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 17:07 [PATCH] of/platform: Avoid compilation warning Miquel Raynal
2020-05-27 18:35 ` Rob Herring
2020-05-28 11:03 ` Miquel Raynal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.