[PATCH 1/2] iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_read_meas()

Antoniu Miclaus posted 2 patches 1 month, 2 weeks ago
[PATCH 1/2] iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_read_meas()
Posted by Antoniu Miclaus 1 month, 2 weeks ago
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.

Fixes: 8f3f13085278 ("iio: sps30: separate core and interface specific code")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
 drivers/iio/chemical/sps30_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/chemical/sps30_i2c.c b/drivers/iio/chemical/sps30_i2c.c
index f692c089d17b..c92f04990c34 100644
--- a/drivers/iio/chemical/sps30_i2c.c
+++ b/drivers/iio/chemical/sps30_i2c.c
@@ -171,7 +171,7 @@ static int sps30_i2c_read_meas(struct sps30_state *state, __be32 *meas, size_t n
 	if (!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)
-- 
2.43.0
Re: [PATCH 1/2] iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_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) (8 bytes on 64-bit) instead
> of the intended __be32 element size (4 bytes). Use sizeof(*meas) to
> correctly match the buffer element type.
>
> Fixes: 8f3f13085278 ("iio: sps30: separate core and interface specific code")
> Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
> ---
>  drivers/iio/chemical/sps30_i2c.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/chemical/sps30_i2c.c b/drivers/iio/chemical/sps30_i2c.c
> index f692c089d17b..c92f04990c34 100644
> --- a/drivers/iio/chemical/sps30_i2c.c
> +++ b/drivers/iio/chemical/sps30_i2c.c
> @@ -171,7 +171,7 @@ static int sps30_i2c_read_meas(struct sps30_state *state, __be32 *meas, size_t n
>         if (!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)
> --
> 2.43.0
>

Acked-by: Tomasz Duszynski <tduszyns@gmail.com>
Re: [PATCH 1/2] iio: chemical: sps30_i2c: fix buffer size in sps30_i2c_read_meas()
Posted by Andy Shevchenko 1 month, 2 weeks ago
On Thu, Feb 12, 2026 at 02:46:07PM +0200, Antoniu Miclaus wrote:
> 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.

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

-- 
With Best Regards,
Andy Shevchenko