aboutsummaryrefslogtreecommitdiff
path: root/kmod
diff options
context:
space:
mode:
authorSwapnil Ingle <swapnil.ingle@nutanix.com>2019-11-06 08:14:38 -0500
committerSwapnil Ingle <swapnil.ingle@nutanix.com>2019-11-06 09:56:54 -0500
commit5153d44b5370b4728b87afacdad17474be444efd (patch)
treeca56f21e7526fddda1e0d03323cf32fcf2e52c7b /kmod
parentadd5efb8913e8292e670de861126b68df4495cfe (diff)
downloadlibvfio-user-5153d44b5370b4728b87afacdad17474be444efd.zip
libvfio-user-5153d44b5370b4728b87afacdad17474be444efd.tar.gz
libvfio-user-5153d44b5370b4728b87afacdad17474be444efd.tar.bz2
muser, libmuser: Do not abuse muser_cmd.mmap.response to return err
muser_cmd.mmap.response is unsigned and should not be used to return errors, instead use muser_cmd.err Also fixed the code path to use valid errno values. Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'kmod')
-rw-r--r--kmod/muser.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/kmod/muser.c b/kmod/muser.c
index 54e3e70..7ee5926 100644
--- a/kmod/muser.c
+++ b/kmod/muser.c
@@ -605,7 +605,7 @@ static int muser_process_dma_request(struct muser_dev *mudev,
if (unlikely(err))
return err;
- return mucmd.muser_cmd.mmap.response;
+ return mucmd.muser_cmd.err;
}
static int muser_process_dma_map(struct muser_dev *mudev, int flags)
@@ -1478,9 +1478,6 @@ static inline int mmap_done(struct mudev_cmd * const mucmd)
char __user *addr = (char __user *) cmd->mmap.response;
int ret;
- if (cmd->err < 0)
- return -EINVAL;
-
ret = do_pin_pages(addr, mucmd->mmap_len, 1, &mucmd->pg_map);
if (ret) {
muser_alert("failed to pin pages: %d", ret);
@@ -1497,7 +1494,7 @@ static long libmuser_unl_ioctl(struct file *filep, unsigned int cmd,
struct muser_dev *mudev = filep->private_data;
struct mudev_cmd *mucmd;
unsigned long offset;
- int ret = -EINVAL;
+ int ret = -EINVAL, mucmd_err;
WARN_ON(mudev == NULL);
switch (cmd) {
@@ -1552,6 +1549,7 @@ static long libmuser_unl_ioctl(struct file *filep, unsigned int cmd,
if (ret)
goto out;
+ mucmd_err = mucmd->muser_cmd.err;
switch (mucmd->type) {
case MUSER_IOCTL:
offset = offsetof(struct muser_cmd, ioctl);
@@ -1559,13 +1557,12 @@ static long libmuser_unl_ioctl(struct file *filep, unsigned int cmd,
ret = bounce_in(mucmd, (void __user *)(arg + offset));
break;
case MUSER_MMAP:
- ret = mmap_done(mucmd);
+ if (!mucmd_err)
+ ret = mmap_done(mucmd);
break;
case MUSER_READ:
- if (mucmd->muser_cmd.err < 0) {
- muser_alert("read failed: %d",
- mucmd->muser_cmd.err);
- }
+ if (mucmd_err < 0)
+ muser_alert("read failed: %d", mucmd_err);
break;
case MUSER_WRITE:
case MUSER_DMA_MMAP: