Skip to contentSkip to conversation

iio: adc: ad7476: fix clang -Wpointer-bool-conversion warning

PATCH In review Arnd Bergmann 3 participants 3 messages May 5, 2020 – May 8, 2020

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

PATCH 1/1 iio: adc: ad7476: fix clang -Wpointer-bool-conversion warning

Checking the pointer value of st->chip_info->convst_channel is pointless since this this an array inside of a struct: even if st->chip_info is NULL, the pointer is non-zero. Clang warns about this:

drivers/iio/adc/ad7476.c:312:40: warning: address of array 'st->chip_info->convst_channel' will always evaluate to 'true' [-Wpointer-bool-conversion]

        if (st->convst_gpio && st->chip_info->convst_channel)
                            ~~ ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

I could not come up with a sane way to check whether the entry is valid, so just remove the check and keep the behavior as it is today but without the warning.

Fixes 3a6af93dd66e ("iio: adc: ad7476: Add IIO_CHAN_INFO_RAW for AD7091R")
---
 drivers/iio/adc/ad7476.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7476.c +1 -1
index e9984a38fc4c..4e816d714ad2 100644
@@ -309,7 +309,7 @@ static int ad7476_probe(struct spi_device *spi)
 	indio_dev->num_channels = 2;
 	indio_dev->info = &ad7476_info;
 
-	if (st->convst_gpio && st->chip_info->convst_channel)
+	if (st->convst_gpio)
 		indio_dev->channels = st->chip_info->convst_channel;
 	/* Setup default message */
 
Signature · 1 line
2.26.0
#1 lore raw
Quoted 6 lines · Arnd Bergmann

[External]

Checking the pointer value of st->chip_info->convst_channel is pointless since this this an array inside of a struct: even if st->chip_info is NULL, the pointer is non-zero. Clang warns about this:

Quoted 8 lines

drivers/iio/adc/ad7476.c:312:40: warning: address of array 'st->chip_info-

Quoted 1 line

convst_channel' will always evaluate to 'true' [-Wpointer-bool-conversion]

        if (st->convst_gpio && st->chip_info->convst_channel)
                            ~~ ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

I could not come up with a sane way to check whether the entry is valid, so just remove the check and keep the behavior as it is today but without the warning.

There's already a patch for this, in one of Jonathan's branches.
https://patchwork.kernel.org/patch/11507829/

Thanks
Alex

Quoted 20 lines
Fixes 3a6af93dd66e ("iio: adc: ad7476: Add IIO_CHAN_INFO_RAW for AD7091R")
---
 drivers/iio/adc/ad7476.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7476.c +1 -1
index e9984a38fc4c..4e816d714ad2 100644
@@ -309,7 +309,7 @@ static int ad7476_probe(struct spi_device *spi)
 	indio_dev->num_channels = 2;
 	indio_dev->info = &ad7476_info;
 
-	if (st->convst_gpio && st->chip_info->convst_channel)
+	if (st->convst_gpio)
 		indio_dev->channels = st->chip_info->convst_channel;
 	/* Setup default message */
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann

Checking the pointer value of st->chip_info->convst_channel is pointless since this this an array inside of a struct: even if st->chip_info is NULL, the pointer is non-zero. Clang warns about this:

Quoted 7 lines

drivers/iio/adc/ad7476.c:312:40: warning: address of array 'st->chip_info->convst_channel' will always evaluate to 'true' [-Wpointer-bool-conversion]

        if (st->convst_gpio && st->chip_info->convst_channel)
                            ~~ ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

I could not come up with a sane way to check whether the entry is valid, so just remove the check and keep the behavior as it is today but without the warning.

Me too. Thanks for the patch.

Quoted 27 lines
Fixes 3a6af93dd66e ("iio: adc: ad7476: Add IIO_CHAN_INFO_RAW for AD7091R")
---
 drivers/iio/adc/ad7476.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7476.c +1 -2
index e9984a38fc4c..4e816d714ad2 100644
@@ -309,7 +309,7 @@ static int ad7476_probe(struct spi_device *spi)
        indio_dev->num_channels = 2;
        indio_dev->info = &ad7476_info;
 
-       if (st->convst_gpio && st->chip_info->convst_channel)
+       if (st->convst_gpio)
                indio_dev->channels = st->chip_info->convst_channel;
        /* Setup default message */
 
--

2.26.0

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200505142408.1113763-1-arnd%40arndb.de.

Signature · 2 lines
Thanks,
~Nick Desaulniers