From: Rosen Penev <rosenp@gmail.com>
To: linux-usb@vger.kernel.org
Cc: Andreas Noever <andreas.noever@gmail.com>,
Mika Westerberg <westeri@kernel.org>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] thunderbolt: dma_port: kmalloc_array + kzalloc to flex
Date: Fri, 13 Mar 2026 14:41:37 -0700 [thread overview]
Message-ID: <20260313214137.4257-1-rosenp@gmail.com> (raw)
Use a single allocation with a flexible array member. Simplifies
allocation and freeing.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/thunderbolt/dma_port.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/drivers/thunderbolt/dma_port.c b/drivers/thunderbolt/dma_port.c
index 334fefe21255..c7c2942fa7be 100644
--- a/drivers/thunderbolt/dma_port.c
+++ b/drivers/thunderbolt/dma_port.c
@@ -55,7 +55,7 @@ struct tb_dma_port {
struct tb_switch *sw;
u8 port;
u32 base;
- u8 *buf;
+ u8 buf[];
};
/*
@@ -209,16 +209,10 @@ struct tb_dma_port *dma_port_alloc(struct tb_switch *sw)
if (port < 0)
return NULL;
- dma = kzalloc_obj(*dma);
+ dma = kzalloc_flex(*dma, buf, MAIL_DATA_DWORDS);
if (!dma)
return NULL;
- dma->buf = kmalloc_array(MAIL_DATA_DWORDS, sizeof(u32), GFP_KERNEL);
- if (!dma->buf) {
- kfree(dma);
- return NULL;
- }
-
dma->sw = sw;
dma->port = port;
dma->base = DMA_PORT_CAP;
@@ -232,10 +226,7 @@ struct tb_dma_port *dma_port_alloc(struct tb_switch *sw)
*/
void dma_port_free(struct tb_dma_port *dma)
{
- if (dma) {
- kfree(dma->buf);
- kfree(dma);
- }
+ kfree(dma);
}
static int dma_port_wait_for_completion(struct tb_dma_port *dma,
--
2.53.0
next reply other threads:[~2026-03-13 21:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 21:41 Rosen Penev [this message]
2026-03-18 13:38 ` [PATCH] thunderbolt: dma_port: kmalloc_array + kzalloc to flex Mika Westerberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260313214137.4257-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=westeri@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox