Skip to content

Commit 20f291b

Browse files
error27jic23
authored andcommitted
iio: adc: imx93: fix a signedness bug in imx93_adc_read_raw()
The problem is these lines: ret = vref_uv = regulator_get_voltage(adc->vref); if (ret < 0) The "ret" variable is type long and "vref_uv" is u32 so that means the condition can never be true on a 64bit system. A negative error code from regulator_get_voltage() would be cast to a high positive u32 value and then remain a high positive value when cast to a long. The "ret" variable only ever stores ints so it should be declared as an int. We can delete the "vref_uv" variable and use "ret" directly. Fixes: 7d02296 ("iio: adc: add imx93 adc support") Signed-off-by: Dan Carpenter <error27@gmail.com> Reviewed-by: Haibo Chen <haibo.chen@nxp.com> Link: https://lore.kernel.org/r/Y+utEvjfjQRQo2QB@kili Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent ac9a786 commit 20f291b

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

drivers/iio/adc/imx93_adc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ static int imx93_adc_read_raw(struct iio_dev *indio_dev,
236236
{
237237
struct imx93_adc *adc = iio_priv(indio_dev);
238238
struct device *dev = adc->dev;
239-
long ret;
240-
u32 vref_uv;
239+
int ret;
241240

242241
switch (mask) {
243242
case IIO_CHAN_INFO_RAW:
@@ -253,10 +252,10 @@ static int imx93_adc_read_raw(struct iio_dev *indio_dev,
253252
return IIO_VAL_INT;
254253

255254
case IIO_CHAN_INFO_SCALE:
256-
ret = vref_uv = regulator_get_voltage(adc->vref);
255+
ret = regulator_get_voltage(adc->vref);
257256
if (ret < 0)
258257
return ret;
259-
*val = vref_uv / 1000;
258+
*val = ret / 1000;
260259
*val2 = 12;
261260
return IIO_VAL_FRACTIONAL_LOG2;
262261

0 commit comments

Comments
 (0)