From: Ruan Jinjie <ruanjinjie@huawei.com>
To: <gregkh@linuxfoundation.org>, <hadess@hadess.net>,
<benjamin.tissoires@redhat.com>, <herve.codina@bootlin.com>,
<robh@kernel.org>, <mailhol.vincent@wanadoo.fr>,
<linux-usb@vger.kernel.org>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH -next] USB: core: Switch to use kmemdup_nul() helper
Date: Mon, 7 Aug 2023 20:46:10 +0800 [thread overview]
Message-ID: <20230807124610.2283583-1-ruanjinjie@huawei.com> (raw)
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);
}
kfree(buf);
}
--
2.34.1
next reply other threads:[~2023-08-07 12:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 12:46 Ruan Jinjie [this message]
2023-08-08 8:22 ` [PATCH -next] USB: core: Switch to use kmemdup_nul() helper Greg KH
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=20230807124610.2283583-1-ruanjinjie@huawei.com \
--to=ruanjinjie@huawei.com \
--cc=benjamin.tissoires@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=hadess@hadess.net \
--cc=herve.codina@bootlin.com \
--cc=linux-usb@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=robh@kernel.org \
/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.