Skip to content

Commit 74369d0

Browse files
Colin Ian Kingdlezcano
authored andcommitted
thermal: qcom: Fix comparison with uninitialized variable channels_available
Currently the check of chip->channels[i].channel is against an the uninitialized variable channels_available. I believe the variable channels_available needs to be fetched first by the call to adc_tm5_read before the channels check. Fix the issue swapping the order of the channels check loop with the call to adc_tm5_read. Addresses-Coverity: ("Uninitialized scalar variable") Fixes: ca66dca ("thermal: qcom: add support for adc-tm5 PMIC thermal monitor") Signed-off-by: Colin Ian King <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ca66dca commit 74369d0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/thermal/qcom/qcom-spmi-adc-tm5.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,20 +375,20 @@ static int adc_tm5_init(struct adc_tm5_chip *chip)
375375
int ret;
376376
unsigned int i;
377377

378-
for (i = 0; i < chip->nchannels; i++) {
379-
if (chip->channels[i].channel >= channels_available) {
380-
dev_err(chip->dev, "Invalid channel %d\n", chip->channels[i].channel);
381-
return -EINVAL;
382-
}
383-
}
384-
385378
ret = adc_tm5_read(chip, ADC_TM5_NUM_BTM,
386379
&channels_available, sizeof(channels_available));
387380
if (ret) {
388381
dev_err(chip->dev, "read failed for BTM channels\n");
389382
return ret;
390383
}
391384

385+
for (i = 0; i < chip->nchannels; i++) {
386+
if (chip->channels[i].channel >= channels_available) {
387+
dev_err(chip->dev, "Invalid channel %d\n", chip->channels[i].channel);
388+
return -EINVAL;
389+
}
390+
}
391+
392392
buf[0] = chip->decimation;
393393
buf[1] = chip->avg_samples | ADC_TM5_FAST_AVG_EN;
394394
buf[2] = ADC_TM5_TIMER1;

0 commit comments

Comments
 (0)