|
12 | 12 | #include <linux/io.h>
|
13 | 13 | #include <linux/of.h>
|
14 | 14 | #include <linux/module.h>
|
| 15 | +#include <linux/overflow.h> |
15 | 16 | #include <linux/platform_device.h>
|
16 | 17 | #include <linux/spi/spi.h>
|
17 | 18 |
|
|
75 | 76 |
|
76 | 77 | struct spi_engine_program {
|
77 | 78 | unsigned int length;
|
78 |
| - uint16_t instructions[]; |
| 79 | + uint16_t instructions[] __counted_by(length); |
79 | 80 | };
|
80 | 81 |
|
81 | 82 | /**
|
82 | 83 | * struct spi_engine_message_state - SPI engine per-message state
|
83 | 84 | */
|
84 | 85 | struct spi_engine_message_state {
|
85 |
| - /** @p: Instructions for executing this message. */ |
86 |
| - struct spi_engine_program *p; |
87 | 86 | /** @cmd_length: Number of elements in cmd_buf array. */
|
88 | 87 | unsigned cmd_length;
|
89 | 88 | /** @cmd_buf: Array of commands not yet written to CMD FIFO. */
|
@@ -117,9 +116,10 @@ struct spi_engine {
|
117 | 116 | static void spi_engine_program_add_cmd(struct spi_engine_program *p,
|
118 | 117 | bool dry, uint16_t cmd)
|
119 | 118 | {
|
120 |
| - if (!dry) |
121 |
| - p->instructions[p->length] = cmd; |
122 | 119 | p->length++;
|
| 120 | + |
| 121 | + if (!dry) |
| 122 | + p->instructions[p->length - 1] = cmd; |
123 | 123 | }
|
124 | 124 |
|
125 | 125 | 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)
|
503 | 503 | static int spi_engine_optimize_message(struct spi_message *msg)
|
504 | 504 | {
|
505 | 505 | struct spi_engine_program p_dry, *p;
|
506 |
| - size_t size; |
507 | 506 |
|
508 | 507 | spi_engine_precompile_message(msg);
|
509 | 508 |
|
510 | 509 | p_dry.length = 0;
|
511 | 510 | spi_engine_compile_message(msg, true, &p_dry);
|
512 | 511 |
|
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); |
515 | 513 | if (!p)
|
516 | 514 | return -ENOMEM;
|
517 | 515 |
|
@@ -543,7 +541,6 @@ static int spi_engine_transfer_one_message(struct spi_controller *host,
|
543 | 541 |
|
544 | 542 | /* reinitialize message state for this transfer */
|
545 | 543 | memset(st, 0, sizeof(*st));
|
546 |
| - st->p = p; |
547 | 544 | st->cmd_buf = p->instructions;
|
548 | 545 | st->cmd_length = p->length;
|
549 | 546 | msg->state = st;
|
|
0 commit comments