[lvc-project] [PATCH] iio: adc: qcom-pm8xxx-xoadc: Remove useless condition in pm8xxx_xoadc_parse_channel()

Andi Shyti andi.shyti at kernel.org
Wed Mar 15 00:28:51 MSK 2023


Hi,

> > The left side of the loop condition never becomes false.
> > hwchan cannot be NULL, because it points to elements of the
> > hw_channels array that takes one of 4 predefined values:
> > pm8018_xoadc_channels, pm8038_xoadc_channels,
> > pm8058_xoadc_channels, pm8921_xoadc_channels.
> >
> > Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> I am not impressed with that tool. See below:
> 
> > Fixes: 63c3ecd946d4 ("iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC")
> > Signed-off-by: Kasumov Ruslan <s02210418 at gse.cs.msu.ru>
> 
> (...)
> >         hwchan = &hw_channels[0];
> > -       while (hwchan && hwchan->datasheet_name) {
> > +       while (hwchan->datasheet_name) {
> >                 if (hwchan->pre_scale_mux == pre_scale_mux &&
> >                     hwchan->amux_channel == amux_channel)
> >                         break;
> 
> NAK have you tested this on a real system?
> 
> Here is the complete loop:
> 
>         hwchan = &hw_channels[0];
>         while (hwchan && hwchan->datasheet_name) {
>                 if (hwchan->pre_scale_mux == pre_scale_mux &&
>                     hwchan->amux_channel == amux_channel)
>                         break;
>                 hwchan++;

ops, yes, sorry, I overlooked at this... This becomes NULL at
some point as there is a sentinel in the _variant structures.

Thanks,
Andi

>                 chid++;
>         }
> 
> Notice how hwchan is used as iterator in hwchan++.
> 
> What you are doing will cause a zero-pointer dereference.
> 
> Whoever is developing "SVACE" needs to fix the tool to understand
> this kind of usage.
> 
> Yours,
> Linus Walleij



More information about the lvc-project mailing list