Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

authored by

Andy Shevchenko and committed by
Wolfram Sang
df6d7277 3435b7f0

+10 -10
+10 -9
drivers/i2c/i2c-core-base.c
··· 961 961 struct i2c_client * 962 962 i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info) 963 963 { 964 + struct fwnode_handle *fwnode; 964 965 struct i2c_client *client; 965 966 bool need_put = false; 966 967 int status; ··· 1002 1001 client->dev.parent = &client->adapter->dev; 1003 1002 client->dev.bus = &i2c_bus_type; 1004 1003 client->dev.type = &i2c_client_type; 1005 - client->dev.of_node = of_node_get(info->of_node); 1006 - client->dev.fwnode = info->fwnode; 1007 1004 1008 1005 device_enable_async_suspend(&client->dev); 1006 + 1007 + fwnode = info->fwnode ?: of_fwnode_handle(info->of_node); 1008 + device_set_node(&client->dev, fwnode_handle_get(fwnode)); 1009 1009 1010 1010 if (info->swnode) { 1011 1011 status = device_add_software_node(&client->dev, info->swnode); ··· 1014 1012 dev_err(&adap->dev, 1015 1013 "Failed to add software node to client %s: %d\n", 1016 1014 client->name, status); 1017 - goto out_err_put_of_node; 1015 + goto out_err_put_fwnode; 1018 1016 } 1019 1017 } 1020 1018 ··· 1033 1031 out_remove_swnode: 1034 1032 device_remove_software_node(&client->dev); 1035 1033 need_put = true; 1036 - out_err_put_of_node: 1037 - of_node_put(info->of_node); 1034 + out_err_put_fwnode: 1035 + fwnode_handle_put(fwnode); 1038 1036 out_err: 1039 1037 dev_err(&adap->dev, 1040 1038 "Failed to register i2c client %s at 0x%02x (%d)\n", ··· 1062 1060 return; 1063 1061 1064 1062 fwnode = dev_fwnode(&client->dev); 1065 - if (is_of_node(fwnode)) { 1063 + if (is_of_node(fwnode)) 1066 1064 of_node_clear_flag(to_of_node(fwnode), OF_POPULATED); 1067 - of_node_put(client->dev.of_node); 1068 - } else if (is_acpi_device_node(fwnode)) { 1065 + else if (is_acpi_device_node(fwnode)) 1069 1066 acpi_device_clear_enumerated(to_acpi_device_node(fwnode)); 1070 - } 1067 + fwnode_handle_put(fwnode); 1071 1068 1072 1069 device_remove_software_node(&client->dev); 1073 1070 device_unregister(&client->dev);
-1
drivers/i2c/i2c-core-of.c
··· 49 49 } 50 50 51 51 info->addr = addr; 52 - info->of_node = node; 53 52 info->fwnode = of_fwnode_handle(node); 54 53 55 54 if (of_property_read_bool(node, "host-notify"))