* [PATCH] iio: adc: ad7944: simplify adi,spi-mode property parsing
@ 2024-03-18 21:56 David Lechner
2024-03-18 22:43 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: David Lechner @ 2024-03-18 21:56 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Michael Hennerich, Nuno Sá,
linux-iio, linux-kernel, Andy Shevchenko
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 problem parsing the property.
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad7944.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
index d5ec6b5a41c7..356aea02920f 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,16 +381,18 @@ 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 {
+ ret = device_property_match_property_string(dev, "adi,spi-mode",
+ ad7944_spi_modes,
+ ARRAY_SIZE(ad7944_spi_modes));
+ if (ret < 0) {
/* absence of adi,spi-mode property means default mode */
- adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
+ if (ret == -EINVAL)
+ adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
+ else
+ 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)
---
base-commit: 1446d8ef48196409f811c25071b2cc510a49fc60
change-id: 20240318-ad7944-cleanups-9f95a7c598b6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ad7944: simplify adi,spi-mode property parsing
2024-03-18 21:56 [PATCH] iio: adc: ad7944: simplify adi,spi-mode property parsing David Lechner
@ 2024-03-18 22:43 ` Andy Shevchenko
2024-03-18 22:48 ` David Lechner
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2024-03-18 22:43 UTC (permalink / raw)
To: David Lechner
Cc: Jonathan Cameron, Michael Hennerich, Nuno Sá,
linux-iio, linux-kernel
On Mon, Mar 18, 2024 at 11:57 PM David Lechner <dlechner@baylibre.com> wrote:
>
> 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 problem parsing the property.
a problem
...
> + ret = device_property_match_property_string(dev, "adi,spi-mode",
> + ad7944_spi_modes,
> + ARRAY_SIZE(ad7944_spi_modes));
> + if (ret < 0) {
> /* absence of adi,spi-mode property means default mode */
> - adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
> + if (ret == -EINVAL)
> + adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
> + else
> + return dev_err_probe(dev, ret,
> + "getting adi,spi-mode property failed\n");
No need to have 'else'
if (ret != -EINVAL)
return dev_err_probe(dev, ret, "getting
adi,spi-mode property failed\n");
/* absence of adi,spi-mode property means default mode */
adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
> + } else {
> + adc->spi_mode = ret;
> }
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ad7944: simplify adi,spi-mode property parsing
2024-03-18 22:43 ` Andy Shevchenko
@ 2024-03-18 22:48 ` David Lechner
0 siblings, 0 replies; 3+ messages in thread
From: David Lechner @ 2024-03-18 22:48 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, Michael Hennerich, Nuno Sá,
linux-iio, linux-kernel
On 3/18/24 5:43 PM, Andy Shevchenko wrote:
> On Mon, Mar 18, 2024 at 11:57 PM David Lechner <dlechner@baylibre.com> wrote:
>>
>> 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 problem parsing the property.
>
> a problem
>
> ...
>
>> + ret = device_property_match_property_string(dev, "adi,spi-mode",
>> + ad7944_spi_modes,
>> + ARRAY_SIZE(ad7944_spi_modes));
>> + if (ret < 0) {
>> /* absence of adi,spi-mode property means default mode */
>> - adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
>> + if (ret == -EINVAL)
>> + adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
>> + else
>> + return dev_err_probe(dev, ret,
>> + "getting adi,spi-mode property failed\n");
>
> No need to have 'else'
>
> if (ret != -EINVAL)
> return dev_err_probe(dev, ret, "getting
> adi,spi-mode property failed\n");
>
> /* absence of adi,spi-mode property means default mode */
> adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
>
>> + } else {
>> + adc->spi_mode = ret;
>> }
>
I agree it is better that way. Will send a v2.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-18 22:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 21:56 [PATCH] iio: adc: ad7944: simplify adi,spi-mode property parsing David Lechner
2024-03-18 22:43 ` Andy Shevchenko
2024-03-18 22:48 ` David Lechner
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.