Skip to contentSkip to conversation

iio: use dev_get_platdata() to access platform_data

PATCH In review Andy Shevchenko 5 participants 31 messages Sep 2, 2024 – Sep 9, 2024

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover iio: use dev_get_platdata() to access platform_data

Unify how IIO drivers access platform_data field of struct device. In simple and straightforward cases constify the local variables.

(Not tested)

Andy Shevchenko (22):
iio: accel: hid-sensor-accel-3d: Get platform data via
dev_get_platdata()
iio: adc: ad7266: Get platform data via dev_get_platdata()
iio: adc: ad7791: Get platform data via dev_get_platdata()
iio: adc: ad7887: Get platform data via dev_get_platdata()
iio: adc: ad7793: Get platform data via dev_get_platdata()
iio: adc: ltc2497: Get platform data via dev_get_platdata()
iio: dac: ad5504: Get platform data via dev_get_platdata()
iio: dac: ad5791: Get platform data via dev_get_platdata()
iio: dac: m62332: Get platform data via dev_get_platdata()
iio: dac: max517: Get platform data via dev_get_platdata()
iio: frequency: ad9523: Get platform data via dev_get_platdata()
iio: frequency: adf4350: Get platform data via dev_get_platdata()
iio: gyro: hid-sensor-gyro-3d: Get platform data via
dev_get_platdata()
iio: imu: st_lsm6dsx: Get platform data via dev_get_platdata()
iio: light: hid-sensor-als: Get platform data via dev_get_platdata()
iio: light: hid-sensor-prox: Get platform data via dev_get_platdata()
iio: light: lm3533-als: Get platform data via dev_get_platdata()
iio: magnetometer: hid-sensor-magn-3d: Get platform data via
dev_get_platdata()
iio: orientation: hid-sensor-incl-3d: Get platform data via
dev_get_platdata()
iio: orientation: hid-sensor-rotation: Get platform data via
dev_get_platdata()
iio: position: hid-sensor-custom-intel-hinge: Get platform data via
dev_get_platdata()
iio: pressure: hid-sensor-press: Get platform data via
dev_get_platdata()

 drivers/iio/accel/hid-sensor-accel-3d.c           |  5 ++---
 drivers/iio/adc/ad7266.c                          |  2 +-
 drivers/iio/adc/ad7791.c                          |  4 ++--
 drivers/iio/adc/ad7793.c                          |  2 +-
 drivers/iio/adc/ad7887.c                          |  2 +-
 drivers/iio/adc/ltc2497-core.c                    | 15 +++++----------
 drivers/iio/dac/ad5504.c                          |  2 +-
 drivers/iio/dac/ad5791.c                          |  2 +-
 drivers/iio/dac/m62332.c                          |  2 +-
 drivers/iio/dac/max517.c                          |  4 ++--
 drivers/iio/frequency/ad9523.c                    |  2 +-
 drivers/iio/frequency/adf4350.c                   |  2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c             |  4 ++--
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c      | 15 +++++----------
 drivers/iio/light/hid-sensor-als.c                |  4 ++--
 drivers/iio/light/hid-sensor-prox.c               |  4 ++--
 drivers/iio/light/lm3533-als.c                    |  6 +++---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c     |  4 ++--
 drivers/iio/orientation/hid-sensor-incl-3d.c      |  4 ++--
 drivers/iio/orientation/hid-sensor-rotation.c     |  4 ++--
 .../iio/position/hid-sensor-custom-intel-hinge.c  |  4 ++--
 drivers/iio/pressure/hid-sensor-press.c           |  4 ++--
 22 files changed, 43 insertions(+), 54 deletions(-)
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/22 iio: accel: hid-sensor-accel-3d: Get platform data via dev_get_platdata()

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/accel/hid-sensor-accel-3d.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +2 -3
index 9b7a73a4c48a..caa183637422 100644
@@ -328,6 +328,7 @@ static int accel_3d_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_accel_3d_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	int ret = 0;
 	const char *name;
 	struct iio_dev *indio_dev;
