All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Ruan Jinjie <ruanjinjie@huawei.com>
Cc: hadess@hadess.net, benjamin.tissoires@redhat.com,
	herve.codina@bootlin.com, robh@kernel.org,
	mailhol.vincent@wanadoo.fr, linux-usb@vger.kernel.org
Subject: Re: [PATCH -next] USB: core: Switch to use kmemdup_nul() helper
Date: Tue, 8 Aug 2023 10:22:14 +0200	[thread overview]
Message-ID: <2023080822-embark-quaking-074e@gregkh> (raw)
In-Reply-To: <20230807124610.2283583-1-ruanjinjie@huawei.com>

On Mon, Aug 07, 2023 at 08:46:10PM +0800, Ruan Jinjie wrote:
> Use kmemdup_nul() helper instead of open-coding it to simplify the code.
> 
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
>  drivers/usb/core/message.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
> index 0d2bfc909019..5762fd04f0d5 100644
> --- a/drivers/usb/core/message.c
> +++ b/drivers/usb/core/message.c
> @@ -1029,10 +1029,9 @@ char *usb_cache_string(struct usb_device *udev, int index)
>  	if (buf) {
>  		len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
>  		if (len > 0) {
> -			smallbuf = kmalloc(++len, GFP_NOIO);
> +			smallbuf = kmemdup_nul(buf, len, GFP_NOIO);
>  			if (!smallbuf)
>  				return buf;
> -			memcpy(smallbuf, buf, len);

But you changed the logic here, you now added an extra \0 where the
existing code did not.  Are you sure you mean to do this?  If so, why,
and it needs to be documented in the changelog text.

What this could be is a call to kmemdup() if you really want it, but be
careful about the ++len usage...

Also, does this need to be changed at all?  How was it tested?

thanks,

greg k-h

  reply	other threads:[~2023-08-08 20:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 12:46 [PATCH -next] USB: core: Switch to use kmemdup_nul() helper Ruan Jinjie
2023-08-08  8:22 ` Greg KH [this message]
2023-08-08  8:57   ` Ruan Jinjie

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=2023080822-embark-quaking-074e@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=hadess@hadess.net \
    --cc=herve.codina@bootlin.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=robh@kernel.org \
    --cc=ruanjinjie@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.