提交 4caf35f9 编写于 作者: A Alex Elder 提交者: Alex Elder

rbd: use kmemdup()

This replaces two kmalloc()/memcpy() combinations with a single
call to kmemdup().
Signed-off-by: NAlex Elder <elder@inktank.com>
Reviewed-by: NDavid Zafman <david.zafman@inktank.com>
Reviewed-by: NJosh Durgin <josh.durgin@inktank.com>
上级 979ed480
...@@ -3151,11 +3151,9 @@ static inline char *dup_token(const char **buf, size_t *lenp) ...@@ -3151,11 +3151,9 @@ static inline char *dup_token(const char **buf, size_t *lenp)
size_t len; size_t len;
len = next_token(buf); len = next_token(buf);
dup = kmalloc(len + 1, GFP_KERNEL); dup = kmemdup(*buf, len + 1, GFP_KERNEL);
if (!dup) if (!dup)
return NULL; return NULL;
memcpy(dup, *buf, len);
*(dup + len) = '\0'; *(dup + len) = '\0';
*buf += len; *buf += len;
...@@ -3264,10 +3262,9 @@ static int rbd_add_parse_args(const char *buf, ...@@ -3264,10 +3262,9 @@ static int rbd_add_parse_args(const char *buf,
ret = -ENAMETOOLONG; ret = -ENAMETOOLONG;
goto out_err; goto out_err;
} }
spec->snap_name = kmalloc(len + 1, GFP_KERNEL); spec->snap_name = kmemdup(buf, len + 1, GFP_KERNEL);
if (!spec->snap_name) if (!spec->snap_name)
goto out_mem; goto out_mem;
memcpy(spec->snap_name, buf, len);
*(spec->snap_name + len) = '\0'; *(spec->snap_name + len) = '\0';
/* Initialize all rbd options to the defaults */ /* Initialize all rbd options to the defaults */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册