aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorswapnili <swapnil.ingle@nutanix.com>2019-11-06 17:29:57 +0100
committerGitHub <noreply@github.com>2019-11-06 17:29:57 +0100
commit6686b7f5963c834566ba57787e949e7d0ffb29f7 (patch)
tree96e33245c086d3d3a1b752a87497b9ab2c426fd0
parent9985e21d9b00c35d53c181fdca7e3191531289f7 (diff)
parent5153d44b5370b4728b87afacdad17474be444efd (diff)
downloadlibvfio-user-6686b7f5963c834566ba57787e949e7d0ffb29f7.zip
libvfio-user-6686b7f5963c834566ba57787e949e7d0ffb29f7.tar.gz
libvfio-user-6686b7f5963c834566ba57787e949e7d0ffb29f7.tar.bz2
Merge pull request #8 from swapnili/master
Fix the return values type
-rw-r--r--kmod/muser.c52
-rw-r--r--lib/libmuser.c15
2 files changed, 28 insertions, 39 deletions
diff --git a/kmod/muser.c b/kmod/muser.c
index cd60021..451d007 100644
--- a/kmod/muser.c
+++ b/kmod/muser.c
@@ -613,7 +613,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)
@@ -697,7 +697,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);
@@ -705,11 +705,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,
@@ -1114,7 +1114,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:
@@ -1126,10 +1126,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:
@@ -1142,20 +1142,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,
@@ -1165,8 +1164,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)
@@ -1486,24 +1485,23 @@ 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 -1;
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, mucmd_err;
WARN_ON(mudev == NULL);
switch (cmd) {
@@ -1512,7 +1510,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;
}
@@ -1545,7 +1543,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. */
@@ -1558,6 +1556,7 @@ static long libmuser_unl_ioctl(struct file *filep,
if (ret)
goto out;
+ mucmd_err = mucmd->muser_cmd.err;
switch (mucmd->type) {
case MUSER_IOCTL:
offset = offsetof(struct muser_cmd, ioctl);
@@ -1565,13 +1564,12 @@ static long libmuser_unl_ioctl(struct file *filep,
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:
@@ -1589,7 +1587,7 @@ static long libmuser_unl_ioctl(struct file *filep,
default:
muser_info("bad ioctl 0x%x", cmd);
- return -1;
+ return -EINVAL;
}
out:
diff --git a/lib/libmuser.c b/lib/libmuser.c
index fcfdfd2..4233023 100644
--- a/lib/libmuser.c
+++ b/lib/libmuser.c
@@ -540,8 +540,7 @@ muser_dma_unmap(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
if (lm_ctx->dma == NULL) {
lm_log(lm_ctx, LM_ERR, "DMA not initialized\n");
- cmd->mmap.response = -1;
- return -1;
+ return -EINVAL;
}
err = dma_controller_remove_region(lm_ctx->dma,
@@ -553,8 +552,6 @@ muser_dma_unmap(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
cmd->mmap.request.len, cmd->mmap.request.addr, strerror(err));
}
- cmd->mmap.response = err;
-
return err;
}
@@ -568,8 +565,7 @@ muser_dma_map(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
if (lm_ctx->dma == NULL) {
lm_log(lm_ctx, LM_ERR, "DMA not initialized\n");
- cmd->mmap.response = -1;
- return -1;
+ return -EINVAL;
}
err = dma_controller_add_region(lm_ctx, lm_ctx->dma,
@@ -579,12 +575,9 @@ muser_dma_map(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
if (err < 0) {
lm_log(lm_ctx, LM_ERR, "failed to add DMA region %#lx@%#lx: %d\n",
cmd->mmap.request.len, cmd->mmap.request.addr, err);
- cmd->mmap.response = -1;
- return -1;
+ return err;
}
- cmd->mmap.response = 0;
-
return 0;
}
@@ -624,8 +617,6 @@ out:
if (err != 0) {
lm_log(lm_ctx, LM_ERR, "failed to mmap device memory %#x@%#lx: %s\n",
len, offset, strerror(-errno));
- cmd->err = err;
- err = -1;
}
return err;