summaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2017-01-25 18:16:21 +0100
committerIlya Dryomov <idryomov@gmail.com>2017-02-20 12:16:11 +0100
commit848d796c8c918e2d60060992786f82754f539cd4 (patch)
treeae489d58e6a2a2d09313c4da51b1842dca787d6b /drivers/block/rbd.c
parent083a51fbc57ca848ab087692f3cc97898fd88b54 (diff)
downloadlinux-stable-848d796c8c918e2d60060992786f82754f539cd4.tar.gz
linux-stable-848d796c8c918e2d60060992786f82754f539cd4.tar.bz2
linux-stable-848d796c8c918e2d60060992786f82754f539cd4.zip
rbd: use kstrndup() in rbd_header_from_disk()
Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Jason Dillaman <dillaman@redhat.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 36d2b9f4e836..c3251f9123c0 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -992,15 +992,11 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,
/* Allocate this now to avoid having to handle failure below */
if (first_time) {
- size_t len;
-
- len = strnlen(ondisk->object_prefix,
- sizeof (ondisk->object_prefix));
- object_prefix = kmalloc(len + 1, GFP_KERNEL);
+ object_prefix = kstrndup(ondisk->object_prefix,
+ sizeof(ondisk->object_prefix),
+ GFP_KERNEL);
if (!object_prefix)
return -ENOMEM;
- memcpy(object_prefix, ondisk->object_prefix, len);
- object_prefix[len] = '\0';
}
/* Allocate the snapshot context and fill it in */