From nobody Tue Nov 24 14:20:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420295; b=LPyTCdkHyHOdaitFf+CLBib4y5gVMR7TioeebrPY4ae9l19XnCjv6b8zwm/fS5hTl11A 4Rbj31PEH3Zu7YDpcnCWnGVRUQpyqinI6M7q2/1wRTfI5PkgD5dm8IVwH78/y5bGLK8Y9 a2J9SNApE10G+5Ddn5z6KwiapqrPpNrnq4is+WnhB6qhWuyUpqGmEoqEGRWx8EyFoplG7 WO2LNkMzwbNA7R2eQCNtY4/ZwvBussdPMPlIUfPseaDot519f2SyIdmYNyl41Yq5Hdmck i5ZgsMqw4gtiO3QZ2/2LMPPPRNZdhJA7/8jGMIcX5CjQ8vqZEWx8LnW55ylwNqexyew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420295; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=oazF4+IESuembcd1tmGXA1W/tSrKsfNqYpwuKjqwHus=; b=0NUQAe4j+NTdGBQzn0WqzbuWzFdMZQikUaPg695LVMMzf4055/pthPkDAycokAbT7G5A 4l+8aaK1sD4ADd5iM5WWFFRhvBBZ+yiWb1HqzuGp3bnk2fwLP1N79XlcDyiV9yHSWpLyR gKXbtVkRfNiTQS7940DabNgzm/gbUP1pKM8abvNrukb/sRIuK5hzLzFobuLZaCplPho0T 7uirpcwE8p7fBkEV1jTkyuma3BUsiN/v0pASF+cCz4ACjJw/M2c2fovDE+LC2rJE14XpS QesodGOb7YhBU6eET1RAku2/MVA7bt3MXsSPkfVn8FtGdsrDOD0NNE66H/0OnX1uIAg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="oAw/MZxR"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32E14606A32D; Mon, 23 Nov 2026 07:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oAw/MZxR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 060D11F0089E; Mon, 23 Nov 2026 07:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420294; bh=oazF4+IESuembcd1tmGXA1W/tSrKsfNqYpwuKjqwHus=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oAw/MZxRKAaHI/0Jn+L7RisNTjper98Nn7krMKpqlG0xbESKfwvMYrPelp5ZJ6O0c WXWIWui4Xy2tPCQiWiRhV+8pSN9NNu0/XGtnLTlGJAKz9ElbAS1k6ZojdtPNAsHyZ6 w9KHQI0tTtYos3m06HPxHBrVAwekGSRrzdjnAnvPQIRKY3GxwKhBihNxQGoM22xrny f6TGmzhJWctg69g5RnBml+SJh94967rJ4yMirKoFTMgSvCHJaEOnvyHxqO3lF7S+pg fJZehShZaXATK+ZjrIGXVnentbDNReUg7sOLX3yJ6ufOB2A6cMrHLDmswHtTiBapNN XLtm3mupnQYKw== From: Lee Jones To: lee@kernel.org, =?UTF-8?q?Nuno=20S=C3=A1?= , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Lars-Peter Clausen , linux@analog.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, Radu Sabau Subject: [PATCH v2 1/7] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode() Date: Mon, 23 Nov 2026 07:50:27 +0000 Message-ID: <20261123075122.373060-2-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075122.373060-1-lee@kernel.org> References: <20261123075122.373060-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" adis_update_scan_mode() frees both adis->xfer and adis->buffer at the start of a scan mode update without clearing either pointer to NULL. In both adis_update_scan_mode_burst() and the non-burst path, adis->xfer is allocated before adis->buffer. If the adis->xfer allocation fails, the function returns -ENOMEM while adis->buffer still holds the freed pointer from the previous scan configuration, causing a double-free on the next scan mode update or during device teardown in adis_buffer_cleanup(). Clear both pointers immediately after freeing them. Fixes: aacff892cbd5 ("staging:iio:adis: Preallocate transfer message") Closes: https://sashiko.dev/#/bug/linux-966f0cd4-488a-4d69-b8a5-449c751365d2 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- Cc: Radu Sabau v1 =3D> v2: - CC Radu Sabau (Jonathan) drivers/iio/imu/adis_buffer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c index 501da4eaef69..9d317b627eba 100644 --- a/drivers/iio/imu/adis_buffer.c +++ b/drivers/iio/imu/adis_buffer.c @@ -74,7 +74,9 @@ int adis_update_scan_mode(struct iio_dev *indio_dev, __be16 *tx, *rx; =20 kfree(adis->xfer); + adis->xfer =3D NULL; kfree(adis->buffer); + adis->buffer =3D NULL; =20 if (adis->data->burst_len) return adis_update_scan_mode_burst(indio_dev, scan_mask); --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 14:20:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420306; b=GsV0aHv/R5Xt9Ew7g97AEcdbF+lDKrbKZlmDxkL7Km1C5dPed03HZ2Jh8pm2ZvgFC9az /9KLrAjDpVYnck3j2jp/jdH9vpLpeay0evIuQvaMPWcQAGkh+TA3CKvtUCcAg7ZgKL/6l 9DzjBV0pjEdYzFGRHwfe9QSzsWnkgSJRXXx3BBgg/yF+iOK2FszbT/wrQobJ2tePcgxe0 XhNAaOLzFUpQ/07c00VUM0xK2NBTrwQxanTjjXsqCkJkUs23ziaQm6vKylwLWOdz7lxPD Uqco2k7+aHhs9OgcHmQny4MYpcgA3lk0A0wirqn1VieekYg/4qUPyxLKmv6PyKZzpDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420306; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=4U9CbCw+DHOvkyr6gju/PyFcVkH3hB0bo/MNj6uBwF8=; b=g2+Vz2OcraD2nYy9YVaUhvLBA6nStlNpXRv8GkKD7IZTfAwyqZtYqK9Bm/8MQRNb79tQ QtKEM97EBxxEUr8t3v/TS97r/XvQeGJ3EEeox6GgBnvDpRtj4vfxSBw5hbZRSpfZeJyi6 P0SGrM2izxd1CfW4jpfA7YzJnxf8qfq3ti2WqcwjPodigkb4dcsltt+7S5qmEnTv0+msg 8tWa2l8fe6glI2Y2GPhSp6kAUBz0wJgccNjUQwl9pleeZKqt5cH06ieIuec81xY7duGQo pvGNXdQZgoSZ2fh0BQEyKso8kdXBGVArs3HkHmrVhVjUm2AkZMGzu50IikCx5jr4e4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SX2gE6Gl; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85B69606A31A; Mon, 23 Nov 2026 07:51:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SX2gE6Gl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88E7C1F000CA; Mon, 23 Nov 2026 07:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420306; bh=4U9CbCw+DHOvkyr6gju/PyFcVkH3hB0bo/MNj6uBwF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SX2gE6Gls7B9LjRpUvHD3NISkbLG9H2oKGq8Yt1mPvZ41+PH2rdULZ5n5OWyjrb2h z5AYtdwdFlNtBrc1oqRmXhB7o0Vq0Ay4qqH0SX1h2jJhvGiiKEDKZklOXIfCxV+P41 +5akEKaL71bAkLzaERkrRDEuvKByKhDTqLY2cKjtUwrL9kta06mfr3vhofVwy+ZDR+ S1FKISkCj27b22xjyvsYBbCQDBsLTC5IAdh4Rl0zDAR8uN+c1e6qBDMXLj14b2T5ZY Z3KL6neI36qp+GDp0/HfK8OkSu3+yuCu0ft0yV+lttvzrJhUSEOEdbQlp1vHT4MR66 HWCLBhRusM1Lw== From: Lee Jones To: lee@kernel.org, Lucas Stankus , =?UTF-8?q?Nuno=20S=C3=A1?= , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Lothar Rubusch , linux@analog.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 2/7] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer() Date: Mon, 23 Nov 2026 07:50:28 +0000 Message-ID: <20261123075122.373060-3-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075122.373060-1-lee@kernel.org> References: <20261123075122.373060-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The ADXL313 32-entry FIFO plus one sample held in the output filter can yield up to 33 3-axis samples (ADXL313_FIFO_SIZE + 1). Because of missing parentheses in ADXL313_NUM_AXIS * ADXL313_FIFO_SIZE + 1, fifo_buf is sized at 97 16-bit elements instead of 99, overflowing the buffer by four bytes whenever all 33 entries are read. In addition, adxl313_get_samples() returns the 6-bit FIFO_STATUS entries field (0..63) without bounds checking, allowing a malfunctioning or spoofed bus device to overflow fifo_buf on the heap in adxl313_fifo_transfer(). Parenthesise (ADXL313_FIFO_SIZE + 1) when sizing fifo_buf and reject entry counts exceeding ADXL313_FIFO_SIZE + 1 with -EIO in adxl313_get_samples(). Fixes: ff8093fa6ba4 ("iio: accel: adxl313: add buffered FIFO watermark with= interrupt handling") Closes: https://sashiko.dev/#/bug/linux-6baeb7fe-ad68-4961-b5f9-5f0c7628df1e Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Return -EIO instead of -EINVAL when FIFO entries exceed ADXL313_FIFO_SIZE + 1 (Andy, Jonathan) drivers/iio/accel/adxl313.h | 2 +- drivers/iio/accel/adxl313_core.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/adxl313.h b/drivers/iio/accel/adxl313.h index 75ef54b60f75..de0bccfcdd0a 100644 --- a/drivers/iio/accel/adxl313.h +++ b/drivers/iio/accel/adxl313.h @@ -93,7 +93,7 @@ struct adxl313_data { struct mutex lock; /* lock to protect transf_buf */ u8 watermark; __le16 transf_buf __aligned(IIO_DMA_MINALIGN); - __le16 fifo_buf[ADXL313_NUM_AXIS * ADXL313_FIFO_SIZE + 1]; + __le16 fifo_buf[ADXL313_NUM_AXIS * (ADXL313_FIFO_SIZE + 1)]; }; =20 struct adxl313_chip_info { diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_c= ore.c index 6dc918c4ae17..dd0b3efd594e 100644 --- a/drivers/iio/accel/adxl313_core.c +++ b/drivers/iio/accel/adxl313_core.c @@ -921,7 +921,12 @@ static int adxl313_get_samples(struct adxl313_data *da= ta) if (ret) return ret; =20 - return FIELD_GET(ADXL313_REG_FIFO_STATUS_ENTRIES_MSK, regval); + /* 32 FIFO entries plus 1 entry at the output filter */ + ret =3D FIELD_GET(ADXL313_REG_FIFO_STATUS_ENTRIES_MSK, regval); + if (ret > ADXL313_FIFO_SIZE + 1) + return -EIO; + + return ret; } =20 static int adxl313_fifo_transfer(struct adxl313_data *data, int samples) --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 14:20:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420313; b=CE3sKgqT2wzdDo2z6obRzyU6fQbDRTqdKfPZRtEob2v7TXYPjJS4WYqMmunXTeMX6J9u 9f/+tPUh6M/4BRfVBhqPDZbPHDumoNQrekTosOgxHxny6x5GP/Mrbmo/4U4AkiY9A0yur mOgUxdN9LKvKr2+mll6isDMo9EruqNHwNXS3Q6dHziR4iFWgQuSVYDGjNmZyI3Qo5Y7Zr C+qFCX2fhm0Sfq81C1c3pFRuJXuqf+OHV/3uOg1MuEbqkwdk1ZVyl7YjI/z9AMH4EH0qH YbZbE2tVBROSvtltziMv9qlb0LTbj1rEQ3QJEJsRrlem+LYMa+x7KABgrr9FaB+15EA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420313; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=UhqU/Jx83x1rLEZktX/dxjJ0nFQK0B2T2V+HlFh1pHw=; b=z8xS1Z1RC2WfkioSxEG3PRKu+hxUUjmolcOr4CinsNZNcSGyui1iKLh5xUqSkE2hG3om yv3sWnYLXKcU7pTaMA0Qqhw1rSrf8KS8ei17WGWgjdBvvfLqUPlgxSreBRfl9rxVp2Z0j 9zVS5k7pvetrVHzUnkeOVuPlEgtZSa8Y75bVECe3WdbBPC+uhbNOIHojUCsXIhhRvYMRw r0xlWId7/j9YgRtZdjVJNKsIlSjV6gj4ibCETnhGyaSXF8GSKlvJkY0/b1s+yAPFRaekq sIUd+v/eptc8gafjVD26hzvrxm0ywqkfxIBgOueD3Sgq2p26dMB33HLcAh+IZD1666g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DBYeEPk0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C364D606A321; Mon, 23 Nov 2026 07:51:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DBYeEPk0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64AA91F000C4; Mon, 23 Nov 2026 07:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420313; bh=UhqU/Jx83x1rLEZktX/dxjJ0nFQK0B2T2V+HlFh1pHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DBYeEPk0U9ZU7K324UXVxoPzyM0nqbg9V+2FgIRCxfr+YW0QF59rGD/tyIYr7U+bc bkq1451FZ6ghQZajs3GhsPGVmYFKovd151h25995zeeog4YPU33xcbVYmXCLXVrM0v wH6VySduWEGFUDrR6xjTAIZbFfFIW03WiS8ZASoF9dvVnYwpUWYLAR69Co6HpzfxJc 7mr8viutRRYFuNasYybmhdXQw+mmg3GGvaIM62LiIR3fhE0I4Zh+5MQiTrBh1zZ+GB A5/9NZtGzPOwwDRTAaJ63z3gsik9H3NpRC3QNpszgw91cX164CT9lx5FZX38vqmaEw AkkHo6BZJrquA== From: Lee Jones To: lee@kernel.org, Lucas Stankus , =?UTF-8?q?Nuno=20S=C3=A1?= , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Alexandru Ardelean , linux@analog.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 3/7] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw() Date: Mon, 23 Nov 2026 07:50:29 +0000 Message-ID: <20261123075122.373060-4-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075122.373060-1-lee@kernel.org> References: <20261123075122.373060-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When reading IIO_CHAN_INFO_SAMP_FREQ, adxl313_read_raw() extracts the 4-bit rate field (0..15) from ADXL313_REG_BW_RATE and subtracts ADXL313_RATE_BASE (6) to index adxl313_odr_freqs[]. ADXL312 and ADXL314 support sub-6.25 Hz rate codes 0..5 and do not perform a soft reset during setup, and debugfs register writes or a faulty bus read can likewise yield codes below ADXL313_RATE_BASE. When that happens, subtracting ADXL313_RATE_BASE produces a negative index and reads before the start of adxl313_odr_freqs[]. Return -ERANGE if the rate field is below ADXL313_RATE_BASE. Fixes: 636d44633039 ("iio: accel: Add driver support for ADXL313") Closes: https://sashiko.dev/#/bug/linux-d6086ee0-d732-43b6-b8ac-24e5bf86a9f8 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Return -ERANGE instead of -EINVAL for sub-base ODR codes (Andy) drivers/iio/accel/adxl313_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_c= ore.c index dd0b3efd594e..aaab1935ac60 100644 --- a/drivers/iio/accel/adxl313_core.c +++ b/drivers/iio/accel/adxl313_core.c @@ -647,7 +647,11 @@ static int adxl313_read_raw(struct iio_dev *indio_dev, if (ret) return ret; =20 - ret =3D FIELD_GET(ADXL313_RATE_MSK, regval) - ADXL313_RATE_BASE; + regval =3D FIELD_GET(ADXL313_RATE_MSK, regval); + if (regval < ADXL313_RATE_BASE) + return -ERANGE; + + ret =3D regval - ADXL313_RATE_BASE; *val =3D adxl313_odr_freqs[ret][0]; *val2 =3D adxl313_odr_freqs[ret][1]; return IIO_VAL_INT_PLUS_MICRO; --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 14:20:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420320; b=KwnoW7zVbM9DFG3H4JATQHtuiO+ee6v6qu7VIAny8RI/p6eeG0MkXns5Md37Aris1LUu xB3Bz8NsBKSaKhPEl38KOFC16ivJ+aErbiOVOLziUj1i0b5SoYD1tF2mm9MUpGX1ZwJ8e rMfPw6ie6WZy3PxMD8KtQZXUMTZVLAaniXiBdjZcDd5VxmGDSqVo/M8hpXJnHJtP5cEd2 U14k45unD0ILrCrboeUtdof6RKazB4eDlZqutTd3oDsJUYSx5AoAUTdXbS/0Yd668jJfU whoJHywmX5e74yR3GHa5AQGENSBJI+X9j7Y9a1zQM+APNQ2B092LRDRQhQbU+x1dNzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420320; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=YRyfRtj39QvPj0FnuGJPdIFrD+6NLjA2bCiGMIOAbQE=; b=d5iZx6gac9cRJeOT/6IQQMnB159RYPty3f/JnO8v8v80Yzf6ljIaiypivxDJ8+rTS9UZ vrWVeeUeokrhIcJ26KjXU2JtreEBOiHgk++oSVLjjvVPCUMUtP45LrHGj8eZEmz1/nOQA XyiVSuB2DqUqNUD0Vpt8Oj14sSfsd1Z9PJWLEG3tgbEbnlJBd+CRF4JktM6de2IYRAyiA uuia0JFOhbvkjPICfgKqZ2wGQ2U6hsRzKfqCF3KyakjhP6XK3Htf6CItwiv64IeV6TNW/ vNzDoXA6hbARL4f3YlFo68vJRwIxS0b5hPIQB/DcnzqKcH6SYR/0FqLoVBNBLeDnjKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hDElAKwj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D51E606A31E; Mon, 23 Nov 2026 07:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hDElAKwj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 820081F000E1; Mon, 23 Nov 2026 07:51:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420320; bh=YRyfRtj39QvPj0FnuGJPdIFrD+6NLjA2bCiGMIOAbQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hDElAKwjNFR8RXQExLIBsG67NFyZfajMfMvSoN5OkoxS+7/bxK/AVJN4dph/SzLJ2 31Qtt7YOv6E91vPdb9xklVcueeFmCjw/2DNB4yubAVUMbhfZ1AbDOpR2i6M/zoaH5e 43OukL4H2M+brxL7OTxVniRJmCZEYdyt/xEqDLTzRrNRG9AIDKs9kJxNvhkmNDpP1O OcNW/NtK7IWcZLeQJ2FVOY+/0WfvXAxf0GAqfAvW7S9Ffk86YChpxhZHFGlvH3wKlb pVlFRH3UecFVWLwazw+lpw4KJWiNwV6eDQaZByenKHUnFRlNoO0UHPHMIRAjqP9UyN r8XrfsiaLFh0Q== From: Lee Jones To: lee@kernel.org, Marius Cristea , Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Bogdan Bolocan , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 4/7] iio: adc: pac1934: Fix custom attribute allocation and channel bounds Date: Mon, 23 Nov 2026 07:50:30 +0000 Message-ID: <20261123075122.373060-5-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075122.373060-1-lee@kernel.org> References: <20261123075122.373060-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pac1934_prep_custom_attributes() sizes the pac1934_custom_attr pointer array using sizeof(*pac1934_group) instead of sizeof(*pac1934_custom_attr) and adds 1 byte rather than one pointer element for the terminating NULL entry. When active_channels_count is zero, only a single byte is allocated and iio_device_register_sysfs() reads past the allocation when scanning the attribute list. In addition, active_channels_count is counted over info->phys_channels, whereas the population steps unconditionally inspect all four entries of info->active_channels[], which can write past the end of the array on 1-, 2-, and 3-channel chip variants. Allocate active_channels_count + 1 attribute pointers with devm_kzalloc_objs() and bound the population loop by info->phys_channels. Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x") Closes: https://sashiko.dev/#/bug/linux-e7b7eab1-9ed4-4d4b-b9c7-889bf720aa5b Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Order local variables in reverse Christmas tree style (Andy, Jonathan) - Scope loop index j to the for-loop (Andy, Jonathan) drivers/iio/adc/pac1934.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c index 5e901ab25c8e..a307689c6814 100644 --- a/drivers/iio/adc/pac1934.c +++ b/drivers/iio/adc/pac1934.c @@ -1435,13 +1435,20 @@ static IIO_DEVICE_ATTR(in_shunt_resistor3, 0644, static IIO_DEVICE_ATTR(in_shunt_resistor4, 0644, pac1934_shunt_value_show, pac1934_shunt_value_store, 3); =20 +static struct attribute * const pac1934_shunt_attrs[] =3D { + PAC1934_DEV_ATTR(in_shunt_resistor1), + PAC1934_DEV_ATTR(in_shunt_resistor2), + PAC1934_DEV_ATTR(in_shunt_resistor3), + PAC1934_DEV_ATTR(in_shunt_resistor4), +}; + static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info, struct iio_dev *indio_dev) { - int i, active_channels_count =3D 0; + struct device *dev =3D &info->client->dev; struct attribute **pac1934_custom_attr; struct attribute_group *pac1934_group; - struct device *dev =3D &info->client->dev; + int i, active_channels_count =3D 0; =20 for (i =3D 0 ; i < info->phys_channels; i++) if (info->active_channels[i]) @@ -1451,26 +1458,16 @@ static int pac1934_prep_custom_attributes(struct pa= c1934_chip_info *info, if (!pac1934_group) return -ENOMEM; =20 - pac1934_custom_attr =3D devm_kzalloc(dev, - (PAC1934_CUSTOM_ATTR_FOR_CHANNEL * - active_channels_count) - * sizeof(*pac1934_group) + 1, - GFP_KERNEL); + pac1934_custom_attr =3D devm_kzalloc_objs(dev, *pac1934_custom_attr, + PAC1934_CUSTOM_ATTR_FOR_CHANNEL * + active_channels_count + 1); if (!pac1934_custom_attr) return -ENOMEM; =20 i =3D 0; - if (info->active_channels[0]) - pac1934_custom_attr[i++] =3D PAC1934_DEV_ATTR(in_shunt_resistor1); - - if (info->active_channels[1]) - pac1934_custom_attr[i++] =3D PAC1934_DEV_ATTR(in_shunt_resistor2); - - if (info->active_channels[2]) - pac1934_custom_attr[i++] =3D PAC1934_DEV_ATTR(in_shunt_resistor3); - - if (info->active_channels[3]) - pac1934_custom_attr[i] =3D PAC1934_DEV_ATTR(in_shunt_resistor4); + for (int j =3D 0; j < info->phys_channels; j++) + if (info->active_channels[j]) + pac1934_custom_attr[i++] =3D pac1934_shunt_attrs[j]; =20 pac1934_group->attrs =3D pac1934_custom_attr; info->iio_info.attrs =3D pac1934_group; --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 14:20:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420333; b=SfkidSNqS0pDvZJnM2fC7NHTo+Hljzl8sV64M0TFuZmdS1to3bdXqYwyHYLYGr7VbcXr FKzLJAL1+GVPwYhExsQw1S+6y6A/00a3iNeaKViMX2rIy76gzWffcbOH16/cTpkhfYBR7 NGAM70ZD+KDNW5QvwaQnaqX5CWDOxX/UxOnQ6Do9NdoRQ18chtZqOdFeuZCnsowQZDphY tHro35QqOymS17TfynO2fHjyW5Hdc1mlUDThp25XqcMB4B6WLWr/pLdex3nAs3WyoxIxf VQ/wu9EHUUnuIqyW17XNUSwWlF9gYK2KSQ6FdMRoROxpyRpY/HxJ2NaZd9S07QXX3NA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420333; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=9L/uB9YKTqcIXG5snVM/1M/beitHoknzxunxoF1iTN0=; b=C9VDyR7Vgsz+5h2Vudq8JYhpC+Qcx5k8rqIC48DPLFRcJODFkoVb4uVxTz9IWoX1I7He X0KpsVeBPa+GxBXpO4Kyv9DwOJuRhblktWt6/FQq+HvsWjVNLI6qv/gmpbe44xNnbJOwK mFnS6w7WYZBm7cLnPRACE6hxfAXs/FpWg8bL0NPca22tJkfZt5sxgoZQ9U7RO2v7vGVwv pw7mBdqNcY3gcHjNuyMIN45LVH75bG85hIkxuVYPZdlrbSbIFOGuFkGsmjS488ktNzH5I m1Sppueqae5z9NrvQaVRpGoR6QTmLF4arscbhmLjpPEX9fm1JjpRQmQbUOydZi1jhQA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RPrAzqwO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DEB5606A31E; Mon, 23 Nov 2026 07:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RPrAzqwO Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABF861F000D4; Mon, 23 Nov 2026 07:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420333; bh=9L/uB9YKTqcIXG5snVM/1M/beitHoknzxunxoF1iTN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RPrAzqwOw9XPFQZrikGt3pcMD8WGP2ipxlnAmY0OTOYvPnmCFGL15UXF3iukXOT8X YltaN3xU4Wv+2ZU8vzXeg9ECqj63VTICUr57qaSREFywhu6q/FTT1JhvwVXIn9VM+I R2cyXr/YE2rrIUQThzYNYnD0iyPLGE7kL3Edxh7erzFV5xC3+hYa91HFtWBVvjWusf +euACf1jdEsMHrqhj0ET/udGrhvb3aEBgzgSebc8bWLfa0rzLMjDiAVsBw4cQS8GdX lrn8NlsDEn4I1ZXkhnv8IW8Fq8+QeAwtFviQIJkIzRHsOg+48BfebzFSaXhLrlsQqW I4r3Xxb8stbOg== From: Lee Jones To: lee@kernel.org, Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Jishnu Prakash , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Date: Mon, 23 Nov 2026 07:50:31 +0000 Message-ID: <20261123075122.373060-6-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075122.373060-1-lee@kernel.org> References: <20261123075122.373060-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" struct tm5_aux_dev_wrapper embeds a reference-counted struct auxiliary_device, whose memory must be released from its dev.release callback once the final device reference is dropped. Allocating the wrapper and its tm_props array with parent-managed devm_*() helpers and providing an empty adc5_gen3_aux_device_release() causes parent devres teardown to free both allocations immediately when the parent unbinds, even if external references to the embedded struct device are still held. It also leaks the OF node reference taken by device_set_of_node_from_dev(). Allocate the wrapper and tm_props array without devm, release them together with the OF node reference in adc5_gen3_aux_device_release(), and register auxiliary_device_destroy() via devm_add_action_or_reset() once the auxiliary device has been added. Fixes: baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC") Closes: https://sashiko.dev/#/bug/linux-b738d116-f32b-4edf-aa73-77827b79a407 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Allocate tm_props without devm and release it alongside the OF node reference in adc5_gen3_aux_device_release() (Jonathan) - Move auxiliary_device_init() earlier and register auxiliary_device_destroy() via devm_add_action_or_reset(), avoiding devm_release_action() (Andy, Jonathan) - Note: is already included drivers/iio/adc/qcom-spmi-adc5-gen3.c | 57 +++++++++++++-------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-s= pmi-adc5-gen3.c index a23eb5c9096d..85450aa37e65 100644 --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c @@ -21,9 +21,11 @@ #include #include #include +#include #include #include #include +#include #include #include =20 @@ -598,24 +600,22 @@ static int adc5_get_fw_data(struct adc5_chip *adc) return 0; } =20 -static void adc5_gen3_uninit_aux(void *data) +static void adc5_gen3_aux_device_release(struct device *dev) { - auxiliary_device_uninit(data); -} + struct tm5_aux_dev_wrapper *aux_device =3D + container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev); =20 -static void adc5_gen3_delete_aux(void *data) -{ - auxiliary_device_delete(data); + of_node_put(dev->of_node); + kfree(aux_device->tm_props); + kfree(aux_device); } =20 -static void adc5_gen3_aux_device_release(struct device *dev) {} - static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id) { struct tm5_aux_dev_wrapper *aux_device; int i, ret, i_tm =3D 0; =20 - aux_device =3D devm_kzalloc(adc->dev, sizeof(*aux_device), GFP_KERNEL); + aux_device =3D kzalloc_obj(*aux_device); if (!aux_device) return -ENOMEM; =20 @@ -624,11 +624,20 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_ch= ip *adc, int id) aux_device->aux_dev.dev.parent =3D adc->dev; aux_device->aux_dev.dev.release =3D adc5_gen3_aux_device_release; =20 - aux_device->tm_props =3D devm_kcalloc(adc->dev, adc->n_tm_channels, - sizeof(*aux_device->tm_props), - GFP_KERNEL); - if (!aux_device->tm_props) + ret =3D auxiliary_device_init(&aux_device->aux_dev); + if (ret) { + kfree(aux_device); + return ret; + } + + device_set_of_node_from_dev(&aux_device->aux_dev.dev, adc->dev); + + aux_device->tm_props =3D kzalloc_objs(*aux_device->tm_props, + adc->n_tm_channels); + if (!aux_device->tm_props) { + auxiliary_device_uninit(&aux_device->aux_dev); return -ENOMEM; + } =20 aux_device->dev_data =3D &adc->dev_data; =20 @@ -639,28 +648,16 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_ch= ip *adc, int id) i_tm++; } =20 - device_set_of_node_from_dev(&aux_device->aux_dev.dev, adc->dev); - aux_device->n_tm_channels =3D adc->n_tm_channels; =20 - ret =3D auxiliary_device_init(&aux_device->aux_dev); - if (ret) - return ret; - - ret =3D devm_add_action_or_reset(adc->dev, adc5_gen3_uninit_aux, - &aux_device->aux_dev); - if (ret) - return ret; - ret =3D auxiliary_device_add(&aux_device->aux_dev); - if (ret) - return ret; - ret =3D devm_add_action_or_reset(adc->dev, adc5_gen3_delete_aux, - &aux_device->aux_dev); - if (ret) + if (ret) { + auxiliary_device_uninit(&aux_device->aux_dev); return ret; + } =20 - return 0; + return devm_add_action_or_reset(adc->dev, auxiliary_device_destroy, + &aux_device->aux_dev); } =20 void adc5_gen3_mutex_lock(struct device *dev) --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 14:20:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420346; b=u0ZWoUaMm8XDWQJ20uucaeabmXtOBCFaV96zmY9S2Mho88+Sj75u92OVbW+XNa5AUyp0 a3bCk41f3/Vx2DEyaCZhkVfoCWtxljVM61Ikxa7SYojeOBkQRXevooesjSbk+jGrtQIls 9mt41GH4PHbUTzy2PG2SXbDI2IhXgU2IvoDd0nUUS5yvqrSbYpDoP4Iffq2o8x2F6uP7Q 5GbCmU3ZrULbA3jEur3GHNDRtzj7IXcC677AMISOaKqEQrLWmMk6W85CtIhoKqTdTHZ+Y ARsI/hjGgvZ2Z0SoDj/ZPUEuUzRMpqto2eX+uOjwvNz1wCLKnLcEZJV3dW5HLoHb1fw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420346; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=pzBruCLqcjTUf993fFO1zsE6F8+uGYlxYUHOWN/SV4U=; b=l4qTaN+UJ7krpWEml4yvrxSKi5hj+nAayB7sy8tPUydSMdEBrBhhZ/kMG8A37QGUwNKN D7unE/CSldC2JUafH+8gWmw/CcAgXUOmcnQz/aOVwla+U2g1SwDFCpispFklXscNFBKja T64yTSa00eox0T+q8dKkfMqEQILgE+Qz7HV8elap45gILSZGbNiWbF/mxxrAtuD3zCCEA jPbb3JVBeugs/1hJy6WnVPRVdTClQq0Xb5rr28P4/prQohFu4W94LRbcfBy+Jl9/dqBQ1 +9ABTz/N4qCgbbX5c5cdW1mI8O9S/HLM9E6o/KmzZb19aaewyKJ5ptRTtw9a+YJxvtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T8WAQKBS; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 725FC606A688; Mon, 23 Nov 2026 07:52:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T8WAQKBS Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACC7F1F000D0; Mon, 23 Nov 2026 07:52:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420346; bh=pzBruCLqcjTUf993fFO1zsE6F8+uGYlxYUHOWN/SV4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T8WAQKBSFSa+AYF4ma/3QxzVEqIGxhTDeaBYC5fDApUW6Q2MnCu8CQ8g0alJZ/FsG 8EEYKMcowfWLHZ86+Md4g7SXs3auULNQWpi+vTU5+UZTEiHzYXYmk7VbxUZ4e5jK4D 2YP04mQQp00xj1ZIFKESyZbmRiRLdwXs6rPXSWszuYU6Pt0r2qsKJ9xCuoklgl5mCo 8R6xeF98wltDir9AcX4DZ0LdVKco+nhMiYm0NSqNpBY+8KqsREbkKEY93iln0rvOsR byYRTJX4jFA8xCUGB5kWpAYj5Och0Pqn/HOUX4mfDlI7CWMvKcEShCr4r/gpE40Y1k 8G2d6d6K81v4Q== From: Lee Jones To: lee@kernel.org, Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Jishnu Prakash , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Date: Mon, 23 Nov 2026 07:50:32 +0000 Message-ID: <20261123075122.373060-7-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075122.373060-1-lee@kernel.org> References: <20261123075122.373060-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If a firmware node supplies an empty reg property, device_property_count_u32() returns 0, which passes the negative error check in adc5_gen3_probe() and leaves num_sdams set to 0. Subsequent zero-length allocations return ZERO_SIZE_PTR, which is then dereferenced when requesting the VADC SDAM interrupt, and num_sdams * 8 - 1 wraps in unsigned comparisons when counting TM channels. Return -ENOENT when device_property_count_u32() reports zero elements. Fixes: baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC") Closes: https://sashiko.dev/#/bug/linux-d8ad5868-82f5-4c97-bc67-84ceebb10a1a Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Return -ENOENT instead of -EINVAL when reg is empty (Andy) drivers/iio/adc/qcom-spmi-adc5-gen3.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-s= pmi-adc5-gen3.c index 85450aa37e65..8e316aa88f48 100644 --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c @@ -736,6 +736,8 @@ static int adc5_gen3_probe(struct platform_device *pdev) ret =3D device_property_count_u32(dev, "reg"); if (ret < 0) return ret; + if (!ret) + return -ENOENT; =20 adc->dev_data.num_sdams =3D ret; =20 --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 14:20:09 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420353; b=lK0P1+PlFbfjFJfQ0rYLWJHFVmtRYzMzNagomkw3xOK63cSoPxSlkqwv7BXJOmu4Znma qdz5ra4AFiNcam5up19v5DN5dLdyRhTTW20A8iD/OiNttgJVnHJdqUrvb6LzH3e7c3ZNO /Muls8ZOtlQsIojUKfQRJVMHr22TfbMwscWp72twQfmwX1B+Q0kisSB3PZ4xqSYWUixMh PSKEw8z4J3FmqtORCzxMP7JR81cYkLnLnrqQqqgVx03YwOV0lngdh303tSgsgkoJ8A1Si /rC4Ioacb7NUEsk2ONru5EtvD8JOytwBiDzEVzMW+maG1EUV0tpPRrU4mLuhwwLtVdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420353; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=JVswLX8KECFVMNl+lWiOH76IWuKZyq8o+lWmxaPSi7Q=; b=oOQ/iCQN87QmGvdeJmSWd9bOdYQz5iDQXr6FuSizTYDRmm8sXgE0KphJ0pJ5lg5gd3YW 28rnzSYnRK0saSei4juwwQN0dwT57ieSjtclfmMqiaEQPHcxkM7/D6YdeZ/N+P58uRD5K eXakcgxZhehrAF3Y/C1u5DkRs/ZhDEYSnfwQYHG8+ZmGHbjerSNy8E+vALNCWUFL2mPvl BkbddckwzJZyIM5cTc2EJatjT1l+aDLzbafveNU7QUPgRRgOPGtvQFYoAvsz0gYr6KyuG ntl4kgeteNobFzrHvyRXTsJ5lqsdnhoHkw2grAODT6aHQpCubv+lJpzUMOQmlEIAqIg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="bWPHT2/D"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76612606A6AA; Mon, 23 Nov 2026 07:52:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bWPHT2/D Received: by smtp.kernel.org (Postfix) with ESMTPSA id 867251F000D0; Mon, 23 Nov 2026 07:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420353; bh=JVswLX8KECFVMNl+lWiOH76IWuKZyq8o+lWmxaPSi7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bWPHT2/D7y+b0FV1aPHKqFL0zvg2hTUszzW3wN2RVKtXEaBZTjBc12QXnBo8tHN8K gc83Z9apRrDYd3ofKoQDOCQqmtA8qR4lB72CPKX5OSPvfel/VSfeL1zImfOR2HqcwW QgCB764Rum3iQaQ1lZYnD0taNYMCTSdzAHbj1VcubWbYbNsGpzYKF+Z04ppw4PLsST pMNJvnxkOCQOQ4/nEmvEpB5dhpN0fSo1iJZTufAZEqv/BRcgIDL+HkXkuOYGc4NIN8 r8TfttjblaNNKp/Tt/MiRqmwqUtmPtF+RjcbocK8P6OITn+5JOQGg9Hj0GhGw1JD2I I0f/iNGQJpL4w== From: Lee Jones To: lee@kernel.org, Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Mathieu Othacehe , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 7/7] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq() Date: Mon, 23 Nov 2026 07:50:33 +0000 Message-ID: <20261123075122.373060-8-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075122.373060-1-lee@kernel.org> References: <20261123075122.373060-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" isl29501_set_freq() computes freq =3D val * 1000000 + val2 % 1000000 in a signed 32-bit int and passes it directly to do_div() without checking for zero or negative inputs. Writing 0 to the sampling_frequency attribute triggers a division by zero in the kernel, while valid frequencies above 2147 Hz up to the sensor's 2222 Hz limit overflow signed int. Validate that val and val2 are non-negative, compute freq using HZ_PER_MHZ as an unsigned int within [1, 2222 * HZ_PER_MHZ], and return -ERANGE otherwise. Fixes: 1c28799257bc ("iio: light: isl29501: Add support for the ISL29501 To= F sensor.") Closes: https://sashiko.dev/#/bug/linux-e4bc1c30-bbf1-458a-99f9-a36e949af67c Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Order local variables in reverse Christmas tree style (Andy) - Group range checks by variable (Andy) - Use HZ_PER_MHZ from (Andy) drivers/iio/proximity/isl29501.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/iio/proximity/isl29501.c b/drivers/iio/proximity/isl29= 501.c index a98a9975323c..43be78b82e50 100644 --- a/drivers/iio/proximity/isl29501.c +++ b/drivers/iio/proximity/isl29501.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 /* Control, setting and status registers */ #define ISL29501_DEVICE_ID 0x00 @@ -863,12 +864,18 @@ static int isl29501_set_calibbias(struct isl29501_pri= vate *isl29501, static int isl29501_set_freq(struct isl29501_private *isl29501, int val, int val2) { - int freq; unsigned long long sample_time; + unsigned int freq; + + if (val < 0 || val > 2222 || val2 < 0) + return -ERANGE; =20 /* sample_freq =3D 1 / (0.000450 * (sample_time + 1) * 10^-6) */ - freq =3D val * 1000000 + val2 % 1000000; - sample_time =3D 2222ULL * 1000000ULL; + freq =3D val * HZ_PER_MHZ + val2 % HZ_PER_MHZ; + if (!freq || freq > 2222U * HZ_PER_MHZ) + return -ERANGE; + + sample_time =3D 2222ULL * HZ_PER_MHZ; do_div(sample_time, freq); =20 sample_time -=3D 1; --=20 2.56.1.750.gf70dc682cf-goog