spi: axi-spi-engine: use struct_size() macro
authorDavid Lechner <dlechner@baylibre.com>
Mon, 4 Mar 2024 16:04:25 +0000 (10:04 -0600)
committerMark Brown <broonie@kernel.org>
Mon, 4 Mar 2024 17:44:00 +0000 (17:44 +0000)
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 <christophe.jaillet@wanadoo.fr>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://msgid.link/r/20240304-mainline-axi-spi-engine-small-cleanups-v2-3-5b14ed729a31@baylibre.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-axi-spi-engine.c

index a8f626165f44d95ca306a3ea3b502e4b06ddbd5d..7cc219d78551adbcd99e10e4d59f50653276cac1 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/module.h>
+#include <linux/overflow.h>
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 
@@ -502,15 +503,13 @@ static irqreturn_t spi_engine_irq(int irq, void *devid)
 static int spi_engine_optimize_message(struct spi_message *msg)
 {
        struct spi_engine_program p_dry, *p;
-       size_t size;
 
        spi_engine_precompile_message(msg);
 
        p_dry.length = 0;
        spi_engine_compile_message(msg, true, &p_dry);
 
-       size = sizeof(*p->instructions) * (p_dry.length + 1);
-       p = kzalloc(sizeof(*p) + size, GFP_KERNEL);
+       p = kzalloc(struct_size(p, instructions, p_dry.length + 1), GFP_KERNEL);
        if (!p)
                return -ENOMEM;