Skip to content

Commit ccf9af8

Browse files
donutAneesjic23
authored andcommitted
iioc: dac: ltc2664: Fix span variable usage in ltc2664_channel_config()
In the current implementation of the ltc2664_channel_config() function, a variable named span is declared and initialized to 0, intended to capture the return value of the ltc2664_set_span() function. However, the output of ltc2664_set_span() is directly assigned to chan->span, leaving span unchanged. As a result, when the function later checks if (span < 0), this condition will never trigger an error since span remains 0, this flaw leads to ineffective error handling. Resolve this issue by using the ret variable to get the return value and later assign it if successful and remove unused span variable. Fixes: 4cc2fc4 ("iio: dac: ltc2664: Add driver for LTC2664 and LTC2672") Signed-off-by: Mohammed Anees <[email protected]> Link: https://patch.msgid.link/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 27b6aa6 commit ccf9af8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/iio/dac/ltc2664.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static int ltc2664_channel_config(struct ltc2664_state *st)
516516
const struct ltc2664_chip_info *chip_info = st->chip_info;
517517
struct device *dev = &st->spi->dev;
518518
u32 reg, tmp[2], mspan;
519-
int ret, span = 0;
519+
int ret;
520520

521521
mspan = LTC2664_MSPAN_SOFTSPAN;
522522
ret = device_property_read_u32(dev, "adi,manual-span-operation-config",
@@ -579,20 +579,21 @@ static int ltc2664_channel_config(struct ltc2664_state *st)
579579
ret = fwnode_property_read_u32_array(child, "output-range-microvolt",
580580
tmp, ARRAY_SIZE(tmp));
581581
if (!ret && mspan == LTC2664_MSPAN_SOFTSPAN) {
582-
chan->span = ltc2664_set_span(st, tmp[0] / 1000,
583-
tmp[1] / 1000, reg);
584-
if (span < 0)
585-
return dev_err_probe(dev, span,
582+
ret = ltc2664_set_span(st, tmp[0] / 1000, tmp[1] / 1000, reg);
583+
if (ret < 0)
584+
return dev_err_probe(dev, ret,
586585
"Failed to set span\n");
586+
chan->span = ret;
587587
}
588588

589589
ret = fwnode_property_read_u32_array(child, "output-range-microamp",
590590
tmp, ARRAY_SIZE(tmp));
591591
if (!ret) {
592-
chan->span = ltc2664_set_span(st, 0, tmp[1] / 1000, reg);
593-
if (span < 0)
594-
return dev_err_probe(dev, span,
592+
ret = ltc2664_set_span(st, 0, tmp[1] / 1000, reg);
593+
if (ret < 0)
594+
return dev_err_probe(dev, ret,
595595
"Failed to set span\n");
596+
chan->span = ret;
596597
}
597598
}
598599

0 commit comments

Comments
 (0)