From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 B3BA32C027F for ; Tue, 4 Aug 2026 06:49:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785826170; cv=none; b=Q4wR0IHwd0LV4MNt0Uf4hjGaQ0gCuwaF1s63v8WaDVlHBVZAOfnASy937nuzv+BlgiROx9F1UCZpXelOiqjwbx5l0JAsJ02Mv39qgC+uII8Y8BmT4gU0RhR12/ThumsfTmdM1Xn9FFImLmJAoY7c6uQS8fFfUVxRs6xJ4xfp3z0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785826170; c=relaxed/simple; bh=DMpO3ajwC7Btu5PMHyb9DYRbQhvyvou7TYl47BKDq7w=; h=Date:Message-ID:In-Reply-To:From:References:Subject:To:Cc: MIME-Version:Content-Type; b=Y8Br9S7hKWORLFuymEfNo86YSFhBuF1T594Cs+v8l9bU1xD/yHfBb5hABoutYbtuP70Z+l/+9pktBRP25Nq6F3/mRXAKnTaCH6ekIHGaTLA1TnNE/oV5MlZi72viwxCO0Ow46J6utrerk1K7FCzcRbd93pA1NEb+3tKC8E2npjk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=oFPiv4LE; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oFPiv4LE" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-495757ccbc1so27391485e9.2 for ; Mon, 03 Aug 2026 23:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785826167; x=1786430967; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:cc:to:subject :references:from:in-reply-to:message-id:date:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ATMBDpTJ93xuadTJt1TrQQurBYrCmx1OgG4lu8gYdpI=; b=oFPiv4LEatyzD8ZSFeAPEO+6Nl2/hfKhfdgRIeYQ2lxm05lIvMt4zrs7BgJqA8M0/A JE9zoC+vTjF2Ruof3omONvuaJbUx0BwsXC+iFwPutuY8EdkybTd3X4gpaITtnYYse9AI dgwdXgpvkvtWgibLYcAl0oNPbkWRKLolWg2BYPjK/L4ls/d/L0mlVgOU3XQb3Ja4wsUh MOs3yMcXYJI1FxYPDcNkCu/g/y+IddktkBIQyBdBD4NTIq1st+jjCcJzIY3d36GsSyO1 Q5OWOPGTfXVsjB42zcXWPlcajb8o4umSjSINvY2aFjKhbIcrF++bi1k1ehwvgeBWshm+ IAWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785826167; x=1786430967; h=content-transfer-encoding:content-type:mime-version:cc:to:subject :references:from:in-reply-to:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ATMBDpTJ93xuadTJt1TrQQurBYrCmx1OgG4lu8gYdpI=; b=n8aVNulv5LSR3G88DVbM35b6zwmgNaIo88asTS+ky26Czz9+1fzWu4spprHjeLI87K hFDxZMOjJV/gyR0C5jdRwJvCYOXnxFd353/24i1b2sIzioGDW+iLC8DByx2BEsU8RuAT KAnfqV81KA8n8pbX08HKU/6Kld18UBRRXi866VsrJNPUf7S42A5eFViVEoj6r3Px3ulm stzmpgGGE2bYQjBegU6Uka8twWOFZhtAgVQSCNVzMAXhY019lHugXmo1yUZuZs3C4obW RX+CJzr1I4hZSppGCgLnNn9P7HuCHEHiXilCzoK5UYBMr1H4eElXaTLFCK/DL/8uMtu+ reBw== X-Forwarded-Encrypted: i=1; AHgh+RqVhW7CyAcz88IHkcc3BGJXAVqKnAPqx2Fa6zlm2S5wa0KxRLmN9r9qaV+2D01MvXlykxO1HVGKvFryNP0=@vger.kernel.org X-Gm-Message-State: AOJu0Ywa7AqweKyWNMp5NOj0ZEMYoUdCftFXLMR/nG+YABErz6J1340I 1hzou3zhOLjv+8taFb7ag4F6up4Y+W61F2tVO51bkiGra90GrSg68FBR X-Gm-Gg: AR+sD10gQxIS2u3qE7bc410DXDzNW5XuEUCYIic87IAmwD5NdApJh2dRUrQ0DoD5J6F fL/z/RQfdvn4s0udPrTpEL5AM5s4WRG8oReQMPcxX/QhRcTGYOyuUuCmW+OVwZEEEEAT9xNAV+k OQW9EMesShrnAJBIc+ztmkd0XdG4UoghlNKFEy7+O83PIL4MwSneOtbnt3+JFTvzwVhCvlG2Tqa LfN3fJjKrliHNz3+L8jFXMs8a2h5ljoktmclBrAWGIVYnU/C/ZDWj41GnH9+tnnSBqoZEkQkLR3 ZabWuMqX7m+MrUya/c7Iu6uReTDrqBHZebip/OxULG525pYGYRuHgMVFJJibJgyLtcCj5h74Rds xNSqo53G2aw1ZUWOqm+F9R/ClXGw+eJUoP+M/FTGm/a11rWOan2RHIun5tLqiUQMeybPH6r2Edy 8NwQocHYtsEq+xYVGW5yyj2C+0hW7Ky8lkI3q+lC5iT+xJSEqomBTGozd3xubmGh4twWVmlu/bf fC5lCPUUrRQ0O3n+QImlnUERFqfFwhW2CKYlK+7oJeiUWBwa016FS488RqfrKy8Cw5fgRKz X-Received: by 2002:a05:600c:33a5:b0:496:c1f3:e8f8 with SMTP id 5b1f17b1804b1-4980c66d95bmr204358605e9.7.1785826166768; Mon, 03 Aug 2026 23:49:26 -0700 (PDT) Received: from localhost (host-95-246-56-150.retail.telecomitalia.it. [95.246.56.150]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49949fdf392sm99790885e9.11.2026.08.03.23.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 23:49:26 -0700 (PDT) Date: Tue, 04 Aug 2026 08:49:25 +0200 Message-ID: <5ea928fb5e9370824d62a0c5d5913458@gmail.com> In-Reply-To: <20260802071246.62046-1-congnt264@gmail.com> From: Matteo Martelli References: <20260802071246.62046-1-congnt264@gmail.com> Subject: Re: [PATCH] iio: adc: pac1921: fix wrong channel used in trigger handler read To: Cong Nguyen , Jonathan Cameron Cc: David Lechner , Nuno =?iso-8859-1?b?U+E=?= , Andy Shevchenko , Matteo Martelli , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On Sun, 2 Aug 2026 14:12:46 +0700, Cong Nguyen wrote: > pac1921_trigger_handler() walks the enabled channels with > iio_for_each_active_channel(), which yields the scan index (bit) of each > active channel, while ch is a separate counter used to pack the samples > contiguously into the scan buffer. > > The register to read was looked up with the packing counter instead of > the scan index: > > ret = pac1921_read_res(priv, idev->channels[ch].address, &val); > > pac1921_channels[] is ordered by scan index, so channels[bit] is the > channel that is actually enabled, whereas channels[ch] is merely the > ch-th array entry. These coincide only when the enabled channels form a > contiguous prefix (e.g. all channels enabled). With a sparse scan mask - > for example when only the power channel (scan index 3) is enabled - the > handler reads the wrong register (VBUS instead of VPOWER) and pushes it > to userspace as the enabled channel's data. > > Index the channel array by the scan index (bit) to read the correct > register, keeping ch only for contiguous packing into the scan buffer. > > Fixes: 371f778b83cd ("iio: adc: add support for pac1921") > Cc: stable@vger.kernel.org > Assisted-by: Claude:claude-opus-4 > Signed-off-by: Cong Nguyen > --- > drivers/iio/adc/pac1921.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/pac1921.c b/drivers/iio/adc/pac1921.c > index bce7185953ec..0037509503ed 100644 > --- a/drivers/iio/adc/pac1921.c > +++ b/drivers/iio/adc/pac1921.c > @@ -1037,7 +1037,7 @@ static irqreturn_t pac1921_trigger_handler(int irq, void *p) > iio_for_each_active_channel(idev, bit) { > u16 val; > > - ret = pac1921_read_res(priv, idev->channels[ch].address, &val); > + ret = pac1921_read_res(priv, idev->channels[bit].address, &val); > if (ret) > goto done; > > -- > 2.25.1 > This looks correct to me. I guess I didn't test it properly with a subset of enabled channels when I wrote this. Thanks for the fix! Acked-by: Matteo Martelli