From b1790574d374aa7d90aa8200eae1bc45e03c66c8 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 28 Sep 2026 21:57:16 +0900 Subject: [PATCH] firewire: cdev: use kzalloc_flex() to allocate structure with quadlet array Some event structures have a trailing flexible array member of quadlets to store event-specific data. Use kzalloc_flex() to allocate the structure together with storage for the flexible array member. Link: https://lore.kernel.org/r/20260928125718.50974-3-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 9c204bd7af74..caabaaf99cb7 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -683,8 +683,8 @@ static int init_request(struct client *client, request->length < 4) return -EINVAL; - e = kmalloc(sizeof(*e) + request->length, GFP_KERNEL); - if (e == NULL) + e = kzalloc_flex(*e, rsp.with_tstamp.data, DIV_ROUND_UP(request->length, sizeof(u32))); + if (!e) return -ENOMEM; e->client = client; @@ -1696,7 +1696,7 @@ static int ioctl_send_phy_packet(struct client *client, union ioctl_arg *arg) if (!client->device->is_local) return -ENOSYS; - e = kzalloc(sizeof(*e) + sizeof(a->data), GFP_KERNEL); + e = kzalloc_flex(*e, phy_packet.with_tstamp.data, ARRAY_SIZE(a->data)); if (e == NULL) return -ENOMEM; @@ -1762,7 +1762,8 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p) if (client->device->card != card) continue; - struct inbound_phy_packet_event *e = kmalloc(sizeof(*e) + 8, GFP_KERNEL); + struct inbound_phy_packet_event *e = + kzalloc_flex(*e, phy_packet.with_tstamp.data, 2); if (!e) break;