Skip to content

drivers/spi: Properly check for rx/tx and buffering on #5785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2018

Conversation

tbursztyka
Copy link
Collaborator

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]

@codecov-io
Copy link

codecov-io commented Jan 23, 2018

Codecov Report

Merging #5785 into master will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5785      +/-   ##
==========================================
- Coverage   54.37%   54.32%   -0.06%     
==========================================
  Files         457      457              
  Lines       43298    43298              
  Branches     8302     8302              
==========================================
- Hits        23545    23521      -24     
- Misses      19612    19638      +26     
+ Partials      141      139       -2
Impacted Files Coverage Δ
...sts/net/ieee802154/l2/src/ieee802154_fake_driver.c 74.35% <0%> (-15.39%) ⬇️
include/net/net_ip.h 67.36% <0%> (-4.87%) ⬇️
subsys/net/ip/6lo.c 38.73% <0%> (-2.79%) ⬇️
arch/posix/core/posix_core.c 85.34% <0%> (-1.73%) ⬇️
arch/posix/soc/inf_clock/soc.c 66.66% <0%> (+3.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1675bf...f0ee1d3. Read the comment docs.

Copy link
Collaborator

@ydamigos ydamigos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

static ALWAYS_INLINE
bool spi_context_rx_buf_on(struct spi_context *ctx)
{
return !!(ctx->rx_buf && ctx->rx_len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tbursztyka this might break the stm32 driver. Inside the shift-next-byte loop, the stm32 does the following:

data = read byte
if spi_context_rx_on(...) {
   *ctx.rx_buf = data
   spi_context_update_rx(...)
}

With this change, the above code will fail when rx_buf.buf = NULL and rx_buf.len > 0.

WDYT about documenting the spi_context API then we can go through and fix the current users?

Copy link
Collaborator

@ydamigos ydamigos Jan 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already pushed a commit to fix it in PR #5413.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

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]>
@nashif nashif merged commit c968a85 into zephyrproject-rtos:master Jan 30, 2018
@tbursztyka tbursztyka deleted the spi_context_fix branch February 14, 2018 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants