iio: simplify with spi_get_device_match_data()
Subsystems (8)
cover iio: simplify with spi_get_device_match_data()
Not tested on hardware, but code looks equivalent and should not have functional effect.
Best regards,
Krzysztof
---
Krzysztof Kozlowski (8):
iio: accel: adxl313: simplify with spi_get_device_match_data()
iio: accel: adxl355: simplify with spi_get_device_match_data()
iio: adc: max11205: simplify with spi_get_device_match_data()
iio: adc: ti-ads131e08: simplify with spi_get_device_match_data()
iio: adc: ti-tsc2046: simplify with spi_get_device_match_data()
iio: addac: ad74413r: simplify with spi_get_device_match_data()
iio: dac: max5522: simplify with spi_get_device_match_data()
iio: adc: mcp3564: drop redundant open-coded spi_get_device_match_data()
drivers/iio/accel/adxl313_spi.c | 8 +------- drivers/iio/accel/adxl355_spi.c | 10 +++------- drivers/iio/adc/max11205.c | 5 +---- drivers/iio/adc/mcp3564.c | 6 ------ drivers/iio/adc/ti-ads131e08.c | 4 +--- drivers/iio/adc/ti-tsc2046.c | 7 +------ drivers/iio/addac/ad74413r.c | 13 +++---------- drivers/iio/dac/max5522.c | 11 +++-------- 8 files changed, 13 insertions(+), 51 deletions(-)
---
base-commit: ed3dab9323648a17a85908c574787be12d4cc871
change-id: 20240606-spi-match-data-6bf7c51ba913
Best regards,
Signature · 1 line
Krzysztof Kozlowski <[email protected]>
PATCH 1/8 iio: accel: adxl313: simplify with spi_get_device_match_data()
Use spi_get_device_match_data() helper to simplify a bit the driver.
--- drivers/iio/accel/adxl313_spi.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/iio/accel/adxl313_spi.c +1 -7
@@ -72,13 +72,7 @@ static int adxl313_spi_probe(struct spi_device *spi)if (ret)return ret; -/* -* Retrieves device specific data as a pointer to a -* adxl313_chip_info structure -*/ - chip_data =device_get_match_data (&spi->dev); -if (!chip_data) - chip_data = (const struct adxl313_chip_info *)spi_get_device_id (spi)->driver_data; + chip_data =spi_get_device_match_data (spi); regmap =devm_regmap_init_spi (spi, &adxl31x_spi_regmap_config[chip_data->type]);
Signature · 1 line
2.43.0
Re: [PATCH 1/8] iio: accel: adxl313: simplify with spi_get_device_match_data()
Quoted 24 lines · Krzysztof Kozlowski
Use
spi_get_device_match_data()helper to simplify a bit the driver.Signed-off-by Krzysztof Kozlowski <[email protected]>---
drivers/iio/accel/adxl313_spi.c | 8 +-------1 file changed, 1 insertion(+), 7 deletions(-)drivers/iio/accel/adxl313_spi.c +0
-0@@ -72,13 +72,7 @@ static int adxl313_spi_probe(struct spi_device *spi) if (ret) return ret;drivers/iio/accel/adxl313_spi.c +0
-7-/* -* Retrieves device specific data as a pointer to a -* adxl313_chip_info structure -*/ - chip_data =device_get_match_data (&spi->dev); -if (!chip_data) - chip_data = (const struct adxl313_chip_info*)spi_get_device_id(spi)->driver_data;
drivers/iio/accel/adxl313_spi.c +1
-0+ chip_data =spi_get_device_match_data (spi);
Quoted 1 line
I understand you're sticking with the original code but since you're doing this, could we maybe add proper error checking for the call? Maybe Jonathan can even tweak that while applying...
(same comment for patch 3)
- Nuno Sá
Re: [PATCH 1/8] iio: accel: adxl313: simplify with spi_get_device_match_data()
Quoted 31 lines · Nuno Sá
Quoted 24 lines · Krzysztof Kozlowski
Use
spi_get_device_match_data()helper to simplify a bit the driver.Signed-off-by Krzysztof Kozlowski <[email protected]>---
drivers/iio/accel/adxl313_spi.c | 8 +-------1 file changed, 1 insertion(+), 7 deletions(-)drivers/iio/accel/adxl313_spi.c +0
-0@@ -72,13 +72,7 @@ static int adxl313_spi_probe(struct spi_device *spi) if (ret) return ret;drivers/iio/accel/adxl313_spi.c +0
-7-/* -* Retrieves device specific data as a pointer to a -* adxl313_chip_info structure -*/ - chip_data =device_get_match_data (&spi->dev); -if (!chip_data) - chip_data = (const struct adxl313_chip_info*)spi_get_device_id(spi)->driver_data;
drivers/iio/accel/adxl313_spi.c +1
-0+ chip_data =spi_get_device_match_data (spi);Quoted 1 line
I understand you're sticking with the original code but since you're doing this, could we maybe add proper error checking for the call? Maybe Jonathan can even tweak that while applying...
Quoted 1 line
(same comment for patch 3)
I consider that a separate patch/work, because it would have functional impact.
Best regards,
Krzysztof
Jonathan Cameron
maintainerRe: [PATCH 1/8] iio: accel: adxl313: simplify with spi_get_device_match_data()
Quoted 32 lines · On Fri, 7 Jun 2024 11:18:54 +0200 Krzysztof Kozlowski…
Quoted 31 lines · Nuno Sá
Quoted 24 lines · Krzysztof Kozlowski
Use
spi_get_device_match_data()helper to simplify a bit the driver.Signed-off-by Krzysztof Kozlowski <[email protected]>---
drivers/iio/accel/adxl313_spi.c | 8 +-------1 file changed, 1 insertion(+), 7 deletions(-)drivers/iio/accel/adxl313_spi.c +0
-0@@ -72,13 +72,7 @@ static int adxl313_spi_probe(struct spi_device *spi) if (ret) return ret;drivers/iio/accel/adxl313_spi.c +0
-7-/* -* Retrieves device specific data as a pointer to a -* adxl313_chip_info structure -*/ - chip_data =device_get_match_data (&spi->dev); -if (!chip_data) - chip_data = (const struct adxl313_chip_info*)spi_get_device_id(spi)->driver_data;
drivers/iio/accel/adxl313_spi.c +1
-0+ chip_data =spi_get_device_match_data (spi);Quoted 1 line
I understand you're sticking with the original code but since you're doing this, could we maybe add proper error checking for the call? Maybe Jonathan can even tweak that while applying...
Quoted 4 lines
Quoted 1 line
(same comment for patch 3)
I consider that a separate patch/work, because it would have functional impact.
Agreed. Though error checking on these is normally paranoia / readability thing as we probed from some firmware match and all those entries are present, so it should just work.
Quoted 4 lines
Best regards,
Krzysztof
PATCH 2/8 iio: accel: adxl355: simplify with spi_get_device_match_data()
In reply to Krzysztof KozlowskiUse spi_get_device_match_data() helper to simplify a bit the driver.
--- drivers/iio/accel/adxl355_spi.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/iio/accel/adxl355_spi.c +3 -7
@@ -28,13 +28,9 @@ static int adxl355_spi_probe(struct spi_device *spi)const struct adxl355_chip_info *chip_data;struct regmap *regmap; - chip_data =device_get_match_data (&spi->dev); -if (!chip_data) { - chip_data = (void *)spi_get_device_id (spi)->driver_data; - -if (!chip_data) -return -EINVAL ; - } + chip_data =spi_get_device_match_data (spi); +if (!chip_data) +return -EINVAL ; regmap =devm_regmap_init_spi (spi, &adxl355_spi_regmap_config);if (IS_ERR (regmap)) {
Signature · 1 line
2.43.0
PATCH 3/8 iio: adc: max11205: simplify with spi_get_device_match_data()
In reply to Krzysztof KozlowskiUse spi_get_device_match_data() helper to simplify a bit the driver.
--- drivers/iio/adc/max11205.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/adc/max11205.c +1 -4
@@ -116,10 +116,7 @@ static int max11205_probe(struct spi_device *spi)ad_sd_init (&st->sd, indio_dev, spi, &max11205_sigma_delta_info); - st->chip_info =device_get_match_data (&spi->dev); -if (!st->chip_info) - st->chip_info = - (const struct max11205_chip_info *)spi_get_device_id (spi)->driver_data; + st->chip_info =spi_get_device_match_data (spi); indio_dev->name = st->chip_info->name; indio_dev->modes =INDIO_DIRECT_MODE ;
Signature · 1 line
2.43.0
PATCH 4/8 iio: adc: ti-ads131e08: simplify with spi_get_device_match_data()
In reply to Krzysztof KozlowskiUse spi_get_device_match_data() helper to simplify a bit the driver.
--- drivers/iio/adc/ti-ads131e08.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/adc/ti-ads131e08.c +1 -3
@@ -802,9 +802,7 @@ static int ads131e08_probe(struct spi_device *spi)unsigned long adc_clk_ns;int ret; - info =device_get_match_data (&spi->dev); -if (!info) - info = (void *)spi_get_device_id (spi)->driver_data; + info =spi_get_device_match_data (spi);if (!info) {dev_err (&spi->dev,"failed to get match data\n" );return -ENODEV ;
Signature · 1 line
2.43.0
PATCH 5/8 iio: adc: ti-tsc2046: simplify with spi_get_device_match_data()
In reply to Krzysztof KozlowskiUse spi_get_device_match_data() helper to simplify a bit the driver.
--- drivers/iio/adc/ti-tsc2046.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/iio/adc/ti-tsc2046.c +1 -6
@@ -804,12 +804,7 @@ static int tsc2046_adc_probe(struct spi_device *spi)return -EINVAL ; } - dcfg =device_get_match_data (dev); -if (!dcfg) { -const struct spi_device_id *id =spi_get_device_id (spi); - - dcfg = (const struct tsc2046_adc_dcfg *)id->driver_data; - } + dcfg =spi_get_device_match_data (spi);if (!dcfg)return -EINVAL ;
Signature · 1 line
2.43.0
PATCH 6/8 iio: addac: ad74413r: simplify with spi_get_device_match_data()
In reply to Krzysztof KozlowskiUse spi_get_device_match_data() helper to simplify a bit the driver.
--- drivers/iio/addac/ad74413r.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/iio/addac/ad74413r.c +3 -10
@@ -1365,16 +1365,9 @@ static int ad74413r_probe(struct spi_device *spi) st->spi = spi; st->dev = &spi->dev; - st->chip_info =device_get_match_data (&spi->dev); -if (!st->chip_info) { -const struct spi_device_id *id =spi_get_device_id (spi); - -if (id) - st->chip_info = - (struct ad74413r_chip_info *)id->driver_data; -if (!st->chip_info) -return -EINVAL ; - } + st->chip_info =spi_get_device_match_data (spi); +if (!st->chip_info) +return -EINVAL ;mutex_init (&st->lock);init_completion (&st->adc_data_completion);
Signature · 1 line
2.43.0
PATCH 7/8 iio: dac: max5522: simplify with spi_get_device_match_data()
In reply to Krzysztof KozlowskiUse spi_get_device_match_data() helper to simplify a bit the driver.
--- drivers/iio/dac/max5522.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/iio/dac/max5522.c +3 -8
@@ -132,7 +132,6 @@ static const struct regmap_config max5522_regmap_config = {static int max5522_spi_probe (struct spi_device *spi) { -const struct spi_device_id *id =spi_get_device_id (spi);struct iio_dev *indio_dev;struct max5522_state *state;int ret;
@@ -144,13 +143,9 @@ static int max5522_spi_probe(struct spi_device *spi) } state =iio_priv (indio_dev); - state->chip_info =device_get_match_data (&spi->dev); -if (!state->chip_info) { - state->chip_info = - (struct max5522_chip_info *)(id->driver_data); -if (!state->chip_info) -return -EINVAL ; - } + state->chip_info =spi_get_device_match_data (spi); +if (!state->chip_info) +return -EINVAL ; state->vrefin_reg =devm_regulator_get (&spi->dev,"vrefin" );if (IS_ERR (state->vrefin_reg))
Signature · 1 line
2.43.0
PATCH 8/8 iio: adc: mcp3564: drop redundant open-coded spi_get_device_match_data()
In reply to Krzysztof KozlowskiThe driver calls spi_get_device_match_data() and on its failure calls again parts of it: spi_get_device_id() and getting driver data. This is entirely redundant, because it is part of spi_get_device_match_data().
--- drivers/iio/adc/mcp3564.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/iio/adc/mcp3564.c +0 -6
@@ -1114,7 +1114,6 @@ static int mcp3564_config(struct iio_dev *indio_dev) {struct mcp3564_state *adc =iio_priv (indio_dev);struct device *dev = &adc->spi->dev; -const struct spi_device_id *dev_id;u8 tmp_reg;u16 tmp_u16;enum mcp3564_ids ids;
@@ -1212,11 +1211,6 @@ static int mcp3564_config(struct iio_dev *indio_dev)* try using fallback compatible in device tree to deal with some newer part number. */ adc->chip_info =spi_get_device_match_data (adc->spi); -if (!adc->chip_info) { - dev_id =spi_get_device_id (adc->spi); - adc->chip_info = (const struct mcp3564_chip_info *)dev_id->driver_data; - } - adc->have_vref = adc->chip_info->have_vref; }else { adc->chip_info = &mcp3564_chip_infos_tbl[ids];
Signature · 1 line
2.43.0
Quoted 25 lines · Krzysztof Kozlowski
Not tested on hardware, but code looks equivalent and should not have functional effect.
Best regards,
Krzysztof---
Krzysztof Kozlowski (8):
iio: accel: adxl313: simplify withspi_get_device_match_data()
iio: accel: adxl355: simplify withspi_get_device_match_data()
iio: adc: max11205: simplify withspi_get_device_match_data()
iio: adc: ti-ads131e08: simplify withspi_get_device_match_data()
iio: adc: ti-tsc2046: simplify withspi_get_device_match_data()
iio: addac: ad74413r: simplify withspi_get_device_match_data()
iio: dac: max5522: simplify withspi_get_device_match_data()
iio: adc: mcp3564: drop redundant open-codedspi_get_device_match_data()drivers/iio/accel/adxl313_spi.c | 8 +-------
drivers/iio/accel/adxl355_spi.c| 10 +++------- drivers/iio/adc/max11205.c | 5 +---- drivers/iio/adc/mcp3564.c | 6 ------ drivers/iio/adc/ti-ads131e08.c | 4 +--- drivers/iio/adc/ti-tsc2046.c | 7 +------ drivers/iio/addac/ad74413r.c | 13 +++---------- drivers/iio/dac/max5522.c | 11 +++--------
Quoted 2 lines
8 files changed, 13 insertions(+), 51 deletions(-)---
LGTM, just some minor comments/asks that don't really stop me from:
Quoted 29 lines · On Fri, 07 Jun 2024 10:55:44 +0200 Nuno Sá <[email protected]> wrote:
Quoted 25 lines · Krzysztof Kozlowski
Not tested on hardware, but code looks equivalent and should not have functional effect.
Best regards,
Krzysztof---
Krzysztof Kozlowski (8):
iio: accel: adxl313: simplify withspi_get_device_match_data()
iio: accel: adxl355: simplify withspi_get_device_match_data()
iio: adc: max11205: simplify withspi_get_device_match_data()
iio: adc: ti-ads131e08: simplify withspi_get_device_match_data()
iio: adc: ti-tsc2046: simplify withspi_get_device_match_data()
iio: addac: ad74413r: simplify withspi_get_device_match_data()
iio: dac: max5522: simplify withspi_get_device_match_data()
iio: adc: mcp3564: drop redundant open-codedspi_get_device_match_data()drivers/iio/accel/adxl313_spi.c | 8 +-------
drivers/iio/accel/adxl355_spi.c| 10 +++------- drivers/iio/adc/max11205.c | 5 +---- drivers/iio/adc/mcp3564.c | 6 ------ drivers/iio/adc/ti-ads131e08.c | 4 +--- drivers/iio/adc/ti-tsc2046.c | 7 +------ drivers/iio/addac/ad74413r.c | 13 +++---------- drivers/iio/dac/max5522.c | 11 +++--------Quoted 2 lines
8 files changed, 13 insertions(+), 51 deletions(-)---
Quoted 5 lines
LGTM, just some minor comments/asks that don't really stop me from:
Reviewed-by Nuno Sa <[email protected]>
Applied.
Thanks for tidying these up.
Jonathan