Skip to content

Commit 0f1a277

Browse files
committed
spi: axi-spi-engine: small cleanups
Merge series from David Lechner <[email protected]>: This series contains a few small cleanups to the axi-spi-engine driver, mostly suggested from previous reviews.
2 parents ee09bb7 + 5c70854 commit 0f1a277

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

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

Lines changed: 6 additions & 9 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

@@ -75,15 +76,13 @@
7576

7677
struct spi_engine_program {
7778
unsigned int length;
78-
uint16_t instructions[];
79+
uint16_t instructions[] __counted_by(length);
7980
};
8081

8182
/**
8283
* struct spi_engine_message_state - SPI engine per-message state
8384
*/
8485
struct spi_engine_message_state {
85-
/** @p: Instructions for executing this message. */
86-
struct spi_engine_program *p;
8786
/** @cmd_length: Number of elements in cmd_buf array. */
8887
unsigned cmd_length;
8988
/** @cmd_buf: Array of commands not yet written to CMD FIFO. */
@@ -117,9 +116,10 @@ struct spi_engine {
117116
static void spi_engine_program_add_cmd(struct spi_engine_program *p,
118117
bool dry, uint16_t cmd)
119118
{
120-
if (!dry)
121-
p->instructions[p->length] = cmd;
122119
p->length++;
120+
121+
if (!dry)
122+
p->instructions[p->length - 1] = cmd;
123123
}
124124

125125
static unsigned int spi_engine_get_config(struct spi_device *spi)
@@ -503,15 +503,13 @@ static irqreturn_t spi_engine_irq(int irq, void *devid)
503503
static int spi_engine_optimize_message(struct spi_message *msg)
504504
{
505505
struct spi_engine_program p_dry, *p;
506-
size_t size;
507506

508507
spi_engine_precompile_message(msg);
509508

510509
p_dry.length = 0;
511510
spi_engine_compile_message(msg, true, &p_dry);
512511

513-
size = sizeof(*p->instructions) * (p_dry.length + 1);
514-
p = kzalloc(sizeof(*p) + size, GFP_KERNEL);
512+
p = kzalloc(struct_size(p, instructions, p_dry.length + 1), GFP_KERNEL);
515513
if (!p)
516514
return -ENOMEM;
517515

@@ -543,7 +541,6 @@ static int spi_engine_transfer_one_message(struct spi_controller *host,
543541

544542
/* reinitialize message state for this transfer */
545543
memset(st, 0, sizeof(*st));
546-
st->p = p;
547544
st->cmd_buf = p->instructions;
548545
st->cmd_length = p->length;
549546
msg->state = st;

0 commit comments

Comments
 (0)