Skip to contentSkip to conversation

iio: adc: ad7476: remove redundant null check on an array

PATCH In review Colin King 4 participants 4 messages Apr 24, 2020 – Apr 25, 2020

Subsystems (4)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 iio: adc: ad7476: remove redundant null check on an array

From: Colin Ian King <[email protected]>

The null check on st->chip_info->convst_channel is redundant because convst_channel is a 2 element array of struct iio_chan_spec objects and this can never be null. Fix this by removing the null check.

Addresses-Coverity: ("Array compared against 0")

---
 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.25.1
Reviewed-by on v1 1/1
#1 lore raw

T24gRnJpLCAyMDIwLTA0LTI0IGF0IDE0OjA0ICswMTAwLCBDb2xpbiBLaW5nIHdyb3RlOg0KPiBG cm9tOiBDb2xpbiBJYW4gS2luZyA8Y29saW4ua2luZ0BjYW5vbmljYWwuY29tPg0KPiANCj4gVGhl IG51bGwgY2hlY2sgb24gc3QtPmNoaXBfaW5mby0+Y29udnN0X2NoYW5uZWwgaXMgcmVkdW5kYW50 IGJlY2F1c2UNCj4gY29udnN0X2NoYW5uZWwgaXMgYSAyIGVsZW1lbnQgYXJyYXkgb2Ygc3RydWN0 IGlpb19jaGFuX3NwZWMgb2JqZWN0cw0KPiBhbmQgdGhpcyBjYW4gbmV2ZXIgYmUgbnVsbC4gRml4 IHRoaXMgYnkgcmVtb3ZpbmcgdGhlIG51bGwgY2hlY2suDQo+IA0KDQpSZXZpZXdlZC1ieTogQWxl eGFuZHJ1IEFyZGVsZWFuIDxhbGV4YW5kcnUuYXJkZWxlY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null check on st->chip_info->convst_channel is redundant because convst_channel is a 2 element array of struct iio_chan_spec objects and this can never be null. Fix this by removing the null check.

Applied to the togreg branch of iio.git and pushed out as testing. I didn't take this as a fix as it's not doing any harm in the meantime whilst this patch goes the slow route.

Thanks,

Jonathan

Quoted 20 lines
Quoted 20 lines

Addresses-Coverity: ("Array compared against 0")

---
 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 */
 
#3 lore raw
Quoted 11 lines · On Sat, 25 Apr 2020 18:01:10 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 8 lines · Alexandru
Quoted 6 lines · Colin King

From: Colin Ian King <[email protected]>

The null check on st->chip_info->convst_channel is redundant because convst_channel is a 2 element array of struct iio_chan_spec objects and this can never be null. Fix this by removing the null check.

Quoted 4 lines
Quoted 1 line

Applied to the togreg branch of iio.git and pushed out as testing. I didn't take this as a fix as it's not doing any harm in the meantime whilst this patch goes the slow route.

Just noticed this is in next only currently! Hence can definitely got he slow route as doesn't apply to mainline :)

Jonathan

Quoted 26 lines

Thanks,

Jonathan

Quoted 20 lines
Quoted 20 lines

Addresses-Coverity: ("Array compared against 0")

---
 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 */