Skip to content

Commit 500e54d

Browse files
nehebwesteri
authored andcommitted
thunderbolt: dma_port: kmalloc_array + kzalloc to flex
Use a single allocation with a flexible array member. Simplifies allocation and freeing. Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
1 parent f791145 commit 500e54d

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

drivers/thunderbolt/dma_port.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct tb_dma_port {
5555
struct tb_switch *sw;
5656
u8 port;
5757
u32 base;
58-
u8 *buf;
58+
u8 buf[];
5959
};
6060

6161
/*
@@ -209,16 +209,10 @@ struct tb_dma_port *dma_port_alloc(struct tb_switch *sw)
209209
if (port < 0)
210210
return NULL;
211211

212-
dma = kzalloc_obj(*dma);
212+
dma = kzalloc_flex(*dma, buf, MAIL_DATA_DWORDS);
213213
if (!dma)
214214
return NULL;
215215

216-
dma->buf = kmalloc_array(MAIL_DATA_DWORDS, sizeof(u32), GFP_KERNEL);
217-
if (!dma->buf) {
218-
kfree(dma);
219-
return NULL;
220-
}
221-
222216
dma->sw = sw;
223217
dma->port = port;
224218
dma->base = DMA_PORT_CAP;
@@ -232,10 +226,7 @@ struct tb_dma_port *dma_port_alloc(struct tb_switch *sw)
232226
*/
233227
void dma_port_free(struct tb_dma_port *dma)
234228
{
235-
if (dma) {
236-
kfree(dma->buf);
237-
kfree(dma);
238-
}
229+
kfree(dma);
239230
}
240231

241232
static int dma_port_wait_for_completion(struct tb_dma_port *dma,

0 commit comments

Comments
 (0)