Skip to content

Commit

Permalink
net/mlx4_core: Fix error handling when initializing CQ bufs in the dr…
Browse files Browse the repository at this point in the history
…iver

Procedure mlx4_init_user_cqes() handles returns by copy_to_user
incorrectly. copy_to_user() returns the number of bytes not copied.
Thus, a non-zero return should be treated as a -EFAULT error
(as is done elsewhere in the kernel). However, mlx4_init_user_cqes()
error handling simply returns the number of bytes not copied
(instead of -EFAULT).

Note, though, that this is a harmless bug: procedure mlx4_alloc_cq()
(which is the only caller of mlx4_init_user_cqes()) treats any
non-zero return as an error, but that returned error value is processed
internally, and not passed further up the call stack.

In addition, fixes the following sparse warning:
warning: incorrect type in argument 1 (different address spaces)
   expected void [noderef] <asn:1>*to
   got void *buf

Fixes: e456789 ("{net, IB}/mlx4: Initialize CQ buffers in the driver when possible")
Reported by: Dan Carpenter <[email protected]>
Signed-off-by: Jack Morgenstein <[email protected]>
Signed-off-by: Tariq Toukan <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jack Morgenstein authored and davem330 committed Jan 25, 2019
1 parent a40ded6 commit ffe4cfc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/net/ethernet/mellanox/mlx4/cq.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,16 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size)

if (entries_per_copy < entries) {
for (i = 0; i < entries / entries_per_copy; i++) {
err = copy_to_user(buf, init_ents, PAGE_SIZE);
err = copy_to_user((void __user *)buf, init_ents, PAGE_SIZE) ?
-EFAULT : 0;
if (err)
goto out;

buf += PAGE_SIZE;
}
} else {
err = copy_to_user(buf, init_ents, entries * cqe_size);
err = copy_to_user((void __user *)buf, init_ents, entries * cqe_size) ?
-EFAULT : 0;
}

out:
Expand Down

0 comments on commit ffe4cfc

Please sign in to comment.