Skip to content

Commit 5c70854

Browse files
dlechbroonie
authored andcommitted
spi: axi-spi-engine: use struct_size() macro
This makes use of the struct_size() macro to calculate the size of the struct axi_spi_engine when allocating it. Suggested-by: Christophe JAILLET <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: David Lechner <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Link: https://msgid.link/r/20240304-mainline-axi-spi-engine-small-cleanups-v2-3-5b14ed729a31@baylibre.com Signed-off-by: Mark Brown <[email protected]>
1 parent c8340ac commit 5c70854

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/spi/spi-axi-spi-engine.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/io.h>
1313
#include <linux/of.h>
1414
#include <linux/module.h>
15+
#include <linux/overflow.h>
1516
#include <linux/platform_device.h>
1617
#include <linux/spi/spi.h>
1718

@@ -502,15 +503,13 @@ static irqreturn_t spi_engine_irq(int irq, void *devid)
502503
static int spi_engine_optimize_message(struct spi_message *msg)
503504
{
504505
struct spi_engine_program p_dry, *p;
505-
size_t size;
506506

507507
spi_engine_precompile_message(msg);
508508

509509
p_dry.length = 0;
510510
spi_engine_compile_message(msg, true, &p_dry);
511511

512-
size = sizeof(*p->instructions) * (p_dry.length + 1);
513-
p = kzalloc(sizeof(*p) + size, GFP_KERNEL);
512+
p = kzalloc(struct_size(p, instructions, p_dry.length + 1), GFP_KERNEL);
514513
if (!p)
515514
return -ENOMEM;
516515

0 commit comments

Comments
 (0)