Skip to content

Commit

Permalink
rbd: use kmemdup()
Browse files Browse the repository at this point in the history
This replaces two kmalloc()/memcpy() combinations with a single
call to kmemdup().

Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: David Zafman <david.zafman@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
  • Loading branch information
Alex Elder authored and Alex Elder committed Jan 17, 2013
1 parent 979ed48 commit 4caf35f
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3151,11 +3151,9 @@ static inline char *dup_token(const char **buf, size_t *lenp)
size_t len;

len = next_token(buf);
dup = kmalloc(len + 1, GFP_KERNEL);
dup = kmemdup(*buf, len + 1, GFP_KERNEL);
if (!dup)
return NULL;

memcpy(dup, *buf, len);
*(dup + len) = '\0';
*buf += len;

Expand Down Expand Up @@ -3264,10 +3262,9 @@ static int rbd_add_parse_args(const char *buf,
ret = -ENAMETOOLONG;
goto out_err;
}
spec->snap_name = kmalloc(len + 1, GFP_KERNEL);
spec->snap_name = kmemdup(buf, len + 1, GFP_KERNEL);
if (!spec->snap_name)
goto out_mem;
memcpy(spec->snap_name, buf, len);
*(spec->snap_name + len) = '\0';

/* Initialize all rbd options to the defaults */
Expand Down

0 comments on commit 4caf35f

Please sign in to comment.