lib: os: spsc_pbuf: Fix miscalculation in the allocation

Wrong value was used for free space calculation. Updating test which
previously was hiding this bug.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2022-08-22 14:25:46 +02:00 committed by Fabio Baltieri
parent f02c528aab
commit 4b5ff413f5
2 changed files with 5 additions and 5 deletions

View file

@ -169,7 +169,7 @@ int spsc_pbuf_alloc(struct spsc_pbuf *pb, uint16_t len, char **buf)
/* Packet will fit at the end */
free_space = remaining - ((rd_idx > 0) ? 0 : sizeof(uint32_t));
} else {
if (rd_idx > remaining) {
if (rd_idx > space) {
/* Padding must be added. */
data_loc[wr_idx] = PADDING_MARK;
__sync_synchronize();

View file

@ -305,7 +305,7 @@ ZTEST(test_spsc_pbuf, test_0cpy_corner2)
pb = spsc_pbuf_init(buffer, sizeof(buffer), 0);
capacity = spsc_pbuf_capacity(pb);
/* Commit 5 byte packet. */
/* Commit 16 byte packet. */
len1 = 16;
PACKET_WRITE(pb, len1, len1, 0, len1);
@ -349,10 +349,10 @@ ZTEST(test_spsc_pbuf, test_largest_alloc)
PACKET_WRITE(pb, len1, len1, 0, len1);
PACKET_CONSUME(pb, len1, 0);
len2 = capacity - ROUND_UP(len1, sizeof(uint32_t)) - 2 * sizeof(uint32_t) - 10;
len2 = capacity - TLEN(len1) - TLEN(10);
PACKET_WRITE(pb, len2, len2, 1, len2);
PACKET_WRITE(pb, SPSC_PBUF_MAX_LEN, 0, 1, 8);
PACKET_WRITE(pb, SPSC_PBUF_MAX_LEN, 0, 1, 12);
PACKET_WRITE(pb, SPSC_PBUF_MAX_LEN - 1, 0, 1, 12);
@ -363,7 +363,7 @@ ZTEST(test_spsc_pbuf, test_largest_alloc)
PACKET_WRITE(pb, len1, len1, 0, len1);
PACKET_CONSUME(pb, len1, 0);
len2 = capacity - ROUND_UP(len1, sizeof(uint32_t)) - 2 * sizeof(uint16_t) - 8;
len2 = capacity - TLEN(len1) - TLEN(12);
PACKET_WRITE(pb, len2, len2, 1, len2);
PACKET_WRITE(pb, SPSC_PBUF_MAX_LEN - 1, 0, 1, 12);