From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 EF17F489882 for ; Sun, 2 Aug 2026 07:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785654775; cv=none; b=B6BcX+Gux+Jo2VQkOL6dBVYuzSKlRH2hWk9DH+7kp9vH3hm66H5z/DzkI/12cmlHxbReM7WS/Kac9cSxByzOluWD/o6X8uVgZvFabAxPwv6FQF1yu/uUGWEtY5ivn3K1VdlDGuW7BHwdeZuz8clvY8n9zq9KNyfoysGt96nXWek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785654775; c=relaxed/simple; bh=T5lHOsgdNKHdvpMQPLi2YhCHxETt7OgdaHUH/4aE+aA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=uPKahlYoSLTwLN9l3of9PKxiB4hpHzqGG+uBEwtYTDsdHOEO+JrCgBhu4zf+x3t8CTUGwU50Ov6UcNKj5fwaDpn7FP+JTrr8D8QpjoEDiXxTpJM5LJvr7ljGldha6EpOBp4ISTKYb6H33YMFgoBBIcOVzU9wm7XZOC0P2CT1kBs= 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=eHKOg9nl; arc=none smtp.client-ip=209.85.215.170 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="eHKOg9nl" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-ca88130e09aso1829269a12.3 for ; Sun, 02 Aug 2026 00:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785654773; x=1786259573; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=ZPIdTnQh1QKWeUAz+tiT4s3AcWBx4iUakbRHDtSIp1I=; b=eHKOg9nlHsH/RKeQf1QlQ25AGMODQxFMlGuvjMST2dmmXm71ddPASakSbvPiNHTfci lzdGUWFeIn/5BF1OuYHksO/Ik3Z4jogIG/NxNmWqxFahPRz/bB1U7Ch7oYIoTO+VqFgl DelFYfcXCPsJmMXcHC7WUA0l7RxEs8bDgjCWyes/yrC4P7xlENrzFqaF47nYIZFCNjsw YgY2SgorkwtycUYCwlWN7Gkt0vPYy98iot/WS5U8aKXJ4TE4LgRFV90qPpfHy6cHLd7i A6QyZ+r7V1zhiursIKRYEGqKeQIWBjiTCh/xNCrKHsO2LnJvHUNwgVjxIi8f1YwymEA2 40/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785654773; x=1786259573; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ZPIdTnQh1QKWeUAz+tiT4s3AcWBx4iUakbRHDtSIp1I=; b=Y+y8laMksFk15ASS1CXFeCin3X4tiMBvRlYXESLHZzt85kWc84QaZf2q/iO6Rz1pqr M++GIYKyyS6WdO11QltHo+Vz7aZdxHDEZ85BFIiN6NsmFHn5qdP8PzmKmHGg0h0LWKmq PQPe08WrkFX6MAlyEuqe/Cq/mCXifn5c1ti1aRpguHe4NEt5zpu+F+OfXHctyzrUjJjs aotWWeTOfEeu4ObxGJwlKhWIIGsAyyAukI8es1L0i9zjzfP/hp5lO3/pd0cm9NTQ8xN0 f5p6sWLxBGpgkTGzx1CrKfXNKfiCXZ/P6uGftijwq81aOuYTKs6/czDcNOHTbGpo1n23 6sLw== X-Forwarded-Encrypted: i=1; AHgh+RqAy76dVDf3ac0dTIVqn/YTtButL6bUSdfLrRIuEy88XdXS0taM44zBCRhZRpRf1LJJbIGe9+Mu17ZtCbs=@vger.kernel.org X-Gm-Message-State: AOJu0Yzm5rN9wolRm9ZfsG4co2b6nJSF4XujSErZp/JSnzrFwyJGikHh RpRwweTP926crdLpPo27iKCfBw/w9ddsfmd02VB02SwjgxPdYPK2QqLV X-Gm-Gg: AR+sD10iSn3+XRyOEgwY0cpHrcrcDEW92eeA06p0IgaIqnsQ18oEtmmLmrJMDftUedw su6+toU2uv2NGSN5Utyy81ybRfQBqNWfTY4TGKdAhd6kcUvZbmu0SNxjedbBpIQNlhEdaHhCbgG GunSGXlb+nWx3ns3e8k9k/TBBwSsTtBzUTJOXZl70BkKa2zt4APrR4hlhxTjITA+nDtF5XZq9xT LpNF48g3ewC2R9/pKwe1V5l+yGstEKcnmfNQvImWhNwtxEX0IFyntpqF1fi4kFMyFFoue8i2D0q OYKX46oCGW9puFfOKg4t8ls5X8h2vQ/1oaqZkf9BJTSVqvh4s6LfM1jQevJ3qmsY24N27b/SQEM zTveZHPUNW7/EOID3paqPu7GEB95Wwr+WVZZoUfTtmkE7oUXDC1ILABwkaUvJNUY0hurjkvNfFw x1KVzIYX7ab2eg3UTIuZjGLW9Oatvu08tW56qPolaTm2kX36HZbr2rfhBcQHhBdntY/vl0dnqRK hjWtw== X-Received: by 2002:a05:6a20:4499:b0:3c3:8de3:8eee with SMTP id adf61e73a8af0-3c92a88ee11mr5685030637.61.1785654773335; Sun, 02 Aug 2026 00:12:53 -0700 (PDT) Received: from SGN-LDSENG.tasernet.com ([2405:4800:5cc3:11a:1ac0:4dff:fe8b:4a69]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab050d8csm34288859c88.0.2026.08.02.00.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2026 00:12:52 -0700 (PDT) From: Cong Nguyen To: Matteo Martelli , Jonathan Cameron Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio: adc: pac1921: fix wrong channel used in trigger handler read Date: Sun, 2 Aug 2026 14:12:46 +0700 Message-Id: <20260802071246.62046-1-congnt264@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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