diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-21 10:49:23 +0300 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 12:02:28 +0300 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/block/loop.c | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | linux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.xz | |
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/block/loop.c')
| -rw-r--r-- | drivers/block/loop.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 98789a5297f2..949bb4adc4bf 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -355,8 +355,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, if (rq->bio != rq->biotail) { - bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), - GFP_NOIO); + bvec = kmalloc_objs(struct bio_vec, nr_bvec, GFP_NOIO); if (!bvec) return -EIO; cmd->bvec = bvec; @@ -823,7 +822,7 @@ static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd) if (worker) goto queue_work; - worker = kzalloc(sizeof(struct loop_worker), GFP_NOWAIT); + worker = kzalloc_obj(struct loop_worker, GFP_NOWAIT); /* * In the event we cannot allocate a worker, just queue on the * rootcg worker and issue the I/O as the rootcg @@ -2010,7 +2009,7 @@ static int loop_add(int i) int err; err = -ENOMEM; - lo = kzalloc(sizeof(*lo), GFP_KERNEL); + lo = kzalloc_obj(*lo, GFP_KERNEL); if (!lo) goto out; lo->worker_tree = RB_ROOT; |
