[PATCH 2/2] iio: chemical: sps30_serial: fix buffer size in sps30_serial_read_meas()

Antoniu Miclaus posted 2 patches 1 month, 2 weeks ago
[PATCH 2/2] iio: chemical: sps30_serial: fix buffer size in sps30_serial_read_meas()
Posted by Antoniu Miclaus 1 month, 2 weeks ago
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
uses sizeof(*meas) on line 312, making the mismatch evident. Use
sizeof(*meas) consistently.

Fixes: b2e171f5a5c6 ("iio: sps30: add support for serial interface")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
 drivers/iio/chemical/sps30_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/chemical/sps30_serial.c b/drivers/iio/chemical/sps30_serial.c
index 008bc88590f3..a5e6bc08d5fd 100644
--- a/drivers/iio/chemical/sps30_serial.c
+++ b/drivers/iio/chemical/sps30_serial.c
@@ -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 */
-- 
2.43.0
Re: [PATCH 2/2] iio: chemical: sps30_serial: fix buffer size in sps30_serial_read_meas()
Posted by Tomasz Duszyński 1 month, 2 weeks ago
On Thu, Feb 12, 2026 at 1:46 PM Antoniu Miclaus
<antoniu.miclaus@analog.com> wrote:
>
> 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
> uses sizeof(*meas) on line 312, making the mismatch evident. Use
> sizeof(*meas) consistently.
>
> Fixes: b2e171f5a5c6 ("iio: sps30: add support for serial interface")
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> ---
>  drivers/iio/chemical/sps30_serial.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/chemical/sps30_serial.c b/drivers/iio/chemical/sps30_serial.c
> index 008bc88590f3..a5e6bc08d5fd 100644
> --- a/drivers/iio/chemical/sps30_serial.c
> +++ b/drivers/iio/chemical/sps30_serial.c
> @@ -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 */
> --
> 2.43.0
>

Acked-by: Tomasz Duszynski <tduszyns@gmail.com>
Re: [PATCH 2/2] iio: chemical: sps30_serial: fix buffer size in sps30_serial_read_meas()
Posted by Andy Shevchenko 1 month, 2 weeks ago
On Thu, Feb 12, 2026 at 02:46:08PM +0200, Antoniu Miclaus wrote:
> 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
> uses sizeof(*meas) on line 312, making the mismatch evident. Use
> sizeof(*meas) consistently.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko