Re: [PATCH v3] iio: adc: ad4030: fix invalid oversampling_ratio validation

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
On Mon, Aug 24, 2026 at 06:10:26AM +0100, Salah Triki wrote:
> ad4030_set_avg_frame_len() computes avg_log2 = ilog2(avg_val) before
> validating avg_val. The existing check (avg_val < 0) allows avg_val == 0

Try to write the sentences straight to the point using plain English,
Avoid using C language as substitute of plain English.

> to pass through, resulting in ilog2(0) being called with undefined/garbage
> behavior.
> 
> Reject non-positive values (avg_val <= 0) before computing log2.
> 
> This issue was identified with assistance from Claude AI and manually
> verified against the code.

> Changes since v1:
>    - Added note stating the issue was identified with assistance from
>    Claude AI and verified manually.

Assisted-by?

...

>  static int ad4030_set_avg_frame_len(struct iio_dev *dev, int avg_val)
>  {
>  	struct ad4030_state *st = iio_priv(dev);
> -	unsigned int avg_log2 = ilog2(avg_val);
> +	unsigned int avg_log2;

Have you read my comments to the previous version?

>  	unsigned int last_avg_idx = ARRAY_SIZE(ad4030_average_modes) - 1;
>  	int freq_hz;
>  	int ret;
>  
> -	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;

Ditto.


-- 
With Best Regards,
Andy Shevchenko
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.