Skip to content

Commit 32ad111

Browse files
Dan Carpenterjgross1
authored andcommitted
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: 2fb3683 ("xen: Add xenbus device driver") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> Link: https://lore.kernel.org/r/YutxJUaUYRG/VLVc@kili Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 402c43e commit 32ad111

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/xen/xenbus/xenbus_dev_frontend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static ssize_t xenbus_file_read(struct file *filp,
128128
{
129129
struct xenbus_file_priv *u = filp->private_data;
130130
struct read_buffer *rb;
131-
unsigned i;
131+
ssize_t i;
132132
int ret;
133133

134134
mutex_lock(&u->reply_mutex);
@@ -148,7 +148,7 @@ static ssize_t xenbus_file_read(struct file *filp,
148148
rb = list_entry(u->read_buffers.next, struct read_buffer, list);
149149
i = 0;
150150
while (i < len) {
151-
unsigned sz = min((unsigned)len - i, rb->len - rb->cons);
151+
size_t sz = min_t(size_t, len - i, rb->len - rb->cons);
152152

153153
ret = copy_to_user(ubuf + i, &rb->msg[rb->cons], sz);
154154

0 commit comments

Comments
 (0)