Skip to content

Commit

Permalink
xrun: storage: fix xrun_file_read_debounce() to return read bytes
Browse files Browse the repository at this point in the history
The xrun_file_read_debounce() should work the same way as fs_read() and so
return number of read bytes on success. A returned value may be lower than
size if there were fewer bytes available than requested.

Hence fix xrun_file_read_debounce() to follow fs_read() approach.

Signed-off-by: Grygorii Strashko <[email protected]>
Acked-by: Dmytro Firsov <[email protected]>
Tested-by: Oleksandr Grytsov <[email protected]>
  • Loading branch information
Grygorii Strashko authored and firscity committed Jul 23, 2024
1 parent 4ddb65c commit bab9c3b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions xrun/src/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ static uint8_t debounce_buf[KB(CONFIG_XRUN_STORAGE_DMA_DEBOUNCE)]
__aligned(CONFIG_SDHC_BUFFER_ALIGNMENT) __nocache;
static K_MUTEX_DEFINE(debounce_lock);

static int xrun_file_read_debounce(struct fs_file_t *file, uint8_t *buf, size_t read_size)
static ssize_t xrun_file_read_debounce(struct fs_file_t *file, uint8_t *buf, size_t read_size)
{
ssize_t read;
size_t count;
int ret = 0;
ssize_t ret = 0;

k_mutex_lock(&debounce_lock, K_FOREVER);

Expand All @@ -43,10 +43,14 @@ static int xrun_file_read_debounce(struct fs_file_t *file, uint8_t *buf, size_t
LOG_DBG("file count %zd read %zd", count, read);
count -= read;
buf += read;
if (count && read < sizeof(debounce_buf)) {
ret = read_size - count;
break;
}
}

k_mutex_unlock(&debounce_lock);
return ret;
return count ? ret : read_size;
}
#endif /* CONFIG_XRUN_STORAGE_DMA_DEBOUNCE */

Expand Down

0 comments on commit bab9c3b

Please sign in to comment.