diff mbox

[01/15] rbd: use kstrndup() in rbd_header_from_disk()

Message ID 1487103124-2974-2-git-send-email-idryomov@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ilya Dryomov Feb. 14, 2017, 8:11 p.m. UTC
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
 drivers/block/rbd.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Alex Elder Feb. 15, 2017, 3:52 p.m. UTC | #1
On 02/14/2017 02:11 PM, Ilya Dryomov wrote:
> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>

Looks good.

Reviewed-by: Alex Elder <elder@linaro.org>


> ---
>  drivers/block/rbd.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 40a15ae354ce..76e538c3378e 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 */
> 

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alex Elder Feb. 15, 2017, 3:52 p.m. UTC | #2
On 02/14/2017 02:11 PM, Ilya Dryomov wrote:
> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>

Looks good.

Reviewed-by: Alex Elder <elder@linaro.org>


> ---
>  drivers/block/rbd.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 40a15ae354ce..76e538c3378e 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 */
> 

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 40a15ae354ce..76e538c3378e 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 */