diff mbox series

[next] iio: adc: ad7476: remove redundant null check on an array

Message ID 20200424130419.22940-1-colin.king@canonical.com (mailing list archive)
State New, archived
Headers show
Series [next] iio: adc: ad7476: remove redundant null check on an array | expand

Commit Message

Colin King April 24, 2020, 1:04 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

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")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/iio/adc/ad7476.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alexandru Ardelean April 24, 2020, 3:01 p.m. UTC | #1
On Fri, 2020-04-24 at 14:04 +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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.
> 

Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

> Addresses-Coverity: ("Array compared against 0")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/iio/adc/ad7476.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
> index e9984a38fc4c..4e816d714ad2 100644
> --- a/drivers/iio/adc/ad7476.c
> +++ b/drivers/iio/adc/ad7476.c
> @@ -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 */
>
Jonathan Cameron April 25, 2020, 5:01 p.m. UTC | #2
On Fri, 24 Apr 2020 15:01:26 +0000
"Ardelean, Alexandru" <alexandru.Ardelean@analog.com> wrote:

> On Fri, 2020-04-24 at 14:04 +0100, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > 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.
> >   
> 
> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
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

> 
> > Addresses-Coverity: ("Array compared against 0")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >  drivers/iio/adc/ad7476.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
> > index e9984a38fc4c..4e816d714ad2 100644
> > --- a/drivers/iio/adc/ad7476.c
> > +++ b/drivers/iio/adc/ad7476.c
> > @@ -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 */
> >
Jonathan Cameron April 25, 2020, 5:02 p.m. UTC | #3
On Sat, 25 Apr 2020 18:01:10 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Fri, 24 Apr 2020 15:01:26 +0000
> "Ardelean, Alexandru" <alexandru.Ardelean@analog.com> wrote:
> 
> > On Fri, 2020-04-24 at 14:04 +0100, Colin King wrote:  
> > > From: Colin Ian King <colin.king@canonical.com>
> > > 
> > > 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.
> > >     
> > 
> > Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>  
> 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

> 
> Thanks,
> 
> Jonathan
> 
> >   
> > > Addresses-Coverity: ("Array compared against 0")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > > ---
> > >  drivers/iio/adc/ad7476.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
> > > index e9984a38fc4c..4e816d714ad2 100644
> > > --- a/drivers/iio/adc/ad7476.c
> > > +++ b/drivers/iio/adc/ad7476.c
> > > @@ -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 */
> > >      
>
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
index e9984a38fc4c..4e816d714ad2 100644
--- a/drivers/iio/adc/ad7476.c
+++ b/drivers/iio/adc/ad7476.c
@@ -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 */