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/firewire/core-cdev.c | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
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/firewire/core-cdev.c')
| -rw-r--r-- | drivers/firewire/core-cdev.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 9e964fdd175c..6d1a59e33d2e 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -291,7 +291,7 @@ static int fw_device_op_open(struct inode *inode, struct file *file) return -ENODEV; } - client = kzalloc(sizeof(*client), GFP_KERNEL); + client = kzalloc_obj(*client, GFP_KERNEL); if (client == NULL) { fw_device_put(device); return -ENOMEM; @@ -412,7 +412,7 @@ static void queue_bus_reset_event(struct client *client) struct client_resource *resource; unsigned long index; - e = kzalloc(sizeof(*e), GFP_KERNEL); + e = kzalloc_obj(*e, GFP_KERNEL); if (e == NULL) return; @@ -745,8 +745,8 @@ static void handle_request(struct fw_card *card, struct fw_request *request, if (is_fcp) fw_request_get(request); - r = kmalloc(sizeof(*r), GFP_ATOMIC); - e = kmalloc(sizeof(*e), GFP_ATOMIC); + r = kmalloc_obj(*r, GFP_ATOMIC); + e = kmalloc_obj(*e, GFP_ATOMIC); if (r == NULL || e == NULL) goto failed; @@ -837,7 +837,7 @@ static int ioctl_allocate(struct client *client, union ioctl_arg *arg) struct fw_address_region region; int ret; - r = kmalloc(sizeof(*r), GFP_KERNEL); + r = kmalloc_obj(*r, GFP_KERNEL); if (r == NULL) return -ENOMEM; @@ -941,7 +941,7 @@ static int ioctl_add_descriptor(struct client *client, union ioctl_arg *arg) if (a->length > 256) return -EINVAL; - r = kmalloc(struct_size(r, data, a->length), GFP_KERNEL); + r = kmalloc_flex(*r, data, a->length, GFP_KERNEL); if (r == NULL) return -ENOMEM; @@ -1006,7 +1006,7 @@ static void iso_mc_callback(struct fw_iso_context *context, struct client *client = data; struct iso_interrupt_mc_event *e; - e = kmalloc(sizeof(*e), GFP_KERNEL); + e = kmalloc_obj(*e, GFP_KERNEL); if (e == NULL) return; @@ -1409,9 +1409,9 @@ static int init_iso_resource(struct client *client, request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL) return -EINVAL; - r = kmalloc(sizeof(*r), GFP_KERNEL); - e1 = kmalloc(sizeof(*e1), GFP_KERNEL); - e2 = kmalloc(sizeof(*e2), GFP_KERNEL); + r = kmalloc_obj(*r, GFP_KERNEL); + e1 = kmalloc_obj(*e1, GFP_KERNEL); + e2 = kmalloc_obj(*e2, GFP_KERNEL); if (r == NULL || e1 == NULL || e2 == NULL) { ret = -ENOMEM; goto fail; |
