Commit 5c708541 authored by David Lechner's avatar David Lechner Committed by Mark Brown

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: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid Lechner <dlechner@baylibre.com>
Reviewed-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Link: https://msgid.link/r/20240304-mainline-axi-spi-engine-small-cleanups-v2-3-5b14ed729a31@baylibre.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent c8340ac1
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/overflow.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
...@@ -502,15 +503,13 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) ...@@ -502,15 +503,13 @@ static irqreturn_t spi_engine_irq(int irq, void *devid)
static int spi_engine_optimize_message(struct spi_message *msg) static int spi_engine_optimize_message(struct spi_message *msg)
{ {
struct spi_engine_program p_dry, *p; struct spi_engine_program p_dry, *p;
size_t size;
spi_engine_precompile_message(msg); spi_engine_precompile_message(msg);
p_dry.length = 0; p_dry.length = 0;
spi_engine_compile_message(msg, true, &p_dry); spi_engine_compile_message(msg, true, &p_dry);
size = sizeof(*p->instructions) * (p_dry.length + 1); p = kzalloc(struct_size(p, instructions, p_dry.length + 1), GFP_KERNEL);
p = kzalloc(sizeof(*p) + size, GFP_KERNEL);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment