public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: "Ariana Lazar" <ariana.lazar@microchip.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dan Carpenter <error27@gmail.com>
Subject: Re: [PATCH] iio: dac: Fix passing uninitialized vref1_uV for no Vref1 case
Date: Tue, 14 Apr 2026 10:32:11 -0500	[thread overview]
Message-ID: <bcd23f9f-0754-44ae-b921-e312d0185394@baylibre.com> (raw)
In-Reply-To: <20260414-mcp47feb02-fix4-v1-1-9d71badfd25e@microchip.com>

On 4/14/26 7:33 AM, Ariana Lazar wrote:
> Initialize vref1_uV variable to 0 before calling
> mcp47feb02_init_ch_scales() in mcp47feb02_probe() to avoid passing an
> uninitialized value when have_ext_vref1 is false.
> 
> Fixes: dd154646d292 ("iio: dac: mcp47feb02: Fix Vref validation [1-999] case")
> Reported-by: Dan Carpenter <error27@gmail.com>
> Closes: https://lore.kernel.org/all/adiPnla0M5EzvgD-@stanley.mountain/
> Signed-off-by: Ariana Lazar <ariana.lazar@microchip.com>
> ---
>  drivers/iio/dac/mcp47feb02.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/dac/mcp47feb02.c b/drivers/iio/dac/mcp47feb02.c
> index faccb804a5ed548088aaf83266b16ed45a92916c..efd4847913e46a4fa1b671aa9c5bd3e1430406b7 100644
> --- a/drivers/iio/dac/mcp47feb02.c
> +++ b/drivers/iio/dac/mcp47feb02.c
> @@ -1095,9 +1095,10 @@ static int mcp47feb02_probe(struct i2c_client *client)
>  {
>  	const struct mcp47feb02_features *chip_features;
>  	struct device *dev = &client->dev;
> +	int vdd_uV, vref_uV, vref1_uV;
>  	struct mcp47feb02_data *data;
>  	struct iio_dev *indio_dev;
> -	int vref1_uV, vref_uV, vdd_uV, ret;
> +	int ret;
>  
>  	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
>  	if (!indio_dev)
> @@ -1146,13 +1147,13 @@ static int mcp47feb02_probe(struct i2c_client *client)
>  		dev_dbg(dev, "Vref is unavailable.\n");
>  	}
>  
> +	vref1_uV = 0;
>  	if (chip_features->have_ext_vref1) {
>  		ret = devm_regulator_get_enable_read_voltage(dev, "vref1");

I don't think ignoring all errors here is a good idea. For example, what
if it returned -EPROBE_DEFER? Then we could end up with the wrong reference
voltage instead of trying again later.

So probably something like this would be better (also fixes uninitialized
variable):

	if (chip_features->have_ext_vref1 &&
	    device_property_present(dev, "vref1")) {
		ret = devm_regulator_get_enable_read_voltage(dev, "vref1");
		if (ret < 0)
			return ret;

		vref1_uV = ret;
		data->use_vref1 = true;
	} else {
		vref1_uV = 0;
		dev_dbg(dev, "using internal band gap as voltage reference 1.\n");
	}


>  		if (ret > 0) {
>  			vref1_uV = ret;
>  			data->use_vref1 = true;
>  		} else {
> -			vref1_uV = 0;
>  			dev_dbg(dev, "using internal band gap as voltage reference 1.\n");
>  			dev_dbg(dev, "Vref1 is unavailable.\n");
>  		}
> 
> ---
> base-commit: 51e7665ab81f02adc80a1219c260ee678e9c6eb8
> change-id: 20260414-mcp47feb02-fix4-614de9334f22
> 
> Best regards,


  parent reply	other threads:[~2026-04-14 15:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-14 12:33 [PATCH] iio: dac: Fix passing uninitialized vref1_uV for no Vref1 case Ariana Lazar
2026-04-14 12:48 ` Andy Shevchenko
2026-04-14 13:21   ` David Lechner
2026-04-14 16:18     ` Andy Shevchenko
2026-04-14 16:19       ` Andy Shevchenko
2026-04-14 14:26   ` Ariana.Lazar
2026-04-14 16:26     ` Andy Shevchenko
2026-04-20 12:19       ` Jonathan Cameron
2026-04-14 15:32 ` David Lechner [this message]
2026-04-14 16:28   ` Andy Shevchenko
2026-04-20 12:11 ` Jonathan Cameron

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=bcd23f9f-0754-44ae-b921-e312d0185394@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy@kernel.org \
    --cc=ariana.lazar@microchip.com \
    --cc=error27@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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