All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] i2c: core: Do not dereference fwnode in struct device
@ 2021-12-07 16:24 Andy Shevchenko
  2021-12-09  8:44 ` Wolfram Sang
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2021-12-07 16:24 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c, linux-kernel; +Cc: Wolfram Sang, Andy Shevchenko

In order to make the underneath API easier to change in the future,
prevent users from dereferencing fwnode from struct device.
Instead, use the specific device_set_node() API for that.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-core-base.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 80f36709e36a..e685a46fd07a 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1049,12 +1049,13 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf
 	client->dev.parent = &client->adapter->dev;
 	client->dev.bus = &i2c_bus_type;
 	client->dev.type = &i2c_client_type;
-	client->dev.of_node = of_node_get(info->of_node);
-	client->dev.fwnode = info->fwnode;
 
 	device_enable_async_suspend(&client->dev);
 	i2c_dev_set_name(adap, client, info);
 
+	device_set_node(&client->dev, info->fwnode);
+	client->dev.of_node = of_node_get(info->of_node);
+
 	if (info->swnode) {
 		status = device_add_software_node(&client->dev, info->swnode);
 		if (status) {
-- 
2.33.0


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

* Re: [PATCH v1 1/1] i2c: core: Do not dereference fwnode in struct device
  2021-12-07 16:24 [PATCH v1 1/1] i2c: core: Do not dereference fwnode in struct device Andy Shevchenko
@ 2021-12-09  8:44 ` Wolfram Sang
  2021-12-09 10:08   ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfram Sang @ 2021-12-09  8:44 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-i2c, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 957 bytes --]


>  	client->dev.parent = &client->adapter->dev;
>  	client->dev.bus = &i2c_bus_type;
>  	client->dev.type = &i2c_client_type;
> -	client->dev.of_node = of_node_get(info->of_node);
> -	client->dev.fwnode = info->fwnode;
>  
>  	device_enable_async_suspend(&client->dev);
>  	i2c_dev_set_name(adap, client, info);
>  
> +	device_set_node(&client->dev, info->fwnode);
> +	client->dev.of_node = of_node_get(info->of_node);
> +

I am basically OK with this change. I'd just move the code block a
little to have the same behaviour as before. Something like this
(hand-edited preview version):

>  	client->dev.bus = &i2c_bus_type;
>  	client->dev.type = &i2c_client_type;
>  	client->dev.of_node = of_node_get(info->of_node);
> -	client->dev.fwnode = info->fwnode;
>  
> +	device_set_node(&client->dev, info->fwnode);
>  	device_enable_async_suspend(&client->dev);
>  	i2c_dev_set_name(adap, client, info);

Are you okay with that?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v1 1/1] i2c: core: Do not dereference fwnode in struct device
  2021-12-09  8:44 ` Wolfram Sang
@ 2021-12-09 10:08   ` Andy Shevchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-12-09 10:08 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c, linux-kernel

On Thu, Dec 09, 2021 at 09:44:49AM +0100, Wolfram Sang wrote:
> 
> >  	client->dev.parent = &client->adapter->dev;
> >  	client->dev.bus = &i2c_bus_type;
> >  	client->dev.type = &i2c_client_type;
> > -	client->dev.of_node = of_node_get(info->of_node);
> > -	client->dev.fwnode = info->fwnode;
> >  
> >  	device_enable_async_suspend(&client->dev);
> >  	i2c_dev_set_name(adap, client, info);
> >  
> > +	device_set_node(&client->dev, info->fwnode);
> > +	client->dev.of_node = of_node_get(info->of_node);
> > +
> 
> I am basically OK with this change. I'd just move the code block a
> little to have the same behaviour as before. Something like this
> (hand-edited preview version):

And this is exactly what have been done.

> >  	client->dev.bus = &i2c_bus_type;
> >  	client->dev.type = &i2c_client_type;
> >  	client->dev.of_node = of_node_get(info->of_node);
> > -	client->dev.fwnode = info->fwnode;
> >  
> > +	device_set_node(&client->dev, info->fwnode);
> >  	device_enable_async_suspend(&client->dev);
> >  	i2c_dev_set_name(adap, client, info);
> 
> Are you okay with that?

It will be broken in this case. There is subtle detail about device_set_node(),
it sets both fwnode and of_node at once. More thinking about this, I admit that
the best strategy now is to drop this change for now.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2021-12-09 10:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-07 16:24 [PATCH v1 1/1] i2c: core: Do not dereference fwnode in struct device Andy Shevchenko
2021-12-09  8:44 ` Wolfram Sang
2021-12-09 10:08   ` Andy Shevchenko

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.