mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
	"Olivier Moysan" <olivier.moysan@foss.st.com>,
	linux-iio@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] iio: adc: stm32-adc: fix possible division by zero in processed channel
Date: Wed, 16 Sep 2026 17:20:48 +0200	[thread overview]
Message-ID: <538c8203-3880-47aa-ba4e-014a345b3cb9@foss.st.com> (raw)
In-Reply-To: <aqqqCf6mQPMoKZRj@ashevche-desk.local>

On 9/16/26 16:39, Andy Shevchenko wrote:

[ snip ]

> Let's look at the current code in this switch-case
> 

Hi Andy,

Thanks for you suggestions !

Let's keep in the picture the 'normal' raw case:

	case IIO_CHAN_INFO_RAW:
> 	case IIO_CHAN_INFO_PROCESSED:
> 		if (!iio_device_claim_direct(indio_dev))
> 			return -EBUSY;
> 		if (chan->type == IIO_VOLTAGE)
> 			ret = stm32_adc_single_conv(indio_dev, chan, val);
> 		else
> 			ret = -EINVAL;
> 
> 		if (mask == IIO_CHAN_INFO_PROCESSED)
> 			*val = STM32_ADC_VREFINT_VOLTAGE * adc->vrefint.vrefint_cal / *val;
> 
> 		iio_device_release_direct(indio_dev);
> 		return ret;
> 
> In the previous version you were trying to keep goto-less approach.
> However in the current state of affairs I don't think the goto is
> too bad (after all we need to backport this to the kernels that may
> not have IIO_DEV_ACQUIRE_DIRECT_MODE() macro).
> 
> Also checking 'ret' under another condition seems unusual.
> 
> What about
> 
> 	case IIO_CHAN_INFO_PROCESSED:
> 		if (!iio_device_claim_direct(indio_dev))
> 			return -EBUSY;
> 		if (chan->type == IIO_VOLTAGE)
> 			ret = stm32_adc_single_conv(indio_dev, chan, val);
> 		else
> 			ret = -EINVAL;
> 		iio_device_release_direct(indio_dev);
> 		if (ret)
> 			return ret;
> 
> 		if (*val == 0)
> 			return -EINVAL;

So *val == 0 is normally a valid value, for 'normal' raw channels.

> 
> 		if (mask == IIO_CHAN_INFO_PROCESSED)
> 			*val = STM32_ADC_VREFINT_VOLTAGE * adc->vrefint.vrefint_cal / *val;

With you suggestion, moving if (*val == 0) to here should be fine ?

		if (mask == IIO_CHAN_INFO_PROCESSED) {
			if (*val == 0)
				return -EINVAL;
			*val = STM32_ADC_VREFINT_VOLTAGE * adc->vrefint.vrefint_cal / *val;
		}

Best Regards,
Fabrice

> 
> 		return 0;
> 
> ? (Yes, we leave that line untouched, but we get the change cleaner.)
> 
> 


  reply	other threads:[~2026-09-16 15:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 14:10 Fabrice Gasnier
2026-09-16 14:39 ` Andy Shevchenko
2026-09-16 15:20   ` Fabrice Gasnier [this message]
2026-09-16 15:39     ` Andy Shevchenko

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=538c8203-3880-47aa-ba4e-014a345b3cb9@foss.st.com \
    --to=fabrice.gasnier@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=olivier.moysan@foss.st.com \
    --cc=sashiko-bot@kernel.org \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®