Skip to content

Commit

Permalink
rbd: use kstrndup() in rbd_header_from_disk()
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Dryomov <[email protected]>
Reviewed-by: Jason Dillaman <[email protected]>
  • Loading branch information
idryomov committed Feb 20, 2017
1 parent 083a51f commit 848d796
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 848d796

Please sign in to comment.