diff options
| author | Alex Elder <elder@dreamhost.com> | 2012-11-01 09:39:27 -0400 |
|---|---|---|
| committer | Alex Elder <elder@inktank.com> | 2013-01-17 15:09:00 -0500 |
| commit | 4caf35f9ecdca1feef1d2e5e223b78e52ffbea87 (patch) | |
| tree | ae709588c296a65d394489d14fb3635ce2fceea0 | |
| parent | 979ed480a2722ad8d9f87054635158f652a1241e (diff) | |
rbd: use kmemdup()
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>
| -rw-r--r-- | drivers/block/rbd.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index e01dbb12ad03..d97611e2b4ee 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
| @@ -3151,11 +3151,9 @@ static inline char *dup_token(const char **buf, size_t *lenp) | |||
| 3151 | size_t len; | 3151 | size_t len; |
| 3152 | 3152 | ||
| 3153 | len = next_token(buf); | 3153 | len = next_token(buf); |
| 3154 | dup = kmalloc(len + 1, GFP_KERNEL); | 3154 | dup = kmemdup(*buf, len + 1, GFP_KERNEL); |
| 3155 | if (!dup) | 3155 | if (!dup) |
| 3156 | return NULL; | 3156 | return NULL; |
| 3157 | |||
| 3158 | memcpy(dup, *buf, len); | ||
| 3159 | *(dup + len) = '\0'; | 3157 | *(dup + len) = '\0'; |
| 3160 | *buf += len; | 3158 | *buf += len; |
| 3161 | 3159 | ||
| @@ -3264,10 +3262,9 @@ static int rbd_add_parse_args(const char *buf, | |||
| 3264 | ret = -ENAMETOOLONG; | 3262 | ret = -ENAMETOOLONG; |
| 3265 | goto out_err; | 3263 | goto out_err; |
| 3266 | } | 3264 | } |
| 3267 | spec->snap_name = kmalloc(len + 1, GFP_KERNEL); | 3265 | spec->snap_name = kmemdup(buf, len + 1, GFP_KERNEL); |
| 3268 | if (!spec->snap_name) | 3266 | if (!spec->snap_name) |
| 3269 | goto out_mem; | 3267 | goto out_mem; |
| 3270 | memcpy(spec->snap_name, buf, len); | ||
| 3271 | *(spec->snap_name + len) = '\0'; | 3268 | *(spec->snap_name + len) = '\0'; |
| 3272 | 3269 | ||
| 3273 | /* Initialize all rbd options to the defaults */ | 3270 | /* Initialize all rbd options to the defaults */ |
