aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSwapnil Ingle <swapnil.ingle@nutanix.com>2019-11-06 06:25:19 -0500
committerSwapnil Ingle <swapnil.ingle@nutanix.com>2019-11-06 06:25:19 -0500
commitadd5efb8913e8292e670de861126b68df4495cfe (patch)
treeb7b62e152b66dde8d1813a55e9f5d97450ce7439
parent4d1d4dd5b4818ee35d9d9985095493bcf219d296 (diff)
downloadlibvfio-user-add5efb8913e8292e670de861126b68df4495cfe.zip
libvfio-user-add5efb8913e8292e670de861126b68df4495cfe.tar.gz
libvfio-user-add5efb8913e8292e670de861126b68df4495cfe.tar.bz2
muser.c: Fix the return values of the functions
1> Use errno for the failures 2> Use signed types for the returned variables Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
-rw-r--r--kmod/muser.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/kmod/muser.c b/kmod/muser.c
index 72ce427..54e3e70 100644
--- a/kmod/muser.c
+++ b/kmod/muser.c
@@ -689,7 +689,7 @@ err:
return ret;
}
-static int has_anonymous_pages(struct vfio_dma_mapping *dma_map)
+static bool has_anonymous_pages(struct vfio_dma_mapping *dma_map)
{
int i, nr_pages = NR_PAGES(dma_map->length);
@@ -697,11 +697,11 @@ static int has_anonymous_pages(struct vfio_dma_mapping *dma_map)
if (PageAnon(dma_map->pages[i])) {
muser_dbg("ignore IOVA=%lx, page(s) not shared",
dma_map->iova);
- return 1;
+ return true;
}
}
- return 0;
+ return false;
}
static int muser_iommu_dma_map(struct muser_dev *mudev,
@@ -1107,7 +1107,7 @@ err:
return ret;
}
-static unsigned int get_minsz(unsigned int cmd)
+static ssize_t get_minsz(unsigned int cmd)
{
switch (cmd) {
case VFIO_DEVICE_GET_INFO:
@@ -1119,10 +1119,10 @@ static unsigned int get_minsz(unsigned int cmd)
case VFIO_DEVICE_SET_IRQS:
return offsetofend(struct vfio_irq_set, count);
}
- return -1;
+ return -EOPNOTSUPP;
}
-static unsigned int get_argsz(unsigned int cmd, struct mudev_cmd *mucmd)
+static ssize_t get_argsz(unsigned int cmd, struct mudev_cmd *mucmd)
{
switch (cmd) {
case VFIO_DEVICE_GET_INFO:
@@ -1135,20 +1135,19 @@ static unsigned int get_argsz(unsigned int cmd, struct mudev_cmd *mucmd)
return mucmd->muser_cmd.ioctl.data.irq_set.argsz;
}
- return -1;
+ return -EOPNOTSUPP;
}
static int muser_ioctl_setup_cmd(struct mudev_cmd *mucmd, unsigned int cmd,
unsigned long arg)
{
- unsigned int minsz;
- unsigned int argsz;
+ ssize_t argsz, minsz;
int err;
/* Determine smallest argsz we need for this command. */
minsz = get_minsz(cmd);
- if (minsz == -1)
- return -EOPNOTSUPP;
+ if (minsz < 0)
+ return minsz;
/* Copy caller-provided arg. */
err = muser_copyin(&mucmd->muser_cmd.ioctl.data, (void __user *)arg,
@@ -1158,8 +1157,8 @@ static int muser_ioctl_setup_cmd(struct mudev_cmd *mucmd, unsigned int cmd,
/* Fetch argsz provided by caller. */
argsz = get_argsz(cmd, mucmd);
- if (argsz == -1)
- return -EINVAL;
+ if (argsz < 0)
+ return argsz;
/* Ensure provided size is at least the minimum required. */
if (argsz < minsz)
@@ -1480,23 +1479,25 @@ static inline int mmap_done(struct mudev_cmd * const mucmd)
int ret;
if (cmd->err < 0)
- return -1;
+ return -EINVAL;
+
ret = do_pin_pages(addr, mucmd->mmap_len, 1, &mucmd->pg_map);
if (ret) {
muser_alert("failed to pin pages: %d", ret);
mucmd->pg_map.pages = NULL;
mucmd->pg_map.nr_pages = 0;
}
+
return ret;
}
-static long libmuser_unl_ioctl(struct file *filep,
- unsigned int cmd, unsigned long arg)
+static long libmuser_unl_ioctl(struct file *filep, unsigned int cmd,
+ unsigned long arg)
{
struct muser_dev *mudev = filep->private_data;
struct mudev_cmd *mucmd;
unsigned long offset;
- long ret = -EINVAL;
+ int ret = -EINVAL;
WARN_ON(mudev == NULL);
switch (cmd) {
@@ -1505,7 +1506,7 @@ static long libmuser_unl_ioctl(struct file *filep,
ret = wait_event_interruptible(mudev->user_wait_q,
!list_empty(&mudev->cmd_list));
if (unlikely(ret)) {
- muser_dbg("failed to wait for user space: %ld", ret);
+ muser_dbg("failed to wait for user space: %d", ret);
goto out;
}
@@ -1538,7 +1539,7 @@ static long libmuser_unl_ioctl(struct file *filep,
/* This is only called when a command is pending. */
if (mudev->mucmd_pending == NULL) {
muser_dbg("done but no command pending");
- return -1;
+ return -EINVAL;
}
/* Fetch (and clear) the pending command. */
@@ -1582,7 +1583,7 @@ static long libmuser_unl_ioctl(struct file *filep,
default:
muser_info("bad ioctl 0x%x", cmd);
- return -1;
+ return -EINVAL;
}
out: