From add5efb8913e8292e670de861126b68df4495cfe Mon Sep 17 00:00:00 2001 From: Swapnil Ingle Date: Wed, 6 Nov 2019 06:25:19 -0500 Subject: 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 --- kmod/muser.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'kmod') 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: -- cgit v1.1