mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Fuqian Huang <huangfq.daxian@gmail.com>
Cc: Ilya Dryomov <idryomov@gmail.com>, Sage Weil <sage@redhat.com>,
	Alex Elder <elder@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	ceph-devel@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 04/35] block: Use kmemdup rather than duplicating its implementation
Date: Wed, 03 Jul 2019 12:33:43 -0400	[thread overview]
Message-ID: <e3f1ecd6f68ed34df240346fae92f9c821503c68.camel@kernel.org> (raw)
In-Reply-To: <20190703162650.32045-1-huangfq.daxian@gmail.com>

On Thu, 2019-07-04 at 00:26 +0800, Fuqian Huang wrote:
> kmemdup is introduced to duplicate a region of memory in a neat way.
> Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
> write the size twice (sometimes lead to mistakes), kmemdup improves
> readability, leads to smaller code and also reduce the chances of mistakes.
> Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.
> 
> Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
> ---
> Changes in v2:
>   - Fix a typo in commit message (memset -> memcpy)
> 
>  drivers/block/rbd.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index e5009a34f9c2..47ad3772dc58 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -1068,7 +1068,7 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,
>  
>  		if (snap_names_len > (u64)SIZE_MAX)
>  			goto out_2big;
> -		snap_names = kmalloc(snap_names_len, GFP_KERNEL);
> +		snap_names = kmemdup(&ondisk->snaps[snap_count], snap_names_len, GFP_KERNEL);
>  		if (!snap_names)
>  			goto out_err;
>  
> @@ -1088,7 +1088,6 @@ static int rbd_header_from_disk(struct rbd_device *rbd_dev,
>  		 * snap_names_len bytes beyond the end of the
>  		 * snapshot id array, this memcpy() is safe.
>  		 */
> -		memcpy(snap_names, &ondisk->snaps[snap_count], snap_names_len);
>  		snaps = ondisk->snaps;
>  		for (i = 0; i < snap_count; i++) {
>  			snapc->snaps[i] = le64_to_cpu(snaps[i].id);

Reviewed-by: Jeff Layton <jlayton@kernel.org>


      reply	other threads:[~2019-07-03 16:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-03 16:26 Fuqian Huang
2019-07-03 16:33 ` Jeff Layton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3f1ecd6f68ed34df240346fae92f9c821503c68.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=ceph-devel@vger.kernel.org \
    --cc=elder@kernel.org \
    --cc=huangfq.daxian@gmail.com \
    --cc=idryomov@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sage@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®