summaryrefslogtreecommitdiff
path: root/drivers/iio/imu
diff options
context:
space:
mode:
authorKees Cook <kees+treewide@kernel.org>2026-09-17 14:13:51 -0700
committerJonathan Cameron <jonathan.cameron@oss.qualcomm.com>2026-09-21 00:22:17 +0100
commitcee9d40e7e5687e2385214b63cc2c3457e0987c6 (patch)
tree67081e925f8c7ba2a57ba2c27374af02c94521b2 /drivers/iio/imu
parent0e317f8fd1f5db84406ca9bfa37c55aa09fceaad (diff)
iio: imu: st_lsm6dsx: Allocate ext_channels with ARRAY_SIZE()
In preparation for making the devm_kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.) This is allocating a copy of magn_channels, which is an array of struct iio_chan_spec, but the size was taken from the whole array, which would make the allocation type a pointer to the array rather than the "struct iio_chan_spec *" being assigned. Allocate ARRAY_SIZE-many entries instead. The resulting allocation size is the same. Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0: drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.o Assisted-by: LLM coccinelle Signed-off-by: Kees Cook <kees+treewide@kernel.org> Acked-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Diffstat (limited to 'drivers/iio/imu')
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index d6a1eeb151ca..cbc47fa5b101 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -766,8 +766,8 @@ st_lsm6dsx_shub_alloc_iiodev(struct st_lsm6dsx_hw *hw,
IIO_CHAN_SOFT_TIMESTAMP(3),
};
- ext_channels = devm_kzalloc(hw->dev, sizeof(magn_channels),
- GFP_KERNEL);
+ ext_channels = devm_kcalloc(hw->dev, ARRAY_SIZE(magn_channels),
+ sizeof(*ext_channels), GFP_KERNEL);
if (!ext_channels)
return NULL;