@@ -335,8 +336,6 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 	const struct iio_chan_spec *channel_spec;
 	int channel_size;
 
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct accel_3d_state));
 	if (indio_dev == NULL)
@@ -424,7 +423,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_accel_3d_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct accel_3d_state *accel_state = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#2 lore raw

PATCH 2/22 iio: adc: ad7266: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/adc/ad7266.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7266.c +1 -1
index 7949b076fb87..858c8be2ff1a 100644
@@ -383,7 +383,7 @@ static const char * const ad7266_gpio_labels[] = {
 
 static int ad7266_probe(struct spi_device *spi)
 {
-	struct ad7266_platform_data *pdata = spi->dev.platform_data;
+	const struct ad7266_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct iio_dev *indio_dev;
 	struct ad7266_state *st;
 	unsigned int i;
Signature · 1 line
2.46.0
#3 lore raw

PATCH 3/22 iio: adc: ad7791: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/adc/ad7791.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7791.c +2 -2
index 86effe8501b4..5d2ad3dd6caa 100644
@@ -371,7 +371,7 @@ static const struct iio_info ad7791_no_filter_info = {
 };
 
 static int ad7791_setup(struct ad7791_state *st,
-			struct ad7791_platform_data *pdata)
+			const struct ad7791_platform_data *pdata)
 {
 	/* Set to poweron-reset default values */
 	st->mode = AD7791_MODE_BUFFER;
@@ -401,7 +401,7 @@ static void ad7791_reg_disable(void *reg)
 
 static int ad7791_probe(struct spi_device *spi)
 {
-	struct ad7791_platform_data *pdata = spi->dev.platform_data;
+	const struct ad7791_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct iio_dev *indio_dev;
 	struct ad7791_state *st;
 	int ret;
Signature · 1 line
2.46.0
#4 lore raw

PATCH 4/22 iio: adc: ad7887: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/adc/ad7887.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7887.c +1 -1
index 6265ce7df703..b301da9b88b1 100644
@@ -234,7 +234,7 @@ static void ad7887_reg_disable(void *data)
 
 static int ad7887_probe(struct spi_device *spi)
 {
-	struct ad7887_platform_data *pdata = spi->dev.platform_data;
+	const struct ad7887_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct ad7887_state *st;
 	struct iio_dev *indio_dev;
 	uint8_t mode;
Signature · 1 line
2.46.0
#5 lore raw

PATCH 5/22 iio: adc: ad7793: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/adc/ad7793.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7793.c +1 -1
index abebd519cafa..b86e89370e0d 100644
@@ -770,7 +770,7 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
 
 static int ad7793_probe(struct spi_device *spi)
 {
-	const struct ad7793_platform_data *pdata = spi->dev.platform_data;
+	const struct ad7793_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct ad7793_state *st;
 	struct iio_dev *indio_dev;
 	int ret, vref_mv = 0;
Signature · 1 line
2.46.0
#6 lore raw

PATCH 6/22 iio: adc: ltc2497: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

While at it, drop duplicate NULL check that iio_map_array_register() already has.

---
 drivers/iio/adc/ltc2497-core.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/iio/adc/ltc2497-core.c +5 -10
index 996f6cbbed3c..ad8ddf80310e 100644
@@ -168,6 +168,7 @@ static const struct iio_info ltc2497core_info = {
 int ltc2497core_probe(struct device *dev, struct iio_dev *indio_dev)
 {
 	struct ltc2497core_driverdata *ddata = iio_priv(indio_dev);
+	struct iio_map *plat_data = dev_get_platdata(dev);
 	int ret;
 
 	/*
@@ -200,16 +201,10 @@ int ltc2497core_probe(struct device *dev, struct iio_dev *indio_dev)
 		return ret;
 	}
 
-	if (dev->platform_data) {
-		struct iio_map *plat_data;
-
-		plat_data = (struct iio_map *)dev->platform_data;
-
-		ret = iio_map_array_register(indio_dev, plat_data);
-		if (ret) {
-			dev_err(&indio_dev->dev, "iio map err: %d\n", ret);
-			goto err_regulator_disable;
-		}
+	ret = iio_map_array_register(indio_dev, plat_data);
+	if (ret) {
+		dev_err(&indio_dev->dev, "iio map err: %d\n", ret);
+		goto err_regulator_disable;
 	}
 
 	ddata->addr_prev = LTC2497_CONFIG_DEFAULT;
Signature · 1 line
2.46.0
#7 lore raw

PATCH 7/22 iio: dac: ad5504: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/dac/ad5504.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ad5504.c +1 -1
index e6c5be728bb2..305cd58cd257 100644
@@ -270,7 +270,7 @@ static const struct iio_chan_spec ad5504_channels[] = {
 
 static int ad5504_probe(struct spi_device *spi)
 {
-	struct ad5504_platform_data *pdata = spi->dev.platform_data;
+	const struct ad5504_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct iio_dev *indio_dev;
 	struct ad5504_state *st;
 	struct regulator *reg;
Signature · 1 line
2.46.0
#8 lore raw

PATCH 8/22 iio: dac: ad5791: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/dac/ad5791.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ad5791.c +1 -1
index 75b549827e15..553431bf0232 100644
@@ -341,7 +341,7 @@ static const struct iio_info ad5791_info = {
 
 static int ad5791_probe(struct spi_device *spi)
 {
-	struct ad5791_platform_data *pdata = spi->dev.platform_data;
+	const struct ad5791_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct iio_dev *indio_dev;
 	struct ad5791_state *st;
 	int ret, pos_voltage_uv = 0, neg_voltage_uv = 0;
Signature · 1 line
2.46.0
#9 lore raw

PATCH 9/22 iio: dac: m62332: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/dac/m62332.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/m62332.c +1 -1
index ae53baccec91..3497513854d7 100644
@@ -201,7 +201,7 @@ static int m62332_probe(struct i2c_client *client)
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &m62332_info;
 
-	ret = iio_map_array_register(indio_dev, client->dev.platform_data);
+	ret = iio_map_array_register(indio_dev, dev_get_platdata(&client->dev));
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.46.0
#10 lore raw

PATCH 10/22 iio: dac: max517: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/dac/max517.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/dac/max517.c +2 -2
index 685980184d3c..96781ae04f9d 100644
@@ -143,10 +143,10 @@ static const struct iio_chan_spec max517_channels[] = {
 
 static int max517_probe(struct i2c_client *client)
 {
+	const struct max517_platform_data *platform_data = dev_get_platdata(&client->dev);
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
 	struct max517_data *data;
 	struct iio_dev *indio_dev;
-	struct max517_platform_data *platform_data = client->dev.platform_data;
 	int chan;
 
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
@@ -176,7 +176,7 @@ static int max517_probe(struct i2c_client *client)
 
 	/*
 	 * Reference voltage on MAX518 and default is 5V, else take vref_mv
-	 * from platform_data
+	 * from platform_data.
 	 */
 	for (chan = 0; chan < indio_dev->num_channels; chan++) {
 		if (id->driver_data == ID_MAX518 || !platform_data)
Signature · 1 line
2.46.0
maintainer
#11 lore raw

Re: [PATCH v1 10/22] iio: dac: max517: Get platform data via dev_get_platdata()

Quoted 26 lines · On Tue, 3 Sep 2024 01:16:55 +0300 Andy Shevchenko <[email protected]>…

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/dac/max517.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/dac/max517.c +1 -1
index 685980184d3c..96781ae04f9d 100644
@@ -143,10 +143,10 @@ static const struct iio_chan_spec max517_channels[] = {
 
 static int max517_probe(struct i2c_client *client)
 {
+	const struct max517_platform_data *platform_data = dev_get_platdata(&client->dev);
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
 	struct max517_data *data;
 	struct iio_dev *indio_dev;
-	struct max517_platform_data *platform_data = client->dev.platform_data;
 	int chan;
 
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));

drivers/iio/dac/max517.c static int max517_probe(struct i2c_client *client) · line 179

Quoted 5 lines
drivers/iio/dac/max517.c +1 -1
@@ -176,7 +176,7 @@ static int max517_probe(struct i2c_client *client)
 
 	/*
 	 * Reference voltage on MAX518 and default is 5V, else take vref_mv
-	 * from platform_data
+	 * from platform_data.

I guess this is accidental?

J

Quoted 3 lines
drivers/iio/dac/max517.c +0 -0
 	 */
 	for (chan = 0; chan < indio_dev->num_channels; chan++) {
 		if (id->driver_data == ID_MAX518 || !platform_data)
#12 lore raw

Re: [PATCH v1 10/22] iio: dac: max517: Get platform data via dev_get_platdata()

Quoted 2 lines · Jonathan Cameron

On Tue, 3 Sep 2024 01:16:55 +0300
Andy Shevchenko <[email protected]> wrote:

...

Quoted 5 lines

drivers/iio/dac/max517.c static int max517_probe(struct i2c_client *client) · line 179

Quoted 3 lines
drivers/iio/dac/max517.c +1 -1
 	 * Reference voltage on MAX518 and default is 5V, else take vref_mv
-	 * from platform_data
+	 * from platform_data.

I guess this is accidental?

It can be dropped.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

PATCH 11/22 iio: frequency: ad9523: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/frequency/ad9523.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/frequency/ad9523.c +1 -1
index b391c6e27ab0..b1554ced7a26 100644
@@ -970,7 +970,7 @@ static int ad9523_setup(struct iio_dev *indio_dev)
 
 static int ad9523_probe(struct spi_device *spi)
 {
-	struct ad9523_platform_data *pdata = spi->dev.platform_data;
+	struct ad9523_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct iio_dev *indio_dev;
 	struct ad9523_state *st;
 	int ret;
Signature · 1 line
2.46.0
#14 lore raw

PATCH 12/22 iio: frequency: adf4350: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/frequency/adf4350.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/frequency/adf4350.c +1 -1
index e13e64a5164c..61828e61e275 100644
@@ -603,7 +603,7 @@ static int adf4350_probe(struct spi_device *spi)
 		if (pdata == NULL)
 			return -EINVAL;
 	} else {
-		pdata = spi->dev.platform_data;
+		pdata = dev_get_platdata(&spi->dev);
 	}
 
 	if (!pdata) {
Signature · 1 line
2.46.0
#15 lore raw

PATCH 13/22 iio: gyro: hid-sensor-gyro-3d: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/gyro/hid-sensor-gyro-3d.c +2 -2
index 59a38bf9459b..490c325897bd 100644
@@ -279,11 +279,11 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_gyro_3d_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	int ret = 0;
 	static const char *name = "gyro_3d";
 	struct iio_dev *indio_dev;
 	struct gyro_3d_state *gyro_state;
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*gyro_state));
 	if (!indio_dev)
@@ -361,7 +361,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_gyro_3d_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct gyro_3d_state *gyro_state = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#16 lore raw

PATCH 14/22 iio: imu: st_lsm6dsx: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +5 -10
index ed0267929725..3958b5e1a3f6 100644
@@ -2132,14 +2132,11 @@ st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
 			const struct st_lsm6dsx_reg **drdy_reg)
 {
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	int err = 0, drdy_pin;
 
-	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) {
-		struct st_sensors_platform_data *pdata;
-
-		pdata = (struct st_sensors_platform_data *)dev->platform_data;
+	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0)
 		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
-	}
 
 	switch (drdy_pin) {
 	case 1:
@@ -2162,14 +2159,13 @@ st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
 static int st_lsm6dsx_init_shub(struct st_lsm6dsx_hw *hw)
 {
 	const struct st_lsm6dsx_shub_settings *hub_settings;
-	struct st_sensors_platform_data *pdata;
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	unsigned int data;
 	int err = 0;
 
 	hub_settings = &hw->settings->shub_settings;
 
-	pdata = (struct st_sensors_platform_data *)dev->platform_data;
 	if (device_property_read_bool(dev, "st,pullups") ||
 	    (pdata && pdata->pullups)) {
 		if (hub_settings->pullup_en.sec_page) {
@@ -2524,9 +2520,9 @@ static irqreturn_t st_lsm6dsx_sw_trigger_handler_thread(int irq,
 
 static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 {
-	struct st_sensors_platform_data *pdata;
 	const struct st_lsm6dsx_reg *reg;
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	unsigned long irq_type;
 	bool irq_active_low;
 	int err;
@@ -2554,7 +2550,6 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 	if (err < 0)
 		return err;
 
-	pdata = (struct st_sensors_platform_data *)dev->platform_data;
 	if (device_property_read_bool(dev, "drive-open-drain") ||
 	    (pdata && pdata->open_drain)) {
 		reg = &hw->settings->irq_config.od;
@@ -2639,7 +2634,7 @@ static int st_lsm6dsx_init_regulators(struct device *dev)
 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 		     struct regmap *regmap)
 {
-	struct st_sensors_platform_data *pdata = dev->platform_data;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	const struct st_lsm6dsx_shub_settings *hub_settings;
 	struct st_lsm6dsx_hw *hw;
 	const char *name = NULL;
Signature · 1 line
2.46.0
maintainer
#17 lore raw

Re: [PATCH v1 14/22] iio: imu: st_lsm6dsx: Get platform data via dev_get_platdata()

Quoted 14 lines

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +0 -0
index ed0267929725..3958b5e1a3f6 100644

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, · line 2135

Quoted 4 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +1 -0
@@ -2132,14 +2132,11 @@ st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
 			const struct st_lsm6dsx_reg **drdy_reg)
 {
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);

nit: I guess you can move pdata pointer in the 'if' block, since it is just used there.

Regards,
Lorenzo

Quoted 59 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4 -10
 	int err = 0, drdy_pin;
 
-	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) {
-		struct st_sensors_platform_data *pdata;
-
-		pdata = (struct st_sensors_platform_data *)dev->platform_data;
+	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0)
 		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
-	}
 
 	switch (drdy_pin) {
 	case 1:
@@ -2162,14 +2159,13 @@ st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
 static int st_lsm6dsx_init_shub(struct st_lsm6dsx_hw *hw)
 {
 	const struct st_lsm6dsx_shub_settings *hub_settings;
-	struct st_sensors_platform_data *pdata;
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	unsigned int data;
 	int err = 0;
 
 	hub_settings = &hw->settings->shub_settings;
 
-	pdata = (struct st_sensors_platform_data *)dev->platform_data;
 	if (device_property_read_bool(dev, "st,pullups") ||
 	    (pdata && pdata->pullups)) {
 		if (hub_settings->pullup_en.sec_page) {
@@ -2524,9 +2520,9 @@ static irqreturn_t st_lsm6dsx_sw_trigger_handler_thread(int irq,
 
 static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 {
-	struct st_sensors_platform_data *pdata;
 	const struct st_lsm6dsx_reg *reg;
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	unsigned long irq_type;
 	bool irq_active_low;
 	int err;
@@ -2554,7 +2550,6 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 	if (err < 0)
 		return err;
 
-	pdata = (struct st_sensors_platform_data *)dev->platform_data;
 	if (device_property_read_bool(dev, "drive-open-drain") ||
 	    (pdata && pdata->open_drain)) {
 		reg = &hw->settings->irq_config.od;
@@ -2639,7 +2634,7 @@ static int st_lsm6dsx_init_regulators(struct device *dev)
 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 		     struct regmap *regmap)
 {
-	struct st_sensors_platform_data *pdata = dev->platform_data;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	const struct st_lsm6dsx_shub_settings *hub_settings;
 	struct st_lsm6dsx_hw *hw;
 	const char *name = NULL;
Signature · 1 line
2.46.0
#18 lore raw

Re: [PATCH v1 14/22] iio: imu: st_lsm6dsx: Get platform data via dev_get_platdata()

On Tue, Sep 3, 2024 at 10:11 AM Lorenzo Bianconi <[email protected]> wrote:

...

Quoted 5 lines
Quoted 2 lines
      struct device *dev = hw->dev;

+ const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);

nit: I guess you can move pdata pointer in the 'if' block, since it is just used there.

Yes, but it will increase the LoCs number by 3 for no benefit for each of such cases.

Quoted 9 lines
Quoted 9 lines
      int err = 0, drdy_pin;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +1 -5
-     if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) {
-             struct st_sensors_platform_data *pdata;
-
-             pdata = (struct st_sensors_platform_data *)dev->platform_data;
+     if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0)
              drdy_pin = pdata ? pdata->drdy_int_pin : 1;
-     }
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#19 lore raw

PATCH 15/22 iio: light: hid-sensor-als: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/light/hid-sensor-als.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/light/hid-sensor-als.c +2 -2
index 260281194f61..0d995bc7877e 100644
@@ -356,11 +356,11 @@ static int als_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_als_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	int ret = 0;
 	static const char *name = "als";
 	struct iio_dev *indio_dev;
 	struct als_state *als_state;
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct als_state));
 	if (!indio_dev)
@@ -438,7 +438,7 @@ static int hid_als_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_als_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct als_state *als_state = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#20 lore raw

PATCH 16/22 iio: light: hid-sensor-prox: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/light/hid-sensor-prox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/light/hid-sensor-prox.c +2 -2
index 26c481d2998c..5343ebd404bf 100644
@@ -233,11 +233,11 @@ static int prox_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_prox_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	int ret = 0;
 	static const char *name = "prox";
 	struct iio_dev *indio_dev;
 	struct prox_state *prox_state;
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 				sizeof(struct prox_state));
@@ -315,7 +315,7 @@ static int hid_prox_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_prox_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct prox_state *prox_state = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#21 lore raw

PATCH 17/22 iio: light: lm3533-als: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/light/lm3533-als.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/light/lm3533-als.c +3 -3
index 7800f7fa51b7..6429d951ce7f 100644
@@ -754,7 +754,7 @@ static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
 }
 
 static int lm3533_als_setup(struct lm3533_als *als,
-			    struct lm3533_als_platform_data *pdata)
+			    const struct lm3533_als_platform_data *pdata)
 {
 	int ret;
 
@@ -828,8 +828,8 @@ static const struct iio_info lm3533_als_info = {
 
 static int lm3533_als_probe(struct platform_device *pdev)
 {
+	const struct lm3533_als_platform_data *pdata;
 	struct lm3533 *lm3533;
-	struct lm3533_als_platform_data *pdata;
 	struct lm3533_als *als;
 	struct iio_dev *indio_dev;
 	int ret;
@@ -838,7 +838,7 @@ static int lm3533_als_probe(struct platform_device *pdev)
 	if (!lm3533)
 		return -EINVAL;
 
-	pdata = pdev->dev.platform_data;
+	pdata = dev_get_platdata(&pdev->dev);
 	if (!pdata) {
 		dev_err(&pdev->dev, "no platform data\n");
 		return -EINVAL;
Signature · 1 line
2.46.0
#23 lore raw

PATCH 18/22 iio: magnetometer: hid-sensor-magn-3d: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/hid-sensor-magn-3d.c +2 -2
index 5c795a430d09..ae10db87d1e1 100644
@@ -466,11 +466,11 @@ static int magn_3d_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_magn_3d_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	int ret = 0;
 	static char *name = "magn_3d";
 	struct iio_dev *indio_dev;
 	struct magn_3d_state *magn_state;
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 	struct iio_chan_spec *channels;
 	int chan_count = 0;
 
@@ -549,7 +549,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_magn_3d_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct magn_3d_state *magn_state = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#24 lore raw

PATCH 19/22 iio: orientation: hid-sensor-incl-3d: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/orientation/hid-sensor-incl-3d.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/orientation/hid-sensor-incl-3d.c +2 -2
index 8943d5c78bc0..21664563b565 100644
@@ -299,11 +299,11 @@ static int incl_3d_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_incl_3d_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	int ret;
 	static char *name = "incli_3d";
 	struct iio_dev *indio_dev;
 	struct incl_3d_state *incl_state;
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct incl_3d_state));
@@ -385,7 +385,7 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_incl_3d_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct incl_3d_state *incl_state = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#25 lore raw

PATCH 20/22 iio: orientation: hid-sensor-rotation: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/orientation/hid-sensor-rotation.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/orientation/hid-sensor-rotation.c +2 -2
index 5e8cadd5177a..107adadf7711 100644
@@ -230,11 +230,11 @@ static int dev_rot_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_dev_rot_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	int ret;
 	char *name;
 	struct iio_dev *indio_dev;
 	struct dev_rot_state *rot_state;
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct dev_rot_state));
@@ -329,7 +329,7 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_dev_rot_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct dev_rot_state *rot_state = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#26 lore raw

PATCH 21/22 iio: position: hid-sensor-custom-intel-hinge: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/position/hid-sensor-custom-intel-hinge.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/position/hid-sensor-custom-intel-hinge.c +2 -2
index 76e173850a35..63a9f2fcada7 100644
@@ -263,9 +263,9 @@ static int hinge_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_hinge_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct hinge_state *st;
 	struct iio_dev *indio_dev;
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 	int ret;
 	int i;
 
@@ -344,7 +344,7 @@ static int hid_hinge_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_hinge_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct hinge_state *st = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#27 lore raw

PATCH 22/22 iio: pressure: hid-sensor-press: Get platform data via dev_get_platdata()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/iio/pressure/hid-sensor-press.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/pressure/hid-sensor-press.c +2 -2
index 956045e2db29..b7e9a085f0cc 100644
@@ -241,11 +241,11 @@ static int press_parse_report(struct platform_device *pdev,
 /* Function to initialize the processing for usage id */
 static int hid_press_probe(struct platform_device *pdev)
 {
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	int ret = 0;
 	static const char *name = "press";
 	struct iio_dev *indio_dev;
 	struct press_state *press_state;
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 				sizeof(struct press_state));
@@ -325,7 +325,7 @@ static int hid_press_probe(struct platform_device *pdev)
 /* Function to deinitialize the processing for usage id */
 static void hid_press_remove(struct platform_device *pdev)
 {
-	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct press_state *press_state = iio_priv(indio_dev);
 
Signature · 1 line
2.46.0
#28 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

Unify how IIO drivers access platform_data field of struct device. In simple and straightforward cases constify the local variables.

(Not tested)

Jonathan, in case you are fine with the series, feel free to squash, e.g., changes against hid-sensor drivers.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#29 lore raw
Quoted 8 lines · On Tue, 3 Sep 2024 20:57:27 +0300 Andy Shevchenko…
Quoted 4 lines · Andy Shevchenko

Unify how IIO drivers access platform_data field of struct device. In simple and straightforward cases constify the local variables.

(Not tested)

Jonathan, in case you are fine with the series, feel free to squash, e.g., changes against hid-sensor drivers.

I don't follow, but maybe that will become clear once I've looked at rest of the stuff I haven't read yet.

Anyhow, applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons. Another series that will probably be 6.13 material.

Thanks,

Jonathan

Quoted 1 line
#30 lore raw
Quoted 6 lines · Jonathan Cameron
Quoted 4 lines · On Tue, 3 Sep 2024 20:57:27 +0300 Andy Shevchenko…
Quoted 3 lines · Andy Shevchenko

Unify how IIO drivers access platform_data field of struct device. In simple and straightforward cases constify the local variables.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

(Not tested)

Jonathan, in case you are fine with the series, feel free to squash, e.g., changes against hid-sensor drivers.

I don't follow, but maybe that will become clear once I've looked at rest of the stuff I haven't read yet.

I mean all the patches that starts with "iio: *: hid-sensor-*:" can be squashed into one with "iio: hid-sensor:"

Quoted 2 lines

Anyhow, applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons. Another series that will probably be 6.13 material.

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko