Skip to content

Commit 7a52550

Browse files
dlechnunojsa
authored andcommitted
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>
1 parent 1a81799 commit 7a52550

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

drivers/iio/adc/ad7944.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@ static int ad7944_probe(struct spi_device *spi)
574574
struct ad7944_adc *adc;
575575
bool have_refin = false;
576576
struct regulator *ref;
577-
const char *str_val;
578577
int ret;
579578

580579
indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
@@ -590,17 +589,17 @@ static int ad7944_probe(struct spi_device *spi)
590589

591590
adc->timing_spec = chip_info->timing_spec;
592591

593-
if (device_property_read_string(dev, "adi,spi-mode", &str_val) == 0) {
594-
ret = sysfs_match_string(ad7944_spi_modes, str_val);
595-
if (ret < 0)
596-
return dev_err_probe(dev, -EINVAL,
597-
"unsupported adi,spi-mode\n");
598-
599-
adc->spi_mode = ret;
600-
} else {
601-
/* absence of adi,spi-mode property means default mode */
592+
ret = device_property_match_property_string(dev, "adi,spi-mode",
593+
ad7944_spi_modes,
594+
ARRAY_SIZE(ad7944_spi_modes));
595+
/* absence of adi,spi-mode property means default mode */
596+
if (ret == -EINVAL)
602597
adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
603-
}
598+
else if (ret < 0)
599+
return dev_err_probe(dev, ret,
600+
"getting adi,spi-mode property failed\n");
601+
else
602+
adc->spi_mode = ret;
604603

605604
/*
606605
* Some chips use unusual word sizes, so check now instead of waiting

0 commit comments

Comments
 (0)