From patchwork Mon Aug 7 12:46:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13344169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0159C001B0 for ; Mon, 7 Aug 2023 12:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231672AbjHGMra (ORCPT ); Mon, 7 Aug 2023 08:47:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230489AbjHGMr3 (ORCPT ); Mon, 7 Aug 2023 08:47:29 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D42941BEF for ; Mon, 7 Aug 2023 05:47:08 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RKGGL1yfzz1Z1WL; Mon, 7 Aug 2023 20:43:54 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 7 Aug 2023 20:46:41 +0800 From: Ruan Jinjie To: , , , , , , CC: Subject: [PATCH -next] USB: core: Switch to use kmemdup_nul() helper Date: Mon, 7 Aug 2023 20:46:10 +0800 Message-ID: <20230807124610.2283583-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use kmemdup_nul() helper instead of open-coding it to simplify the code. Signed-off-by: Ruan Jinjie --- 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); }