Skip to contentSkip to conversation

xen/xenbus: fix return type in xenbus_file_read()

PATCH Applied Dan Carpenter 3 participants 3 messages Aug 4, 2022 – Aug 14, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/xenbus: fix return type in xenbus_file_read()

This code tries to store -EFAULT in an unsigned int. The xenbus_file_read() function returns type ssize_t so the negative value is returned as a positive value to the user.

This change forces another change to the min() macro. Originally, the min() macro used "unsigned" type which checkpatch complains about. Also unsigned type would break if "len" were not capped at MAX_RW_COUNT. Use size_t for the min(). (No effect on runtime for the min_t() change).

Fixes 2fb3683e7b16 ("xen: Add xenbus device driver")
---
 drivers/xen/xenbus/xenbus_dev_frontend.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/xenbus/xenbus_dev_frontend.c +2 -2
index 597af455a522..0792fda49a15 100644
@@ -128,7 +128,7 @@ static ssize_t xenbus_file_read(struct file *filp,
 {
 	struct xenbus_file_priv *u = filp->private_data;
 	struct read_buffer *rb;
-	unsigned i;
+	ssize_t i;
 	int ret;
 
 	mutex_lock(&u->reply_mutex);
@@ -148,7 +148,7 @@ static ssize_t xenbus_file_read(struct file *filp,
 	rb = list_entry(u->read_buffers.next, struct read_buffer, list);
 	i = 0;
 	while (i < len) {
-		unsigned sz = min((unsigned)len - i, rb->len - rb->cons);
+		size_t sz = min_t(size_t, len - i, rb->len - rb->cons);
 
 		ret = copy_to_user(ubuf + i, &rb->msg[rb->cons], sz);
 
Signature · 1 line
2.35.1
reviewer Reviewed-by on v1 1/1
#1 lore raw

On 04.08.22 10:11, Dan Carpenter wrote:

Hello Dan

Quoted 11 lines

This code tries to store -EFAULT in an unsigned int. The xenbus_file_read() function returns type ssize_t so the negative value is returned as a positive value to the user.

This change forces another change to the min() macro. Originally, the min() macro used "unsigned" type which checkpatch complains about. Also unsigned type would break if "len" were not capped at MAX_RW_COUNT. Use size_t for the min(). (No effect on runtime for the min_t() change).

Fixes 2fb3683e7b16 ("xen: Add xenbus device driver")

I think that patch does correct changes, so

[snip]

Signature · 3 lines
Regards,

Oleksandr Tyshchenko
maintainer Applied
#2 lore raw
In reply to Dan Carpenter
Quoted 11 lines · Dan Carpenter

This code tries to store -EFAULT in an unsigned int. The xenbus_file_read() function returns type ssize_t so the negative value is returned as a positive value to the user.

This change forces another change to the min() macro. Originally, the min() macro used "unsigned" type which checkpatch complains about. Also unsigned type would break if "len" were not capped at MAX_RW_COUNT. Use size_t for the min(). (No effect on runtime for the min_t() change).

Fixes 2fb3683e7b16 ("xen: Add xenbus device driver")

Pushed to xen/tip.git for-linus-6.0

Juergen