public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Mohammed Anees <pvmohammedanees2003@gmail.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Michael Hennerich <michael.hennerich@analog.com>,
	Kim Seer Paller <kimseer.paller@analog.com>,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH v2] iioc: dac: ltc2664: Fix span variable usage in ltc2664_channel_config function
Date: Sun, 6 Oct 2024 15:25:33 +0100	[thread overview]
Message-ID: <20241006152533.329d9b59@jic23-huawei> (raw)
In-Reply-To: <20241005170722.19542-1-pvmohammedanees2003@gmail.com>

On Sat,  5 Oct 2024 22:37:22 +0530
Mohammed Anees <pvmohammedanees2003@gmail.com> wrote:

> 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. The
> current patch resolves this issue by using the ret variable for 
> getting the return value, later assigning if successful and also 
> effectively removing span variable.
> 
> Signed-off-by: Mohammed Anees <pvmohammedanees2003@gmail.com>
> Fixes: 4cc2fc445d2e4e63ed6bd5d310752d88d365f8e4
> ---
> v2:
> - Using the ret variable to store the result from ltc2664_set_span
> ---
>  drivers/iio/dac/ltc2664.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/dac/ltc2664.c b/drivers/iio/dac/ltc2664.c
> index 5be5345ac5c8..7dafcba7ece7 100644
> --- a/drivers/iio/dac/ltc2664.c
> +++ b/drivers/iio/dac/ltc2664.c
> @@ -516,7 +516,7 @@ static int ltc2664_channel_config(struct ltc2664_state *st)
>  	const struct ltc2664_chip_info *chip_info = st->chip_info;
>  	struct device *dev = &st->spi->dev;
>  	u32 reg, tmp[2], mspan;
> -	int ret, span = 0;
> +	int ret;
>  
>  	mspan = LTC2664_MSPAN_SOFTSPAN;
>  	ret = device_property_read_u32(dev, "adi,manual-span-operation-config",
> @@ -579,20 +579,24 @@ static int ltc2664_channel_config(struct ltc2664_state *st)
>  		ret = fwnode_property_read_u32_array(child, "output-range-microvolt",
>  						     tmp, ARRAY_SIZE(tmp));
>  		if (!ret && mspan == LTC2664_MSPAN_SOFTSPAN) {
> -			chan->span = ltc2664_set_span(st, tmp[0] / 1000,
> +			ret = ltc2664_set_span(st, tmp[0] / 1000,
>  						      tmp[1] / 1000, reg);
> -			if (span < 0)
> -				return dev_err_probe(dev, span,
> +			if (ret < 0)
> +				return dev_err_probe(dev, ret,
>  						     "Failed to set span\n");
> +			else
else is unnecessary here as we have the standard check and error and return
if set pattern.


> +				chan->span = ret;
>  		}
>  
>  		ret = fwnode_property_read_u32_array(child, "output-range-microamp",
>  						     tmp, ARRAY_SIZE(tmp));
>  		if (!ret) {
> -			chan->span = ltc2664_set_span(st, 0, tmp[1] / 1000, reg);
> -			if (span < 0)
> -				return dev_err_probe(dev, span,
> +			ret = ltc2664_set_span(st, 0, tmp[1] / 1000, reg);
> +			if (ret < 0)
> +				return dev_err_probe(dev, ret,
>  						     "Failed to set span\n");
> +			else
and here.
> +				chan->span = ret;
>  		}
>  	}
>  


  parent reply	other threads:[~2024-10-06 14:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-05 17:07 [PATCH v2] iioc: dac: ltc2664: Fix span variable usage in ltc2664_channel_config function Mohammed Anees
2024-10-05 19:12 ` Christophe JAILLET
2024-10-05 20:01   ` [PATCH v2] iioc: dac: ltc2664: Fix span variable usage in ltc2664_channel_config Mohammed Anees
2024-10-06 14:25 ` Jonathan Cameron [this message]
2024-10-06 14:42   ` [PATCH v2] iioc: dac: ltc2664: Fix span variable usage in ltc2664_channel_config function Jonathan Cameron
2024-10-06 14:55     ` Mohammed Anees

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241006152533.329d9b59@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=kimseer.paller@analog.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=pvmohammedanees2003@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox