diff options
author | David Lechner <dlechner@baylibre.com> | 2024-03-04 17:04:24 +0100 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2024-03-04 18:43:59 +0100 |
commit | c8340ac1015471ec5af234beff535efe15f382e9 (patch) | |
tree | 353202f73865ba3f9e3f71d872c61564686e9fce /drivers/spi/spi-axi-spi-engine.c | |
parent | spi: axi-spi-engine: remove p from struct spi_engine_message_state (diff) | |
download | linux-c8340ac1015471ec5af234beff535efe15f382e9.tar.xz linux-c8340ac1015471ec5af234beff535efe15f382e9.zip |
spi: axi-spi-engine: use __counted_by() attribute
This adds the __counted_by() attribute to the flex array at the end of
struct spi_engine_program in the AXI SPI Engine controller driver.
The assignment of the length field has to be reordered to be before
the access to the flex array in order to avoid potential compiler
warnings/errors due to adding the __counted_by() attribute.
Suggested-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://msgid.link/r/20240304-mainline-axi-spi-engine-small-cleanups-v2-2-5b14ed729a31@baylibre.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi/spi-axi-spi-engine.c')
-rw-r--r-- | drivers/spi/spi-axi-spi-engine.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index d89f75170c9e..a8f626165f44 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -75,7 +75,7 @@ struct spi_engine_program { unsigned int length; - uint16_t instructions[]; + uint16_t instructions[] __counted_by(length); }; /** @@ -115,9 +115,10 @@ struct spi_engine { static void spi_engine_program_add_cmd(struct spi_engine_program *p, bool dry, uint16_t cmd) { - if (!dry) - p->instructions[p->length] = cmd; p->length++; + + if (!dry) + p->instructions[p->length - 1] = cmd; } static unsigned int spi_engine_get_config(struct spi_device *spi) |