Skip to content

sys: ring_buffer: fix possible ring_buf_put_claim() wrong size #88961

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/zephyr/sys/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ static inline uint32_t ring_buf_put_claim(struct ring_buf *buf,
uint8_t **data,
uint32_t size)
{
uint32_t space = ring_buf_space_get(buf);
return ring_buf_area_claim(buf, &buf->put, data,
MIN(size, ring_buf_space_get(buf)));
MIN(size, space));
}

/**
Expand Down Expand Up @@ -385,8 +386,9 @@ static inline uint32_t ring_buf_get_claim(struct ring_buf *buf,
uint8_t **data,
uint32_t size)
{
uint32_t buf_size = ring_buf_size_get(buf);
return ring_buf_area_claim(buf, &buf->get, data,
MIN(size, ring_buf_size_get(buf)));
MIN(size, buf_size));
}

/**
Expand Down