]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: xilinx-ams: Don't include ams_ctrl_channels in scan_mask
authorSean Anderson <sean.anderson@linux.dev>
Mon, 11 Mar 2024 16:28:00 +0000 (12:28 -0400)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 8 Jun 2024 17:26:57 +0000 (18:26 +0100)
ams_enable_channel_sequence constructs a "scan_mask" for all the PS and
PL channels. This works out fine, since scan_index for these channels is
less than 64. However, it also includes the ams_ctrl_channels, where
scan_index is greater than 64, triggering undefined behavior. Since we
don't need these channels anyway, just exclude them.

Fixes: d5c70627a794 ("iio: adc: Add Xilinx AMS driver")
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Link: https://lore.kernel.org/r/20240311162800.11074-1-sean.anderson@linux.dev
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/xilinx-ams.c

index f0b71a1220e02e5cc6ffcb4f3120b9b0090dc22f..f52abf759260f2a29bf2729f7dfd819eee0461b0 100644 (file)
@@ -414,8 +414,12 @@ static void ams_enable_channel_sequence(struct iio_dev *indio_dev)
 
        /* Run calibration of PS & PL as part of the sequence */
        scan_mask = BIT(0) | BIT(AMS_PS_SEQ_MAX);
-       for (i = 0; i < indio_dev->num_channels; i++)
-               scan_mask |= BIT_ULL(indio_dev->channels[i].scan_index);
+       for (i = 0; i < indio_dev->num_channels; i++) {
+               const struct iio_chan_spec *chan = &indio_dev->channels[i];
+
+               if (chan->scan_index < AMS_CTRL_SEQ_BASE)
+                       scan_mask |= BIT_ULL(chan->scan_index);
+       }
 
        if (ams->ps_base) {
                /* put sysmon in a soft reset to change the sequence */