All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node()
@ 2023-06-15 14:52 Andy Shevchenko
  2023-06-15 14:59 ` Andy Shevchenko
  2023-06-15 16:48 ` Rob Herring
  0 siblings, 2 replies; 8+ messages in thread
From: Andy Shevchenko @ 2023-06-15 14:52 UTC (permalink / raw)
  To: Rob Herring, devicetree, linux-kernel
  Cc: Rob Herring, Frank Rowand, Andy Shevchenko

Insulate of_device_alloc() and of_amba_device_create() from possible
changes to fwnode_handle implementation by using device_set_node()
instead of open-coding dev->dev.fwnode assignments.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/of/platform.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 78ae84187449..051e29b7ad2b 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -140,8 +140,8 @@ struct platform_device *of_device_alloc(struct device_node *np,
 		}
 	}
 
-	dev->dev.of_node = of_node_get(np);
-	dev->dev.fwnode = &np->fwnode;
+	/* setup generic device info */
+	device_set_node(&dev->dev, of_fwnode_handle(np));
 	dev->dev.parent = parent ? : &platform_bus;
 
 	if (bus_id)
@@ -239,8 +239,7 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
 	dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
 
 	/* setup generic device info */
-	dev->dev.of_node = of_node_get(node);
-	dev->dev.fwnode = &node->fwnode;
+	device_set_node(&dev->dev, of_fwnode_handle(node));
 	dev->dev.parent = parent ? : &platform_bus;
 	dev->dev.platform_data = platform_data;
 	if (bus_id)
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node()
  2023-06-15 14:52 [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node() Andy Shevchenko
@ 2023-06-15 14:59 ` Andy Shevchenko
  2023-06-15 15:01   ` Andy Shevchenko
  2023-06-15 16:48 ` Rob Herring
  1 sibling, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2023-06-15 14:59 UTC (permalink / raw)
  To: Rob Herring, devicetree, linux-kernel; +Cc: Rob Herring, Frank Rowand

On Thu, Jun 15, 2023 at 05:52:43PM +0300, Andy Shevchenko wrote:
> Insulate of_device_alloc() and of_amba_device_create() from possible
> changes to fwnode_handle implementation by using device_set_node()
> instead of open-coding dev->dev.fwnode assignments.

Side note. When I preparing this change I have noticed a lot of

	dev_set_name(... dev_name())

in the code which seems to me problematic in two ways:
1) (minor) the dev_set_name() may fail, no checks are there;
2) (major?) the above construction leaks memory.

Is it on purpose (esp. second point)? If no, can it be fixed?
Note, I'm not familiar with OF platform code, so I would help
reviewing the change, but that's it.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node()
  2023-06-15 14:59 ` Andy Shevchenko
@ 2023-06-15 15:01   ` Andy Shevchenko
  2023-06-15 15:03     ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2023-06-15 15:01 UTC (permalink / raw)
  To: Rob Herring, devicetree, linux-kernel; +Cc: Rob Herring, Frank Rowand

On Thu, Jun 15, 2023 at 05:59:52PM +0300, Andy Shevchenko wrote:
> On Thu, Jun 15, 2023 at 05:52:43PM +0300, Andy Shevchenko wrote:
> > Insulate of_device_alloc() and of_amba_device_create() from possible
> > changes to fwnode_handle implementation by using device_set_node()
> > instead of open-coding dev->dev.fwnode assignments.
> 
> Side note. When I preparing this change I have noticed a lot of
> 
> 	dev_set_name(... dev_name())

Plus

	dev_set_name(dev, ...)
	...
	dev_set_name(dev, ...)

on the same device will also give a memory leak.

> in the code which seems to me problematic in two ways:
> 1) (minor) the dev_set_name() may fail, no checks are there;
> 2) (major?) the above construction leaks memory.
> 
> Is it on purpose (esp. second point)? If no, can it be fixed?
> Note, I'm not familiar with OF platform code, so I would help
> reviewing the change, but that's it.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node()
  2023-06-15 15:01   ` Andy Shevchenko
@ 2023-06-15 15:03     ` Andy Shevchenko
  2023-06-15 16:44       ` Rob Herring
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2023-06-15 15:03 UTC (permalink / raw)
  To: Rob Herring, devicetree, linux-kernel; +Cc: Rob Herring, Frank Rowand

On Thu, Jun 15, 2023 at 06:01:17PM +0300, Andy Shevchenko wrote:
> On Thu, Jun 15, 2023 at 05:59:52PM +0300, Andy Shevchenko wrote:
> > On Thu, Jun 15, 2023 at 05:52:43PM +0300, Andy Shevchenko wrote:
> > > Insulate of_device_alloc() and of_amba_device_create() from possible
> > > changes to fwnode_handle implementation by using device_set_node()
> > > instead of open-coding dev->dev.fwnode assignments.
> > 
> > Side note. When I preparing this change I have noticed a lot of
> > 
> > 	dev_set_name(... dev_name())
> 
> Plus
> 
> 	dev_set_name(dev, ...)
> 	...
> 	dev_set_name(dev, ...)
> 
> on the same device will also give a memory leak.

Ah, seems false alarm, the kobject_set_name_vargs() frees the old one.
Sorry for the noise for second point. But the first one still applies.

> > in the code which seems to me problematic in two ways:
> > 1) (minor) the dev_set_name() may fail, no checks are there;
> > 2) (major?) the above construction leaks memory.
> > 
> > Is it on purpose (esp. second point)? If no, can it be fixed?
> > Note, I'm not familiar with OF platform code, so I would help
> > reviewing the change, but that's it.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node()
  2023-06-15 15:03     ` Andy Shevchenko
@ 2023-06-15 16:44       ` Rob Herring
  2023-06-15 17:13         ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Rob Herring @ 2023-06-15 16:44 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: devicetree, linux-kernel, Frank Rowand

