Skip to content

Commit c8340ac

Browse files
dlechbroonie
authored andcommitted
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á <[email protected]> Signed-off-by: David Lechner <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://msgid.link/r/20240304-mainline-axi-spi-engine-small-cleanups-v2-2-5b14ed729a31@baylibre.com Signed-off-by: Mark Brown <[email protected]>
1 parent 69d54ee commit c8340ac

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
struct spi_engine_program {
7777
unsigned int length;
78-
uint16_t instructions[];
78+
uint16_t instructions[] __counted_by(length);
7979
};
8080

8181
/**
@@ -115,9 +115,10 @@ struct spi_engine {
115115
static void spi_engine_program_add_cmd(struct spi_engine_program *p,
116116
bool dry, uint16_t cmd)
117117
{
118-
if (!dry)
119-
p->instructions[p->length] = cmd;
120118
p->length++;
119+
120+
if (!dry)
121+
p->instructions[p->length - 1] = cmd;
121122
}
122123

123124
static unsigned int spi_engine_get_config(struct spi_device *spi)

0 commit comments

Comments
 (0)