Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 4cc2fc445d2e ("iio: dac: ltc2664: Add driver for LTC2664 and LTC2672")
Signed-off-by: Mohammed Anees <pvmohammedanees2003@gmail.com>
Link: https://patch.msgid.link/20241005200435.25061-1-pvmohammedanees2003@gmail.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Mohammed Anees and committed by
Jonathan Cameron
ccf9af8b 27b6aa68

+9 -8
+9 -8
drivers/iio/dac/ltc2664.c
··· 516 516 const struct ltc2664_chip_info *chip_info = st->chip_info; 517 517 struct device *dev = &st->spi->dev; 518 518 u32 reg, tmp[2], mspan; 519 - int ret, span = 0; 519 + int ret; 520 520 521 521 mspan = LTC2664_MSPAN_SOFTSPAN; 522 522 ret = device_property_read_u32(dev, "adi,manual-span-operation-config", ··· 579 579 ret = fwnode_property_read_u32_array(child, "output-range-microvolt", 580 580 tmp, ARRAY_SIZE(tmp)); 581 581 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, 586 585 "Failed to set span\n"); 586 + chan->span = ret; 587 587 } 588 588 589 589 ret = fwnode_property_read_u32_array(child, "output-range-microamp", 590 590 tmp, ARRAY_SIZE(tmp)); 591 591 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, 595 595 "Failed to set span\n"); 596 + chan->span = ret; 596 597 } 597 598 } 598 599