Skip to content

Commit 6d88a62

Browse files
sudarsan-22kartben
authored andcommitted
drivers: adc: fix underflow in lmp90xxx_adc_start_read channel check
Prevent integer underflow when sequence->channels is 0. Add an explicit check before calling find_msb_set(). Coverity CID: 487765 Signed-off-by: sudarsan N <sudarsansamy2002@gmail.com>
1 parent 660d2b3 commit 6d88a62

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/adc/adc_lmp90xxx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,9 @@ static int lmp90xxx_adc_start_read(const struct device *dev,
503503
return -ENOTSUP;
504504
}
505505

506-
if (!lmp90xxx_has_channel(dev, find_msb_set(sequence->channels) - 1)) {
507-
LOG_ERR("unsupported channels in mask: 0x%08x",
508-
sequence->channels);
506+
if (sequence->channels == 0 ||
507+
!lmp90xxx_has_channel(dev, find_msb_set(sequence->channels) - 1)) {
508+
LOG_ERR("unsupported channels in mask: 0x%08x", sequence->channels);
509509
return -ENOTSUP;
510510
}
511511

0 commit comments

Comments
 (0)