i2c: core: Do not dereference fwnode in struct device
Subsystems (2)
PATCH 1/1 i2c: core: Do not dereference fwnode in struct device
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.
--- drivers/i2c/i2c-core-base.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-base.c +3 -2
@@ -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) {
Signature · 1 line
2.33.0
drivers/i2c/i2c-core-base.c i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf · line 1058
Quoted 13 lines
drivers/i2c/i2c-core-base.c +3
-2client->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):
drivers/i2c/i2c-core-base.c i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf
Quoted 8 lines
drivers/i2c/i2c-core-base.c +1
-1client->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?
Quoted 10 lines · Wolfram Sang
Quoted 10 lines
drivers/i2c/i2c-core-base.c +0
-2client->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);
Quoted 7 lines
drivers/i2c/i2c-core-base.c i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf · line 1058
Quoted 3 lines
drivers/i2c/i2c-core-base.c +3
-0+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.
Quoted 10 lines
drivers/i2c/i2c-core-base.c i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf
Quoted 8 lines
drivers/i2c/i2c-core-base.c +1
-1client->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.
Signature · 2 lines
With Best Regards, Andy Shevchenko