Skip to content

Commit c968a85

Browse files
Tomasz BursztykaAnas Nashif
authored andcommitted
drivers/spi: Properly check for rx/tx and buffering on
Current buffers might be configured to skip data, thus only len will be set, buf will be NULL. Buffer should be used if only len is > 0 and buffer is valid as well. tx/rx are "on" if len is > 0 tx/rx buf should be touched if only len is > 0 _and_ buf != NULL. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent 6fbd861 commit c968a85

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

drivers/spi/spi_context.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ void spi_context_update_tx(struct spi_context *ctx, u8_t dfs, u32_t len)
227227
static ALWAYS_INLINE
228228
bool spi_context_tx_on(struct spi_context *ctx)
229229
{
230-
return !!(ctx->tx_buf || ctx->tx_len);
230+
return !!(ctx->tx_len);
231+
}
232+
233+
static ALWAYS_INLINE
234+
bool spi_context_tx_buf_on(struct spi_context *ctx)
235+
{
236+
return !!(ctx->tx_buf && ctx->tx_len);
231237
}
232238

233239
static ALWAYS_INLINE
@@ -263,7 +269,13 @@ void spi_context_update_rx(struct spi_context *ctx, u8_t dfs, u32_t len)
263269
static ALWAYS_INLINE
264270
bool spi_context_rx_on(struct spi_context *ctx)
265271
{
266-
return !!(ctx->rx_buf || ctx->rx_len);
272+
return !!(ctx->rx_len);
273+
}
274+
275+
static ALWAYS_INLINE
276+
bool spi_context_rx_buf_on(struct spi_context *ctx)
277+
{
278+
return !!(ctx->rx_buf && ctx->rx_len);
267279
}
268280

269281
static inline size_t spi_context_longest_current_buf(struct spi_context *ctx)

drivers/spi/spi_dw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static void push_data(struct device *dev)
9696
}
9797

9898
while (f_tx) {
99-
if (spi_context_tx_on(&spi->ctx)) {
99+
if (spi_context_tx_buf_on(&spi->ctx)) {
100100
switch (spi->dfs) {
101101
case 1:
102102
data = UNALIGNED_GET((u8_t *)
@@ -155,7 +155,7 @@ static void pull_data(struct device *dev)
155155

156156
DBG_COUNTER_INC();
157157

158-
if (spi_context_rx_on(&spi->ctx)) {
158+
if (spi_context_rx_buf_on(&spi->ctx)) {
159159
switch (spi->dfs) {
160160
case 1:
161161
UNALIGNED_PUT(data, (u8_t *)spi->ctx.rx_buf);

0 commit comments

Comments
 (0)