Skip to content

Commit

Permalink
drivers: rtio: bugfix
Browse files Browse the repository at this point in the history
fixes the following:
- If a read SQE generates a CQE with an error before a buffer
has been allocated,
the flags of the sqe are not correctly translated into cqe flags.
- rtio_cqe_get_mempool_buffer(...) sets the *buff
to a non-zero value, even if no buffer is assigned

Signed-off-by: Florian Weber <[email protected]>
  • Loading branch information
FlorianWeber1018 authored and kartben committed Jan 13, 2025
1 parent f039ad5 commit b4667e0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions include/zephyr/rtio/rtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,10 +1137,14 @@ static inline uint32_t rtio_cqe_compute_flags(struct rtio_iodev_sqe *iodev_sqe)
if (iodev_sqe->sqe.op == RTIO_OP_RX && iodev_sqe->sqe.flags & RTIO_SQE_MEMPOOL_BUFFER) {
struct rtio *r = iodev_sqe->r;
struct sys_mem_blocks *mem_pool = r->block_pool;
int blk_index = (iodev_sqe->sqe.rx.buf - mem_pool->buffer) >>
mem_pool->info.blk_sz_shift;
int blk_count = iodev_sqe->sqe.rx.buf_len >> mem_pool->info.blk_sz_shift;
unsigned int blk_index = 0;
unsigned int blk_count = 0;

if (iodev_sqe->sqe.rx.buf) {
blk_index = (iodev_sqe->sqe.rx.buf - mem_pool->buffer) >>
mem_pool->info.blk_sz_shift;
blk_count = iodev_sqe->sqe.rx.buf_len >> mem_pool->info.blk_sz_shift;
}
flags = RTIO_CQE_FLAG_PREP_MEMPOOL(blk_index, blk_count);
}
#else
Expand Down Expand Up @@ -1173,15 +1177,21 @@ static inline int z_impl_rtio_cqe_get_mempool_buffer(const struct rtio *r, struc
{
#ifdef CONFIG_RTIO_SYS_MEM_BLOCKS
if (RTIO_CQE_FLAG_GET(cqe->flags) == RTIO_CQE_FLAG_MEMPOOL_BUFFER) {
int blk_idx = RTIO_CQE_FLAG_MEMPOOL_GET_BLK_IDX(cqe->flags);
int blk_count = RTIO_CQE_FLAG_MEMPOOL_GET_BLK_CNT(cqe->flags);
unsigned int blk_idx = RTIO_CQE_FLAG_MEMPOOL_GET_BLK_IDX(cqe->flags);
unsigned int blk_count = RTIO_CQE_FLAG_MEMPOOL_GET_BLK_CNT(cqe->flags);
uint32_t blk_size = rtio_mempool_block_size(r);

*buff = r->block_pool->buffer + blk_idx * blk_size;
*buff_len = blk_count * blk_size;
__ASSERT_NO_MSG(*buff >= r->block_pool->buffer);
__ASSERT_NO_MSG(*buff <

if (blk_count > 0) {
*buff = r->block_pool->buffer + blk_idx * blk_size;

__ASSERT_NO_MSG(*buff >= r->block_pool->buffer);
__ASSERT_NO_MSG(*buff <
r->block_pool->buffer + blk_size * r->block_pool->info.num_blocks);
} else {
*buff = NULL;
}
return 0;
}
return -EINVAL;
Expand Down

0 comments on commit b4667e0

Please sign in to comment.