diff mbox series

[-next] USB: core: Switch to use kmemdup_nul() helper

Message ID 20230807124610.2283583-1-ruanjinjie@huawei.com
State New
Headers show
Series [-next] USB: core: Switch to use kmemdup_nul() helper | expand

Commit Message

Jinjie Ruan Aug. 7, 2023, 12:46 p.m. UTC
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 mbox series

Patch

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);
 	}