From: Kees Cook <[email protected]>

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.)

The assigned type is "struct iio_chan_spec *", but the converted
allocation type would be "const struct iio_chan_spec *", as the size was
taken from "*indio_dev->channels", and "indio_dev->channels" points to
const. As there is no general way to remove const qualifiers, take the
size from the assignment target instead. No change in allocation size
results.

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
drivers/iio/adc/ad7173.o

Assisted-by: LLM coccinelle
Signed-off-by: Kees Cook <[email protected]>
---
Cc: "Nuno Sá" <[email protected]>
Cc: Michael Hennerich <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: David Lechner <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
---
 drivers/iio/adc/ad7173.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
index eb47175a0528..fdd24f3ec1de 100644
--- a/drivers/iio/adc/ad7173.c
+++ b/drivers/iio/adc/ad7173.c
@@ -1801,7 +1801,7 @@ static int ad7173_fw_parse_channel_config(struct iio_dev 
*indio_dev)
        indio_dev->num_channels = num_channels;
        st->num_channels = num_channels;
 
-       chan_arr = devm_kcalloc(dev, sizeof(*indio_dev->channels),
+       chan_arr = devm_kcalloc(dev, sizeof(*chan_arr),
                                st->num_channels, GFP_KERNEL);
        if (!chan_arr)
                return -ENOMEM;
-- 
2.34.1


Reply via email to