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

hwmon: (nct6775-i2c) Use i2c_get_match_data()

Use preferred i2c_get_match_data() instead of of_match_device() and
i2c_match_id() to get the driver match data. With this, adjust the
includes to explicitly include the correct headers.

Adjust the 'kinds' enum to not use 0, so that no match data can be
distinguished from a valid enum value.

Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20231115205703.3730448-2-robh@kernel.org
[groeck: Use double cast for i2c_get_match_data() to make clang happy]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Rob Herring and committed by
Guenter Roeck
10a0575e 5cfc392c

+3 -13
+2 -12
drivers/hwmon/nct6775-i2c.c
··· 21 21 #include <linux/hwmon.h> 22 22 #include <linux/hwmon-sysfs.h> 23 23 #include <linux/err.h> 24 - #include <linux/of_device.h> 24 + #include <linux/of.h> 25 25 #include <linux/regmap.h> 26 26 #include "nct6775.h" 27 27 ··· 155 155 static int nct6775_i2c_probe(struct i2c_client *client) 156 156 { 157 157 struct nct6775_data *data; 158 - const struct of_device_id *of_id; 159 - const struct i2c_device_id *i2c_id; 160 158 struct device *dev = &client->dev; 161 - 162 - of_id = of_match_device(nct6775_i2c_of_match, dev); 163 - i2c_id = i2c_match_id(nct6775_i2c_id, client); 164 - 165 - if (of_id && (unsigned long)of_id->data != i2c_id->driver_data) 166 - dev_notice(dev, "Device mismatch: %s in device tree, %s detected\n", 167 - of_id->name, i2c_id->name); 168 159 169 160 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); 170 161 if (!data) 171 162 return -ENOMEM; 172 163 173 - data->kind = i2c_id->driver_data; 174 - 164 + data->kind = (enum kinds)(uintptr_t)i2c_get_match_data(client); 175 165 data->read_only = true; 176 166 data->driver_data = client; 177 167 data->driver_init = nct6775_i2c_probe_init;
+1 -1
drivers/hwmon/nct6775.h
··· 4 4 5 5 #include <linux/types.h> 6 6 7 - enum kinds { nct6106, nct6116, nct6775, nct6776, nct6779, nct6791, nct6792, 7 + enum kinds { nct6106 = 1, nct6116, nct6775, nct6776, nct6779, nct6791, nct6792, 8 8 nct6793, nct6795, nct6796, nct6797, nct6798, nct6799 }; 9 9 enum pwm_enable { off, manual, thermal_cruise, speed_cruise, sf3, sf4 }; 10 10