[PATCH] ALSA: core: Fix signedness issue in info read callback
From: Sreeraj S Kurup
Date: Mon Nov 09 2026 - 03:10:06 EST
The read callback returns ssize_t, which allows it to return
either the number of bytes read or a negative error code.
However, snd_info_entry_read() stores the callback result in a
size_t variable. This converts negative error codes into large
unsigned values.
Use a separate ssize_t variable to store the callback result.
This preserves negative error codes and ensures that the file
position is updated only when the callback returns a positive
number of bytes.
This prevents callback errors from being incorrectly reported
as successful reads.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@xxxxxxxxx>
---
sound/core/info.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/sound/core/info.c b/sound/core/info.c
index c4d57d0809ad..35aaa8bd6d56 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -144,6 +144,7 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
struct snd_info_private_data *data = file->private_data;
struct snd_info_entry *entry = data->entry;
size_t size;
+ ssize_t ret;
loff_t pos;
pos = *offset;
@@ -153,11 +154,11 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
return 0;
size = entry->size - pos;
size = min(count, size);
- size = entry->c.ops->read(entry, data->file_private_data,
+ ret = entry->c.ops->read(entry, data->file_private_data,
file, buffer, size, pos);
- if ((ssize_t) size > 0)
- *offset = pos + size;
- return size;
+ if (ret > 0)
+ *offset = pos + ret;
+ return ret;
}
static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer,
--
2.55.0