On Thu, Jun 15, 2023 at 06:03:52PM +0300, Andy Shevchenko wrote:
> On Thu, Jun 15, 2023 at 06:01:17PM +0300, Andy Shevchenko wrote:
> > On Thu, Jun 15, 2023 at 05:59:52PM +0300, Andy Shevchenko wrote:
> > > On Thu, Jun 15, 2023 at 05:52:43PM +0300, Andy Shevchenko wrote:
> > > > Insulate of_device_alloc() and of_amba_device_create() from possible
> > > > changes to fwnode_handle implementation by using device_set_node()
> > > > instead of open-coding dev->dev.fwnode assignments.
> > > 
> > > Side note. When I preparing this change I have noticed a lot of
> > > 
> > > 	dev_set_name(... dev_name())
> > 
> > Plus
> > 
> > 	dev_set_name(dev, ...)
> > 	...
> > 	dev_set_name(dev, ...)
> > 
> > on the same device will also give a memory leak.
> 
> Ah, seems false alarm, the kobject_set_name_vargs() frees the old one.
> Sorry for the noise for second point. But the first one still applies.
> 
> > > in the code which seems to me problematic in two ways:
> > > 1) (minor) the dev_set_name() may fail, no checks are there;

Is there anything besides a memory alloc failure? What will print a 
message already. Wouldn't we fail a bit later on when adding the 
device anyways?

In a rough count, 92 out of 500 cases check the return of 
dev_set_name().

Rob

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node()
  2023-06-15 14:52 [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node() Andy Shevchenko
  2023-06-15 14:59 ` Andy Shevchenko
@ 2023-06-15 16:48 ` Rob Herring
  1 sibling, 0 replies; 8+ messages in thread
From: Rob Herring @ 2023-06-15 16:48 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Frank Rowand, linux-kernel, Rob Herring, devicetree


On Thu, 15 Jun 2023 17:52:43 +0300, Andy Shevchenko wrote:
> Insulate of_device_alloc() and of_amba_device_create() from possible
> changes to fwnode_handle implementation by using device_set_node()
> instead of open-coding dev->dev.fwnode assignments.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/of/platform.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 

Applied, thanks!


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node()
  2023-06-15 16:44       ` Rob Herring
@ 2023-06-15 17:13         ` Andy Shevchenko
  2023-06-15 17:20           ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2023-06-15 17:13 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree, linux-kernel, Frank Rowand

On Thu, Jun 15, 2023 at 10:44:52AM -0600, Rob Herring wrote:
> On Thu, Jun 15, 2023 at 06:03:52PM +0300, Andy Shevchenko wrote:
> > On Thu, Jun 15, 2023 at 06:01:17PM +0300, Andy Shevchenko wrote:
> > > On Thu, Jun 15, 2023 at 05:59:52PM +0300, Andy Shevchenko wrote:
> > > > On Thu, Jun 15, 2023 at 05:52:43PM +0300, Andy Shevchenko wrote:

...

> > > > in the code which seems to me problematic in two ways:
> > > > 1) (minor) the dev_set_name() may fail, no checks are there;
> 
> Is there anything besides a memory alloc failure? What will print a
> message already. Wouldn't we fail a bit later on when adding the
> device anyways?

I don't see how we fail. Any pointers?

> In a rough count, 92 out of 500 cases check the return of
> dev_set_name().

Yeah, because it was new finding about that. Some static analyzers complain
nowadays about this.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node()
  2023-06-15 17:13         ` Andy Shevchenko
@ 2023-06-15 17:20           ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2023-06-15 17:20 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree, linux-kernel, Frank Rowand

On Thu, Jun 15, 2023 at 08:13:52PM +0300, Andy Shevchenko wrote:
> On Thu, Jun 15, 2023 at 10:44:52AM -0600, Rob Herring wrote:
> > On Thu, Jun 15, 2023 at 06:03:52PM +0300, Andy Shevchenko wrote:
> > > On Thu, Jun 15, 2023 at 06:01:17PM +0300, Andy Shevchenko wrote:
> > > > On Thu, Jun 15, 2023 at 05:59:52PM +0300, Andy Shevchenko wrote:
> > > > > On Thu, Jun 15, 2023 at 05:52:43PM +0300, Andy Shevchenko wrote:

...

> > > > > in the code which seems to me problematic in two ways:
> > > > > 1) (minor) the dev_set_name() may fail, no checks are there;
> > 
> > Is there anything besides a memory alloc failure? What will print a
> > message already. Wouldn't we fail a bit later on when adding the
> > device anyways?
> 
> I don't see how we fail. Any pointers?

Okay, code in question:

        /* subsystems can specify simple device enumeration */
        if (!dev_name(dev) && dev->bus && dev->bus->dev_name)
                dev_set_name(dev, "%s%u", dev->bus->dev_name, dev->id);

        if (!dev_name(dev)) {
                error = -EINVAL;
                goto name_error;
        }

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-06-15 17:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15 14:52 [PATCH v1 1/1] of/platform: Propagate firmware node by calling device_set_node() Andy Shevchenko
2023-06-15 14:59 ` Andy Shevchenko
2023-06-15 15:01   ` Andy Shevchenko
2023-06-15 15:03     ` Andy Shevchenko
2023-06-15 16:44       ` Rob Herring
2023-06-15 17:13         ` Andy Shevchenko
2023-06-15 17:20           ` Andy Shevchenko
2023-06-15 16:48 ` Rob Herring

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.