iio: chemical: sps30: fix buffer size calculations
Subsystems (2)
cover iio: chemical: sps30: fix buffer size calculations
Fix incorrect buffer size calculations in sps30_i2c_read_meas() and sps30_serial_read_meas(). Both functions used sizeof(num) which evaluates to sizeof(size_t) (8 bytes on 64-bit) instead of sizeof(*meas) (4 bytes for __be32), leading to oversized buffer requests.
Antoniu Miclaus (2):
iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_read_meas()
iio: chemical: sps30_serial: fix buffer size in
sps30_serial_read_meas()
drivers/iio/chemical/sps30_i2c.c | 2 +- drivers/iio/chemical/sps30_serial.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_read_meas()
sizeof(num) evaluates to sizeof(size_t) (8 bytes on 64-bit) instead of the intended __be32 element size (4 bytes). Use sizeof(*meas) to correctly match the buffer element type.
--- drivers/iio/chemical/sps30_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/sps30_i2c.c +1 -1
@@ -171,7 +171,7 @@ static int sps30_i2c_read_meas(struct sps30_state *state, __be32 *meas, size_t nif (!sps30_i2c_meas_ready (state))return -ETIMEDOUT ; -return sps30_i2c_command (state,SPS30_I2C_READ_MEAS ,NULL ,0 , meas,sizeof (num) * num); +return sps30_i2c_command (state,SPS30_I2C_READ_MEAS ,NULL ,0 , meas,sizeof (*meas) * num); }static int sps30_i2c_clean_fan (struct sps30_state *state)
Signature · 1 line
2.43.0
Re: [PATCH 1/2] iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_read_meas()
Quoted 3 lines · Antoniu Miclaus
sizeof(num) evaluates to
sizeof(size_t)(8 bytes on 64-bit) instead of the intended__be32element size (4 bytes). Usesizeof(*meas)to correctly match the buffer element type.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/2] iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_read_meas()
In reply to Antoniu MiclausQuoted 25 lines · Antoniu Miclaus
sizeof(num) evaluates to
sizeof(size_t)(8 bytes on 64-bit) instead of the intended__be32element size (4 bytes). Usesizeof(*meas)to correctly match the buffer element type.Fixes 8f3f13085278 ("iio: sps30: separate core and interface specific code")Signed-off-by Antoniu Miclaus <[email protected]>--- drivers/iio/chemical/sps30_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/chemical/sps30_i2c.c +1
-2@@ -171,7 +171,7 @@ static int sps30_i2c_read_meas(struct sps30_state *state, __be32 *meas, size_t nif (!sps30_i2c_meas_ready (state))return -ETIMEDOUT ; -return sps30_i2c_command (state,SPS30_I2C_READ_MEAS ,NULL ,0 , meas,sizeof (num) * num); +return sps30_i2c_command (state,SPS30_I2C_READ_MEAS ,NULL ,0 , meas,sizeof (*meas) * num); }static int sps30_i2c_clean_fan (struct sps30_state *state) --
Quoted 2 lines
2.43.0
PATCH 2/2 iio: chemical: sps30_serial: fix buffer size in sps30_serial_read_meas()
In reply to Antoniu Miclaussizeof(num) evaluates to sizeof(size_t) which is 8 bytes on 64-bit, but the buffer elements are only 4 bytes. The same function already uses sizeof(*meas) on line 312, making the mismatch evident. Use sizeof(*meas) consistently.
--- drivers/iio/chemical/sps30_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/chemical/sps30_serial.c +1 -1
@@ -303,7 +303,7 @@ static int sps30_serial_read_meas(struct sps30_state *state, __be32 *meas, size_if (msleep_interruptible (1000 ))return -EINTR ; - ret =sps30_serial_command (state,SPS30_SERIAL_READ_MEAS ,NULL ,0 , meas, num *sizeof (num)); + ret =sps30_serial_command (state,SPS30_SERIAL_READ_MEAS ,NULL ,0 , meas, num *sizeof (*meas));if (ret <0 )return ret;/* if measurements aren't ready sensor returns empty frame */
Signature · 1 line
2.43.0
Re: [PATCH 2/2] iio: chemical: sps30_serial: fix buffer size in sps30_serial_read_meas()
Quoted 4 lines · Antoniu Miclaus
sizeof(num) evaluates to
sizeof(size_t)which is 8 bytes on 64-bit, but the buffer elements are only 4 bytes. The same function already usessizeof(*meas)on line 312, making the mismatch evident. Usesizeof(*meas)consistently.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/2] iio: chemical: sps30_serial: fix buffer size in sps30_serial_read_meas()
In reply to Antoniu MiclausQuoted 26 lines · Antoniu Miclaus
sizeof(num) evaluates to
sizeof(size_t)which is 8 bytes on 64-bit, but the buffer elements are only 4 bytes. The same function already usessizeof(*meas)on line 312, making the mismatch evident. Usesizeof(*meas)consistently.Fixes b2e171f5a5c6 ("iio: sps30: add support for serial interface")Signed-off-by Antoniu Miclaus <[email protected]>--- drivers/iio/chemical/sps30_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/chemical/sps30_serial.c +1
-2@@ -303,7 +303,7 @@ static int sps30_serial_read_meas(struct sps30_state *state, __be32 *meas, size_if (msleep_interruptible (1000 ))return -EINTR ; - ret =sps30_serial_command (state,SPS30_SERIAL_READ_MEAS ,NULL ,0 , meas, num *sizeof (num)); + ret =sps30_serial_command (state,SPS30_SERIAL_READ_MEAS ,NULL ,0 , meas, num *sizeof (*meas));if (ret <0 )return ret;/* if measurements aren't ready sensor returns empty frame */ --
Quoted 2 lines
2.43.0
Quoted 6 lines · On Thu, 12 Feb 2026 14:46:06 +0200 Antoniu Miclaus…
Fix incorrect buffer size calculations in
sps30_i2c_read_meas()andsps30_serial_read_meas(). Both functions used sizeof(num) which evaluates tosizeof(size_t)(8 bytes on 64-bit) instead ofsizeof(*meas)(4 bytes for__be32), leading to oversized buffer requests.
Quoted 9 lines
Antoniu Miclaus (2):
iio: chemical:sps30_i2c: fix buffer size insps30_i2c_read_meas()
iio: chemical:sps30_serial: fix buffer size insps30_serial_read_meas()drivers/iio/chemical/sps30_i2c.c | 2 +- drivers/iio/chemical/sps30_serial.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan