From: Wang Wensheng wangwensheng4@huawei.com
The return value of XSHMEM_BLOCK_ALLOC was stored in the input xshm_block_arg, since ioctl could not return long type.
Signed-off-by: Wang Wensheng wangwensheng4@huawei.com --- include/uapi/linux/xshmem_framework.h | 18 +++++++++--------- lib/xshmem/xshmem_blk.c | 6 +++--- lib/xshmem/xshmem_framework.c | 30 ++++++++++++++++++------------ lib/xshmem/xshmem_framework.h | 4 ++-- lib/xshmem/xshmem_fsc.c | 2 +- 5 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/include/uapi/linux/xshmem_framework.h b/include/uapi/linux/xshmem_framework.h index ffb3546..07181d7 100644 --- a/include/uapi/linux/xshmem_framework.h +++ b/include/uapi/linux/xshmem_framework.h @@ -10,7 +10,7 @@
struct xshm_reg_arg { int algo; - unsigned int pool_size; + unsigned long pool_size; unsigned int block_size; /* used for blk algorithm */ unsigned int key_len; char *key; @@ -19,17 +19,17 @@ struct xshm_reg_arg { struct xshm_block_arg { int pool_id; union { - int size; // for alloc - unsigned int offset; // for get and put + unsigned long size; /* for alloc input */ + unsigned long offset; /* for get, put, delete and alloc output */ }; };
-#define XSHMEM_POOL_REGISTER _IOW('X', 1, struct xshm_reg_arg) -#define XSHMEM_POOL_UNREGISTER _IO ('X', 2) -#define XSHMEM_BLOCK_ALLOC _IOW('X', 3, struct xshm_block_arg) -#define XSHMEM_BLOCK_GET _IOW('X', 4, struct xshm_block_arg) -#define XSHMEM_BLOCK_PUT _IOW('X', 5, struct xshm_block_arg) -#define XSHMEM_BLOCK_DELETE _IOW('X', 6, struct xshm_block_arg) +#define XSHMEM_POOL_REGISTER _IOW ('X', 1, struct xshm_reg_arg) +#define XSHMEM_POOL_UNREGISTER _IO ('X', 2) +#define XSHMEM_BLOCK_ALLOC _IOWR('X', 3, struct xshm_block_arg) +#define XSHMEM_BLOCK_GET _IOW ('X', 4, struct xshm_block_arg) +#define XSHMEM_BLOCK_PUT _IOW ('X', 5, struct xshm_block_arg) +#define XSHMEM_BLOCK_DELETE _IOW ('X', 6, struct xshm_block_arg)
#define XSHMEM_ALGO_EMPTY -1 #define XSHMEM_ALGO_BLOCK 0 diff --git a/lib/xshmem/xshmem_blk.c b/lib/xshmem/xshmem_blk.c index a3d93a3..81012e2 100644 --- a/lib/xshmem/xshmem_blk.c +++ b/lib/xshmem/xshmem_blk.c @@ -65,9 +65,9 @@ static int blk_algo_pool_free(struct xshm_pool *xp) return 0; }
-static int blk_algo_block_alloc(struct xshm_pool *xp, struct xshm_block *blk, u32 size) +static long blk_algo_block_alloc(struct xshm_pool *xp, struct xshm_block *blk, unsigned long size) { - int idx; + long idx; struct blk_ctrl *ctrl = xp->private;
if (size > ctrl->block_size) { @@ -97,7 +97,7 @@ static int blk_algo_block_alloc(struct xshm_pool *xp, struct xshm_block *blk, u3
static int blk_algo_block_free(struct xshm_pool *xp, struct xshm_block *blk) { - int idx = (long)blk->private; + long idx = (long)blk->private; struct blk_ctrl *ctrl = xp->private;
clear_bit(idx, ctrl->map); diff --git a/lib/xshmem/xshmem_framework.c b/lib/xshmem/xshmem_framework.c index 74bce3b..46fefb8 100644 --- a/lib/xshmem/xshmem_framework.c +++ b/lib/xshmem/xshmem_framework.c @@ -379,9 +379,10 @@ static struct xshm_block *xshmem_find_block(struct xshm_pool *xp, u32 offset) return NULL; }
-static int ioctl_xshmem_block_alloc(struct xshm_pool *xp, struct xshm_task_pool_node *node, int size) +static int ioctl_xshmem_block_alloc(struct xshm_pool *xp, struct xshm_task_pool_node *node, + struct xshm_block_arg *arg) { - int ret; + long ret; struct xshm_block *blk; struct xshm_task_block_cnt *cnt;
@@ -399,13 +400,14 @@ static int ioctl_xshmem_block_alloc(struct xshm_pool *xp, struct xshm_task_pool_ }
mutex_lock(&xp->xp_block_mutex); - ret = xp->algo->xshm_block_alloc(xp, blk, size); + ret = xp->algo->xshm_block_alloc(xp, blk, arg->size); if (ret < 0) { kfree(blk); kfree(cnt); } else { blk->refcnt = 1; blk->offset = ret; + arg->offset = ret; INIT_LIST_HEAD(&blk->list_head); list_add_tail(&blk->block_node, &xp->block_head);
@@ -417,7 +419,7 @@ static int ioctl_xshmem_block_alloc(struct xshm_pool *xp, struct xshm_task_pool_ } mutex_unlock(&xp->xp_block_mutex);
- return ret; + return ret < 0 ? ret : 0; }
static struct xshm_task_block_cnt * @@ -520,8 +522,9 @@ static int ioctl_xshmem_block_common(struct xshm_task *task, unsigned int cmd, u struct xshm_pool *xp; struct xshm_block_arg block_arg; struct xshm_task_pool_node *node; + struct xshm_block_arg *usr_arg = (struct xshm_block_arg __user *)arg;
- if (copy_from_user(&block_arg, (struct xshm_free_arg __user*)arg, sizeof(block_arg))) { + if (copy_from_user(&block_arg, usr_arg, sizeof(block_arg))) { pr_err("copy_from_user failed\n"); return -EFAULT; } @@ -540,7 +543,10 @@ static int ioctl_xshmem_block_common(struct xshm_task *task, unsigned int cmd, u
switch(cmd) { case XSHMEM_BLOCK_ALLOC: - ret = ioctl_xshmem_block_alloc(xp, node, block_arg.size); + ret = ioctl_xshmem_block_alloc(xp, node, &block_arg); + if (!ret) + /* should never failed */ + ret = put_user(block_arg.offset, &usr_arg->offset); break; case XSHMEM_BLOCK_GET: ret = ioctl_xshmem_block_get(xp, node, block_arg.offset); @@ -642,14 +648,14 @@ EXPORT_SYMBOL_GPL(xshmem_register_algo);
static bool empty_algo_pool_same(struct xshm_pool *xp, struct xshm_reg_arg *arg) { - pr_info("pool_same_hook: algo:%s, pool_size: %d\n", xp->algo->name, arg->pool_size); + pr_info("pool_same_hook: algo:%s, pool_size: %ld\n", xp->algo->name, arg->pool_size); return (unsigned long)xp->private == arg->pool_size; }
static int empty_algo_pool_init(struct xshm_pool *xp, struct xshm_reg_arg *arg) { - pr_info("pool_init_hook: algo:%s, pool_size: %d\n", xp->algo->name, arg->pool_size); - xp->private = (void *)(unsigned long)arg->pool_size; + pr_info("pool_init_hook: algo:%s, pool_size: %ld\n", xp->algo->name, arg->pool_size); + xp->private = (void *)arg->pool_size; return 0; }
@@ -660,15 +666,15 @@ static int empty_algo_pool_free(struct xshm_pool *xp) return 0; }
-static int empty_algo_block_alloc(struct xshm_pool *xp, struct xshm_block *blk, u32 size) +static long empty_algo_block_alloc(struct xshm_pool *xp, struct xshm_block *blk, unsigned long size) { - pr_info("block_alloc_hook:pool_id:%d, alloc_size:%d\n", xp->pool_id, size); + pr_info("block_alloc_hook:pool_id:%d, alloc_size:%lu\n", xp->pool_id, size); return 0; }
static int empty_algo_block_free(struct xshm_pool *xp, struct xshm_block *blk) { - pr_info("block_free_hook:pool_id:%d, offset:%d\n", xp->pool_id, blk->offset); + pr_info("block_free_hook:pool_id:%d, offset:%ld\n", xp->pool_id, blk->offset); return 0; }
diff --git a/lib/xshmem/xshmem_framework.h b/lib/xshmem/xshmem_framework.h index f543c27..a939a69 100644 --- a/lib/xshmem/xshmem_framework.h +++ b/lib/xshmem/xshmem_framework.h @@ -32,7 +32,7 @@ struct xshm_pool {
struct xshm_block { int refcnt; - u32 offset; /* the size of the block is not cared in the + unsigned long offset; /* the size of the block is not cared in the framework, the specified algorithm should manage it properly */ struct list_head block_node; @@ -49,7 +49,7 @@ struct xshm_pool_algo { bool (*xshm_pool_same)(struct xshm_pool *xp, struct xshm_reg_arg *arg); int (*xshm_pool_init)(struct xshm_pool *xp, struct xshm_reg_arg *arg); int (*xshm_pool_free)(struct xshm_pool *xp); - int (*xshm_block_alloc)(struct xshm_pool *xp, struct xshm_block *blk, u32 size); + long (*xshm_block_alloc)(struct xshm_pool *xp, struct xshm_block *blk, unsigned long size); int (*xshm_block_free)(struct xshm_pool *xp, struct xshm_block *blk); };
diff --git a/lib/xshmem/xshmem_fsc.c b/lib/xshmem/xshmem_fsc.c index 941918d..fac8b12 100644 --- a/lib/xshmem/xshmem_fsc.c +++ b/lib/xshmem/xshmem_fsc.c @@ -173,7 +173,7 @@ static int split_new_block(struct fsc_ctrl *ctrl, struct fsc_block *block, u32 s } }
-static int fsc_algo_block_alloc(struct xshm_pool *xp, struct xshm_block *blk, u32 size) +static long fsc_algo_block_alloc(struct xshm_pool *xp, struct xshm_block *blk, unsigned long size) { int ret; u32 aligned_size;