summaryrefslogtreecommitdiff
path: root/drivers/iio/adc/ad7944.c
diff options
context:
space:
mode:
authorDavid Lechner <dlechner@baylibre.com>2024-03-25 14:40:36 -0500
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2024-03-28 13:22:21 +0000
commit27eea4778db8268cd6dc80a5b853c599bd3099f1 (patch)
treec5e62cbdd02884f32560e5c5ceff69a38913454c /drivers/iio/adc/ad7944.c
parent3d797af1d69a23571ec89dc4d95eb0e0e971d3d8 (diff)
iio: adc: ad7944: simplify adi,spi-mode property parsing
This simplifies the adi,spi-mode property parsing by using device_property_match_property_string() instead of two separate functions. Also, the error return value is now more informative in cases where there was a problem parsing the property. Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://lore.kernel.org/r/20240325-ad7944-cleanups-v3-1-3a19120cdd06@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/adc/ad7944.c')
-rw-r--r--drivers/iio/adc/ad7944.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
index d5ec6b5a41c7..9aa3e98cd75c 100644
--- a/drivers/iio/adc/ad7944.c
+++ b/drivers/iio/adc/ad7944.c
@@ -366,7 +366,6 @@ static int ad7944_probe(struct spi_device *spi)
struct ad7944_adc *adc;
bool have_refin = false;
struct regulator *ref;
- const char *str_val;
int ret;
indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
@@ -382,17 +381,17 @@ static int ad7944_probe(struct spi_device *spi)
adc->timing_spec = chip_info->timing_spec;
- if (device_property_read_string(dev, "adi,spi-mode", &str_val) == 0) {
- ret = sysfs_match_string(ad7944_spi_modes, str_val);
- if (ret < 0)
- return dev_err_probe(dev, -EINVAL,
- "unsupported adi,spi-mode\n");
-
- adc->spi_mode = ret;
- } else {
- /* absence of adi,spi-mode property means default mode */
+ ret = device_property_match_property_string(dev, "adi,spi-mode",
+ ad7944_spi_modes,
+ ARRAY_SIZE(ad7944_spi_modes));
+ /* absence of adi,spi-mode property means default mode */
+ if (ret == -EINVAL)
adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
- }
+ else if (ret < 0)
+ return dev_err_probe(dev, ret,
+ "getting adi,spi-mode property failed\n");
+ else
+ adc->spi_mode = ret;
if (adc->spi_mode == AD7944_SPI_MODE_CHAIN)
return dev_err_probe(dev, -EINVAL,