diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/iio/buffer | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/iio/buffer')
| -rw-r--r-- | drivers/iio/buffer/industrialio-buffer-cb.c | 2 | ||||
| -rw-r--r-- | drivers/iio/buffer/industrialio-buffer-dma.c | 2 | ||||
| -rw-r--r-- | drivers/iio/buffer/industrialio-buffer-dmaengine.c | 2 | ||||
| -rw-r--r-- | drivers/iio/buffer/industrialio-hw-consumer.c | 4 | ||||
| -rw-r--r-- | drivers/iio/buffer/kfifo_buf.c | 2 |
5 files changed, 6 insertions, 6 deletions
diff --git a/drivers/iio/buffer/industrialio-buffer-cb.c b/drivers/iio/buffer/industrialio-buffer-cb.c index f4ebff968493..7a251b030b7e 100644 --- a/drivers/iio/buffer/industrialio-buffer-cb.c +++ b/drivers/iio/buffer/industrialio-buffer-cb.c @@ -60,7 +60,7 @@ struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, return ERR_PTR(-EINVAL); } - cb_buff = kzalloc(sizeof(*cb_buff), GFP_KERNEL); + cb_buff = kzalloc_obj(*cb_buff, GFP_KERNEL); if (cb_buff == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/iio/buffer/industrialio-buffer-dma.c b/drivers/iio/buffer/industrialio-buffer-dma.c index 1c94b334f987..2425e1113a7d 100644 --- a/drivers/iio/buffer/industrialio-buffer-dma.c +++ b/drivers/iio/buffer/industrialio-buffer-dma.c @@ -174,7 +174,7 @@ iio_dma_buffer_alloc_block(struct iio_dma_buffer_queue *queue, size_t size, bool fileio) { struct iio_dma_buffer_block *block __free(kfree) = - kzalloc(sizeof(*block), GFP_KERNEL); + kzalloc_obj(*block, GFP_KERNEL); if (!block) return NULL; diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c index 0d3454f4adb0..23b4ac7cca9c 100644 --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c @@ -224,7 +224,7 @@ static struct iio_buffer *iio_dmaengine_buffer_alloc(struct dma_chan *chan) if (ret < 0) return ERR_PTR(ret); - dmaengine_buffer = kzalloc(sizeof(*dmaengine_buffer), GFP_KERNEL); + dmaengine_buffer = kzalloc_obj(*dmaengine_buffer, GFP_KERNEL); if (!dmaengine_buffer) return ERR_PTR(-ENOMEM); diff --git a/drivers/iio/buffer/industrialio-hw-consumer.c b/drivers/iio/buffer/industrialio-hw-consumer.c index 526b2a8d725d..9745b3bd4ac7 100644 --- a/drivers/iio/buffer/industrialio-hw-consumer.c +++ b/drivers/iio/buffer/industrialio-hw-consumer.c @@ -60,7 +60,7 @@ static struct hw_consumer_buffer *iio_hw_consumer_get_buffer( return buf; } - buf = kzalloc(struct_size(buf, scan_mask, mask_longs), GFP_KERNEL); + buf = kzalloc_flex(*buf, scan_mask, mask_longs, GFP_KERNEL); if (!buf) return NULL; @@ -87,7 +87,7 @@ struct iio_hw_consumer *iio_hw_consumer_alloc(struct device *dev) struct iio_channel *chan; int ret; - hwc = kzalloc(sizeof(*hwc), GFP_KERNEL); + hwc = kzalloc_obj(*hwc, GFP_KERNEL); if (!hwc) return ERR_PTR(-ENOMEM); diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c index 38034c8bcc04..73e2cd7e7313 100644 --- a/drivers/iio/buffer/kfifo_buf.c +++ b/drivers/iio/buffer/kfifo_buf.c @@ -204,7 +204,7 @@ struct iio_buffer *iio_kfifo_allocate(void) { struct iio_kfifo *kf; - kf = kzalloc(sizeof(*kf), GFP_KERNEL); + kf = kzalloc_obj(*kf, GFP_KERNEL); if (!kf) return NULL; |
