From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E34A346A07 for ; Sun, 23 Aug 2026 18:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787509780; cv=none; b=TMIuDMzGduZw6fUtx94+2lHK40YxjWN9fBSYYwYyeAlV324vvS2eoWTdSl5bkq7BSpMDMGix34Oua4ya7s6PEZmyhqhknYfL0xJblo89Bj6jvw4aXNKvNbJ7aMkJ6DrBrDkSO15xd+ScjREdSHerW7MSm4SMOt534JGfKukhr6A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787509780; c=relaxed/simple; bh=R8Hc6noLelEsApZK5qb9i50lk78dKe0CiyLEReg9/Dw=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=EbvnqXjCgVxVIE9i15UM5tvM9hzi2mAMe1LubR9/rAROel+06iFRrp8ceH2USPt/S/90jUu+Im31B0oJYOBBJjIoXWF+KVgTZzpNEKXQcBKuNmtrsazXa/mB+wIqcDUBttECdksgZbtqBm+BP5V24RulIJBb3K1/9bwIQ0img68= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b=f/ffq9No; arc=none smtp.client-ip=209.85.210.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b="f/ffq9No" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7eb29ed2bbdso1890419a34.2 for ; Sun, 23 Aug 2026 11:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1787509775; x=1788114575; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=PwVbbct/Lw3Ar4yPDA0xTDROCNpyH8W4YF+42txm7ro=; b=f/ffq9NoWAvVBf4MgPsOPuMH42NJkKKGD36sXvTHsJ6iyIFFI7CmCaLEGzJORLgQcc akYMmIOv5BXBdSSn87uQepSjZd3efj2460yRKaPJacn4QV2L5VjGo4ijF8dq5X11E1ub 52H/JIJiAe2i+J29CauXZfpL9X1Hh5TI3DGFmT83QvHR7QGXQqLoTs3Kb+7cnNiSAfi3 7l43vNiLm691oeJLjIAuIKCu5N59IIqlJ102NrpzEc/r/URrxF2g/Gjh2ccKBPjUzuNs s84U8gW+nkxOeURgAi7Q1+vcZvkj3lHMyHQX2iUJ+YvFK9xEeATM3lUCNeI63Ggd9gY9 8PSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787509775; x=1788114575; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PwVbbct/Lw3Ar4yPDA0xTDROCNpyH8W4YF+42txm7ro=; b=Yz3iWUS0j4QivWVs00WBXSP0QNFV3PJZYsLDKTAmClaykIysoEnEo+I22Wu6sJZXLs ApTqTrUJOswtPQmFhVLUU7q5/r0pMCKdN50643Ked3yFWhtJS4i9mjOWhBOLJQUSATY9 UDvjrG96FODFDJdp82BBSFe26xHnZSmrg7I3UnG49UYFb7n6kZey0xQWayacKge4YcnG arNodcTlGoKJZAacMJ6CueVYDrSmlxEgc5/yq+R2+IxS4gDE2BJLfP5ChOHbmnTv3NFN rZAzHQGgGr/TYo0zekq92gGQNvcnI+C6Ew5TFJfpnwdlTDuLWvsTxeqnkJRhXl36H9eP cCDQ== X-Forwarded-Encrypted: i=1; AHgh+Rrsc7Dm4LDx3+1qqAMFdhPE/TW5Mf/NZLedujD8n01f+z+inwo11HAN4aagGY1six2kWFdkE/LMlrJAw80=@vger.kernel.org X-Gm-Message-State: AFuF++l+lTXzHBRKfe2r1gN83gb3wo3ml1juv5iGGye/HelPRzpCWVZD RvBoW9NIJ2CoQAeN1qbjtDCF9gV8CuursfFdOiuePlhjO5cHG5zvgzN/4teq6+FehKKkPM/+cJ6 84SuzHok= X-Gm-Gg: AR+sD11BqbcgAzJg1AzLRjxHnucxDj/8ZDKB+h1Qcd5FW8a9fj0GHO+sGzKDt6vFTUT tb16kI9GEILezG0IARiaDwrw0+fEDqFLH5ILnZ7JtsPUUvpwCW08tBtiAJlNSFINXTsTANjKijV BxIHGipG944ljVJ4WPZWhgHYkcz2PYbfBMvtLYFtF+zi+CHKSL17IhV64OWQz7GP32cxbahHnAF dhl95fFlxTdj83DIc16+3kT0bofnsa9ExO80pUuzwNPAngfXXJXlg5h7pjaofL69ZwVp6SsB5Aa rKQYiB27bROokHOJGyTatLFjIbKemHeBXwLF5WcMP+CpoIAWAPsVxz85HIH7s8PIMorAo2/yVzv EMOGSnEAnL++c6G06rsehNVFqckhnIx9XtBmfCr3gOzRVYD6jfbLCoV4Bp9sBQIWjhQjWARZ3sh H2mYMzqHrGxZ90UBc+SMrXdRWhBj0SbRHEwtvxkcJW2jU8pDMI/EFsWhQcIznQ1ZEIwSlGeSuWs AM7Cnxvm8vBcToJYj6Zv1SKVb7Nd008+ubv67U= X-Received: by 2002:a05:6820:151a:b0:6a1:47ad:d18e with SMTP id 006d021491bc7-6b159199686mr21356582eaf.2.1787509775218; Sun, 23 Aug 2026 11:29:35 -0700 (PDT) Received: from ?IPV6:2600:8803:e7e4:500:e427:2c2b:7b9e:e073? ([2600:8803:e7e4:500:e427:2c2b:7b9e:e073]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4638352cba7sm3481549fac.13.2026.08.23.11.29.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 Aug 2026 11:29:33 -0700 (PDT) Message-ID: <0b03fc0f-8032-47b2-ac97-f2d93c1c5bdf@baylibre.com> Date: Sun, 23 Aug 2026 13:29:32 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] iio: adc: ad4030: fix invalid oversampling_ratio validation To: Salah Triki , Michael Hennerich , =?UTF-8?Q?Nuno_S=C3=A1?= , Jonathan Cameron , Andy Shevchenko , linux-iio@vger.kernel.org, linux@analog.com, linux-kernel@vger.kernel.org References: <20260823045205.25554-1-salah.triki@gmail.com> Content-Language: en-US From: David Lechner In-Reply-To: <20260823045205.25554-1-salah.triki@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 8/22/26 11:52 PM, Salah Triki wrote: > ad4030_set_avg_frame_len() computes avg_log2 = ilog2(avg_val) before > validating avg_val, and the subsequent range check only rejects > negative values or values above the maximum supported OSR. It does > not reject avg_val == 0, nor values that are not exact powers of 2. > > - avg_val == 0 passes the check (0 is not < 0 and not > max), so > ilog2(0) is called with an undefined/garbage result. > > - Non-power-of-2 values (e.g. avg_val == 3) also pass the check and > silently get rounded down by ilog2() to the nearest lower power of > 2, so userspace can write a value to the oversampling_ratio sysfs > attribute that does not match what actually gets programmed into > hardware, without any error being reported. > > Only powers of 2 in [1, 65536] are valid OSR values, as listed in > ad4030_average_modes[]. Validate avg_val fully before computing its > log2, using is_power_of_2() and requiring avg_val > 0. There is no rule in IIO that says we can't round values when writing attributes. Users are expected to read the attribute after writing to see what actually took effect. So this patch doesn't seem justified. > > This issue was identified with assistance from Claude AI and manually > verified against the code. > > Fixes: 949abd1ca5a4 ("iio: adc: ad4030: add averaging support") Actually, this could break existing users that depend on the current behavior. It certainly doesn't fix anything. > Signed-off-by: Salah Triki > --- > Changes since v1: > - Added note stating the issue was identified with assistance from > Claude AI and verified manually. > - Removed initialization of avg_log2 at declaration. > > drivers/iio/adc/ad4030.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) >