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

iio: st_sensors: Drop redundant parameter from st_sensors_of_name_probe()

Since we have access to the struct device_driver and thus to the ID table,
there is no need to supply special parameters to st_sensors_of_name_probe().

Besides that we have a common API to get driver match data, there is
no need to do matching separately for OF and ACPI.

Taking into consideration above, simplify the ST sensors code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andy Shevchenko and committed by
Jonathan Cameron
efc78983 e825070f

+33 -96
+1 -2
drivers/iio/accel/st_accel_spi.c
··· 107 107 struct iio_dev *indio_dev; 108 108 int err; 109 109 110 - st_sensors_of_name_probe(&spi->dev, st_accel_of_match, 111 - spi->modalias, sizeof(spi->modalias)); 110 + st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias)); 112 111 113 112 settings = st_accel_get_settings(spi->modalias); 114 113 if (!settings) {
+25 -29
drivers/iio/common/st_sensors/st_sensors_core.c
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/delay.h> 14 14 #include <linux/iio/iio.h> 15 + #include <linux/property.h> 15 16 #include <linux/regulator/consumer.h> 16 17 #include <linux/of.h> 17 18 #include <linux/of_device.h> ··· 341 340 342 341 return pdata; 343 342 } 344 - 345 - /** 346 - * st_sensors_of_name_probe() - device tree probe for ST sensor name 347 - * @dev: driver model representation of the device. 348 - * @match: the OF match table for the device, containing compatible strings 349 - * but also a .data field with the corresponding internal kernel name 350 - * used by this sensor. 351 - * @name: device name buffer reference. 352 - * @len: device name buffer length. 353 - * 354 - * In effect this function matches a compatible string to an internal kernel 355 - * name for a certain sensor device, so that the rest of the autodetection can 356 - * rely on that name from this point on. I2C/SPI devices will be renamed 357 - * to match the internal kernel convention. 358 - */ 359 - void st_sensors_of_name_probe(struct device *dev, 360 - const struct of_device_id *match, 361 - char *name, int len) 362 - { 363 - const struct of_device_id *of_id; 364 - 365 - of_id = of_match_device(match, dev); 366 - if (!of_id || !of_id->data) 367 - return; 368 - 369 - /* The name from the OF match takes precedence if present */ 370 - strlcpy(name, of_id->data, len); 371 - } 372 - EXPORT_SYMBOL(st_sensors_of_name_probe); 373 343 #else 374 344 static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev, 375 345 struct st_sensors_platform_data *defdata) ··· 348 376 return NULL; 349 377 } 350 378 #endif 379 + 380 + /** 381 + * st_sensors_dev_name_probe() - device probe for ST sensor name 382 + * @dev: driver model representation of the device. 383 + * @name: device name buffer reference. 384 + * @len: device name buffer length. 385 + * 386 + * In effect this function matches an ID to an internal kernel 387 + * name for a certain sensor device, so that the rest of the autodetection can 388 + * rely on that name from this point on. I2C/SPI devices will be renamed 389 + * to match the internal kernel convention. 390 + */ 391 + void st_sensors_dev_name_probe(struct device *dev, char *name, int len) 392 + { 393 + const void *match; 394 + 395 + match = device_get_match_data(dev); 396 + if (!match) 397 + return; 398 + 399 + /* The name from the match takes precedence if present */ 400 + strlcpy(name, match, len); 401 + } 402 + EXPORT_SYMBOL(st_sensors_dev_name_probe); 351 403 352 404 int st_sensors_init_sensor(struct iio_dev *indio_dev, 353 405 struct st_sensors_platform_data *pdata)
-21
drivers/iio/common/st_sensors/st_sensors_i2c.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/slab.h> 13 13 #include <linux/iio/iio.h> 14 - #include <linux/of_device.h> 15 - #include <linux/acpi.h> 16 14 #include <linux/regmap.h> 17 15 18 16 #include <linux/iio/common/st_sensors_i2c.h> ··· 65 67 return 0; 66 68 } 67 69 EXPORT_SYMBOL(st_sensors_i2c_configure); 68 - 69 - #ifdef CONFIG_ACPI 70 - int st_sensors_match_acpi_device(struct device *dev) 71 - { 72 - const struct acpi_device_id *acpi_id; 73 - kernel_ulong_t driver_data = 0; 74 - 75 - if (ACPI_HANDLE(dev)) { 76 - acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); 77 - if (!acpi_id) { 78 - dev_err(dev, "No driver data\n"); 79 - return -EINVAL; 80 - } 81 - driver_data = acpi_id->driver_data; 82 - } 83 - return driver_data; 84 - } 85 - EXPORT_SYMBOL(st_sensors_match_acpi_device); 86 - #endif 87 70 88 71 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 89 72 MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
+1 -2
drivers/iio/gyro/st_gyro_i2c.c
··· 70 70 struct iio_dev *indio_dev; 71 71 int err; 72 72 73 - st_sensors_of_name_probe(&client->dev, st_gyro_of_match, 74 - client->name, sizeof(client->name)); 73 + st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name)); 75 74 76 75 settings = st_gyro_get_settings(client->name); 77 76 if (!settings) {
+1 -2
drivers/iio/gyro/st_gyro_spi.c
··· 74 74 struct iio_dev *indio_dev; 75 75 int err; 76 76 77 - st_sensors_of_name_probe(&spi->dev, st_gyro_of_match, 78 - spi->modalias, sizeof(spi->modalias)); 77 + st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias)); 79 78 80 79 settings = st_gyro_get_settings(spi->modalias); 81 80 if (!settings) {
+1 -2
drivers/iio/magnetometer/st_magn_i2c.c
··· 62 62 struct iio_dev *indio_dev; 63 63 int err; 64 64 65 - st_sensors_of_name_probe(&client->dev, st_magn_of_match, 66 - client->name, sizeof(client->name)); 65 + st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name)); 67 66 68 67 settings = st_magn_get_settings(client->name); 69 68 if (!settings) {
+1 -2
drivers/iio/magnetometer/st_magn_spi.c
··· 56 56 struct iio_dev *indio_dev; 57 57 int err; 58 58 59 - st_sensors_of_name_probe(&spi->dev, st_magn_of_match, 60 - spi->modalias, sizeof(spi->modalias)); 59 + st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias)); 61 60 62 61 settings = st_magn_get_settings(spi->modalias); 63 62 if (!settings) {
+1 -13
drivers/iio/pressure/st_pressure_i2c.c
··· 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 12 #include <linux/slab.h> 13 - #include <linux/acpi.h> 14 13 #include <linux/i2c.h> 15 14 #include <linux/iio/iio.h> 16 15 ··· 82 83 struct iio_dev *indio_dev; 83 84 int ret; 84 85 85 - if (client->dev.of_node) { 86 - st_sensors_of_name_probe(&client->dev, st_press_of_match, 87 - client->name, sizeof(client->name)); 88 - } else if (ACPI_HANDLE(&client->dev)) { 89 - ret = st_sensors_match_acpi_device(&client->dev); 90 - if ((ret < 0) || (ret >= ST_PRESS_MAX)) 91 - return -ENODEV; 92 - 93 - strlcpy(client->name, st_press_id_table[ret].name, 94 - sizeof(client->name)); 95 - } else if (!id) 96 - return -ENODEV; 86 + st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name)); 97 87 98 88 settings = st_press_get_settings(client->name); 99 89 if (!settings) {
+1 -2
drivers/iio/pressure/st_pressure_spi.c
··· 66 66 struct iio_dev *indio_dev; 67 67 int err; 68 68 69 - st_sensors_of_name_probe(&spi->dev, st_press_of_match, 70 - spi->modalias, sizeof(spi->modalias)); 69 + st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias)); 71 70 72 71 settings = st_press_get_settings(spi->modalias); 73 72 if (!settings) {
+1 -11
include/linux/iio/common/st_sensors.h
··· 315 315 ssize_t st_sensors_sysfs_scale_avail(struct device *dev, 316 316 struct device_attribute *attr, char *buf); 317 317 318 - #ifdef CONFIG_OF 319 - void st_sensors_of_name_probe(struct device *dev, 320 - const struct of_device_id *match, 321 - char *name, int len); 322 - #else 323 - static inline void st_sensors_of_name_probe(struct device *dev, 324 - const struct of_device_id *match, 325 - char *name, int len) 326 - { 327 - } 328 - #endif 318 + void st_sensors_dev_name_probe(struct device *dev, char *name, int len); 329 319 330 320 #endif /* ST_SENSORS_H */
-10
include/linux/iio/common/st_sensors_i2c.h
··· 12 12 13 13 #include <linux/i2c.h> 14 14 #include <linux/iio/common/st_sensors.h> 15 - #include <linux/of.h> 16 15 17 16 int st_sensors_i2c_configure(struct iio_dev *indio_dev, 18 17 struct i2c_client *client); 19 - 20 - #ifdef CONFIG_ACPI 21 - int st_sensors_match_acpi_device(struct device *dev); 22 - #else 23 - static inline int st_sensors_match_acpi_device(struct device *dev) 24 - { 25 - return -ENODEV; 26 - } 27 - #endif 28 18 29 19 #endif /* ST_SENSORS_I2C_H */