Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Alex Elder and committed by
Alex Elder
4caf35f9 979ed480

+2 -5
+2 -5
drivers/block/rbd.c
··· 3151 3151 size_t len; 3152 3152 3153 3153 len = next_token(buf); 3154 - dup = kmalloc(len + 1, GFP_KERNEL); 3154 + dup = kmemdup(*buf, len + 1, GFP_KERNEL); 3155 3155 if (!dup) 3156 3156 return NULL; 3157 - 3158 - memcpy(dup, *buf, len); 3159 3157 *(dup + len) = '\0'; 3160 3158 *buf += len; 3161 3159 ··· 3262 3264 ret = -ENAMETOOLONG; 3263 3265 goto out_err; 3264 3266 } 3265 - spec->snap_name = kmalloc(len + 1, GFP_KERNEL); 3267 + spec->snap_name = kmemdup(buf, len + 1, GFP_KERNEL); 3266 3268 if (!spec->snap_name) 3267 3269 goto out_mem; 3268 - memcpy(spec->snap_name, buf, len); 3269 3270 *(spec->snap_name + len) = '\0'; 3270 3271 3271 3272 /* Initialize all rbd options to the defaults */