mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array
@ 2026-09-28 12:57 Takashi Sakamoto
  2026-09-28 12:57 ` [PATCH 1/3] firewire: core: use kzalloc_flex() to allocate structure with quadlet array Takashi Sakamoto
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Takashi Sakamoto @ 2026-09-28 12:57 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel

Hi,

Some structures are defined with a trailing flexible array member to store
data. kmalloc_flex() and its variants are useful for allocating these
structures.

This series replaces kmalloc() with kzalloc_flex() where appropriate.

Takashi Sakamoto (3):
  firewire: core: use kzalloc_flex() to allocate structure with quadlet
    array
  firewire: cdev: use kzalloc_flex() to allocate structure with quadlet
    array
  firewire: cdev: use kzalloc_flex() to allocate structure with byte
    array

 drivers/firewire/core-cdev.c        | 11 ++++++-----
 drivers/firewire/core-transaction.c |  4 ++--
 2 files changed, 8 insertions(+), 7 deletions(-)


base-commit: a781263c292e7bda50812ba2347459e8ce9d778b
-- 
2.53.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] firewire: core: use kzalloc_flex() to allocate structure with quadlet array
  2026-09-28 12:57 [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array Takashi Sakamoto
@ 2026-09-28 12:57 ` Takashi Sakamoto
  2026-09-28 12:57 ` [PATCH 2/3] firewire: cdev: " Takashi Sakamoto
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Takashi Sakamoto @ 2026-09-28 12:57 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel

fw_core_handle_request() is now called in process context, so GFP_KERNEL
is available. The fw_request structure has a trailing flexible array
member of quadlets to store packet data. Use kzalloc_flex() to allocate
the structure together with storage for the flexible array member.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 drivers/firewire/core-transaction.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
index 7450eb0ac3cd..b4fccabb8fb2 100644
--- a/drivers/firewire/core-transaction.c
+++ b/drivers/firewire/core-transaction.c
@@ -894,8 +894,8 @@ static struct fw_request *allocate_request(struct fw_card *card,
 		return NULL;
 	}
 
-	request = kmalloc(sizeof(*request) + length, GFP_ATOMIC);
-	if (request == NULL)
+	request = kzalloc_flex(*request, data, DIV_ROUND_UP(length, sizeof(u32)));
+	if (!request)
 		return NULL;
 	kref_init(&request->kref);
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] firewire: cdev: use kzalloc_flex() to allocate structure with quadlet array
  2026-09-28 12:57 [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array Takashi Sakamoto
  2026-09-28 12:57 ` [PATCH 1/3] firewire: core: use kzalloc_flex() to allocate structure with quadlet array Takashi Sakamoto
@ 2026-09-28 12:57 ` Takashi Sakamoto
  2026-09-28 12:57 ` [PATCH 3/3] firewire: cdev: use kzalloc_flex() to allocate structure with byte array Takashi Sakamoto
  2026-09-28 22:57 ` [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array Takashi Sakamoto
  3 siblings, 0 replies; 5+ messages in thread
From: Takashi Sakamoto @ 2026-09-28 12:57 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel

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.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 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;
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] firewire: cdev: use kzalloc_flex() to allocate structure with byte array
  2026-09-28 12:57 [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array Takashi Sakamoto
  2026-09-28 12:57 ` [PATCH 1/3] firewire: core: use kzalloc_flex() to allocate structure with quadlet array Takashi Sakamoto
  2026-09-28 12:57 ` [PATCH 2/3] firewire: cdev: " Takashi Sakamoto
@ 2026-09-28 12:57 ` Takashi Sakamoto
  2026-09-28 22:57 ` [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array Takashi Sakamoto
  3 siblings, 0 replies; 5+ messages in thread
From: Takashi Sakamoto @ 2026-09-28 12:57 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel

Some event structures have a trailing flexible array member of bytes to
store event-specific data. Use kzalloc_flex() to allocate the structure
together with storage for the flexible array member.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 drivers/firewire/core-cdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index caabaaf99cb7..60067c5b1973 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1020,7 +1020,7 @@ static void iso_callback(struct fw_iso_context *context, u32 cycle,
 	struct client *client = data;
 	struct iso_interrupt_event *e;
 
-	e = kmalloc(sizeof(*e) + header_length, GFP_KERNEL);
+	e = kzalloc_flex(*e, interrupt.header, header_length);
 	if (e == NULL)
 		return;
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array
  2026-09-28 12:57 [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array Takashi Sakamoto
                   ` (2 preceding siblings ...)
  2026-09-28 12:57 ` [PATCH 3/3] firewire: cdev: use kzalloc_flex() to allocate structure with byte array Takashi Sakamoto
@ 2026-09-28 22:57 ` Takashi Sakamoto
  3 siblings, 0 replies; 5+ messages in thread
From: Takashi Sakamoto @ 2026-09-28 22:57 UTC (permalink / raw)
  To: linux1394-devel; +Cc: linux-kernel

On Mon, Sep 28, 2026 at 09:57:14PM +0900, Takashi Sakamoto wrote:
> Hi,
> 
> Some structures are defined with a trailing flexible array member to store
> data. kmalloc_flex() and its variants are useful for allocating these
> structures.
> 
> This series replaces kmalloc() with kzalloc_flex() where appropriate.
> 
> Takashi Sakamoto (3):
>   firewire: core: use kzalloc_flex() to allocate structure with quadlet
>     array
>   firewire: cdev: use kzalloc_flex() to allocate structure with quadlet
>     array
>   firewire: cdev: use kzalloc_flex() to allocate structure with byte
>     array
> 
>  drivers/firewire/core-cdev.c        | 11 ++++++-----
>  drivers/firewire/core-transaction.c |  4 ++--
>  2 files changed, 8 insertions(+), 7 deletions(-)

Applied to for-next branch.


Regards

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-28 22:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-28 12:57 [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array Takashi Sakamoto
2026-09-28 12:57 ` [PATCH 1/3] firewire: core: use kzalloc_flex() to allocate structure with quadlet array Takashi Sakamoto
2026-09-28 12:57 ` [PATCH 2/3] firewire: cdev: " Takashi Sakamoto
2026-09-28 12:57 ` [PATCH 3/3] firewire: cdev: use kzalloc_flex() to allocate structure with byte array Takashi Sakamoto
2026-09-28 22:57 ` [PATCH 0/3] firewire: core/cdev: use kzalloc_flex() to allocate structure with flexible array Takashi Sakamoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®