All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Salah Triki <salah.triki@gmail.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Esteban Blanc" <eblanc@baylibre.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux@analog.com, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] iio: adc: ad4030: fix invalid oversampling_ratio validation
Date: Tue, 1 Sep 2026 14:08:44 +0300	[thread overview]
Message-ID: <apayPCk4ln_Hh_Bb@ashevche-desk.local> (raw)
In-Reply-To: <20260901104243.48732-1-salah.triki@gmail.com>

On Tue, Sep 01, 2026 at 11:42:43AM +0100, Salah Triki wrote:
> In ad4030_set_avg_frame_len(), the logarithm is calculated before input
> validation. Passing zero or negative values leads to an undefined result
> from ilog2().
> 
> Validate that the input is strictly positive prior to computing its
> logarithm to ensure only valid values are processed.

...

> -	if (avg_val < 0 || avg_val > ad4030_average_modes[last_avg_idx])
> +	if (avg_val <= 0 || avg_val > ad4030_average_modes[last_avg_idx])
>  		return -EINVAL;

I still find '<= 0' confusing. Why not check against 1?
And I would rather see an additional comment.

What about

	/* Reject unsupported modes */
	if (avg_val > ad4030_average_modes[last_avg_idx])
		return -EINVAL;

	/* Avoid invalid values for logarithm since it's undefined */
	if (avg_val < 1)
// In this case, when condition is split, if (avg_val <= 0) is also possible
		return -EINVAL;

> +	avg_log2 = ilog2(avg_val);

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-09-01 11:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 10:42 [PATCH v4] iio: adc: ad4030: fix invalid oversampling_ratio validation Salah Triki
2026-09-01 11:08 ` Andy Shevchenko [this message]
2026-09-01 14:38   ` Nuno Sá

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=apayPCk4ln_Hh_Bb@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=eblanc@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@analog.com \
    --cc=nuno.sa@analog.com \
    --cc=salah.triki@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.