]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
rbd: use kstrndup() in rbd_header_from_disk()
authorIlya Dryomov <idryomov@gmail.com>
Wed, 25 Jan 2017 17:16:21 +0000 (18:16 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 20 Feb 2017 11:16:11 +0000 (12:16 +0100)
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Jason Dillaman <dillaman@redhat.com>
drivers/block/rbd.c

index 36d2b9f4e83654637925d57fce5a4fc8cd0f009e..c3251f9123c067be64ce7cedcae4b8d0f00b58ee 100644 (file)
@@ -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 */