Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1103075ybi; Wed, 3 Jul 2019 09:32:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHpwLQZXCdVwP4nuvHqL32Ot7h1EHbAVE7/S+DB8XmezjXEMHBOVYpDU2Xn7IVt5LVD1qH X-Received: by 2002:a65:4087:: with SMTP id t7mr14371584pgp.10.1562171540473; Wed, 03 Jul 2019 09:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562171540; cv=none; d=google.com; s=arc-20160816; b=o8IeNiGflxrQ/mmUUHR+1qybQ4rPyQhFhfk0zPUcN2lUhCWpx+r2WCb1G/XcKN/exj x94/5tazUgsXyBFpCFRDg6itPgGiyhVb4gQOn0Fi1dH29ihPPnvnuGD+ZpqKl6dpg290 NjDLFoInZiXonNEMGsba9/fpdQ6SbbhzPPYtvLFmwbEW6HFS/OxMQwFnHlDG6RTsPqSO kteEaIbidBUPMrq5ZZC6Js4Jl/Y11WEtCBTXgV/OeRjOfgx4McbdwCxHGkyOMRK/sR/q zgmUmuDOKKI453W78bwWF6fbVNIFBKc1xnWT4sYV2kwIt8sOQo+IYFImk7n7+U5oVbC9 aFsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature; bh=TrUa09acIW6HvvTGIpKx9PQFnQ16L2qeMF4zqtIgcwg=; b=RjmUevLlt1JzdjqhBVm9eE+9YiVPrzpDFWnYnemNyUsn9lM3094Cn49o6XKo1L2/1B wMBpQ0P7E8xAJa0x1AMFpGMzKk5keG7L6RBRgpbj2hqNNEkMppnOb1IvkGJQU9o/6fJk HrpMg2NsHOb/ajpCqpqLiQSB5iD6Eb8raCsmgfQ7V/fyoXBY0o0DG4wUsdfzq6hGzT9n JLuxQ+v241NhOx/DyIx6yuj/CDZEms13dR24Lgv9ak2bFwaWgxExHjlasqAoWlYmFL0i Oe4Y+YsvZ9QXi2t7Pt4jHpK3UDfjLtCmfjZVp1BGTHstrAZyZFSR0REiyUYfySIe4ZXP jzKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=StUzsoCd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l68si2640273plb.416.2019.07.03.09.32.04; Wed, 03 Jul 2019 09:32:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=StUzsoCd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727375AbfGCQau (ORCPT + 99 others); Wed, 3 Jul 2019 12:30:50 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38986 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727172AbfGCQau (ORCPT ); Wed, 3 Jul 2019 12:30:50 -0400 Received: by mail-pf1-f193.google.com with SMTP id j2so1535129pfe.6; Wed, 03 Jul 2019 09:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=TrUa09acIW6HvvTGIpKx9PQFnQ16L2qeMF4zqtIgcwg=; b=StUzsoCdTyphOOOBhHCvimsHOl/lw6873T7vbUGAhmcpeJckEl2APf6QxyfvODfDIx 6sv+a39EElywHWTMqTyLFrLV0YQedXL2l1LNtjU/b13C/pXw15WkDbAg2FPIuLC4gimN 0auJd7+Z7/WvneBw6+x2kNagrFfkxpL6rvIHgXU+nV8xFZf3EsEZwf7wv6Y6SYY2zGSq 9Lw8CMkOLH6e9MkO+4Sa7hWcfrWMxV1YQoFN4kpk4jOpLN8LNE1SUjmXxf6jNgfTbV47 /mIcNT3WshuviL+x5ENk2SgPUA8mV8XGgfPOnywr/LF4HBCswaXpLNYbDMyh0JA8a/3M GM1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TrUa09acIW6HvvTGIpKx9PQFnQ16L2qeMF4zqtIgcwg=; b=iNQPhyIe9Fg4nRequEbF+YOVvJS18rnXZsYneaSeUpWwXZ31Sto+/gy4mH4Incb7H4 NUc0B3M2yXuz6S/U0MDAaizqaq7TzHFLl2XL0oZwVWS0DS12+Csp8nLeD9A6PsbE4b4F CPCTkxu8dtgjejkiYWwP2xdf1I+2qeoyDf/BQArIODWPUTOyFRWSU3bC1UlrMERsI1f8 bYzhEt4rje24jGfcmpV5fcrvgUPAbUuwVIImAXyr6TrJZTFQPy2qA4mVr2bF2ACtUAW/ 8uXVA74NRopD/u3hPdpRgDNbL2A8O1PnhHbx76gvHhx0h7rO4Xor9K41+SlSwcYiF+gd tAZA== X-Gm-Message-State: APjAAAX0Wr7jr4UmOGZjthAEY+6nIutTaTz8XvPYU7h8ndB2c8ZqMXPD bXirx9cczhgCfSVbyxYeNPYL1ZN0KZ8= X-Received: by 2002:a63:d84e:: with SMTP id k14mr38156512pgj.234.1562171449109; Wed, 03 Jul 2019 09:30:49 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id v4sm2915326pff.45.2019.07.03.09.30.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 09:30:48 -0700 (PDT) From: Fuqian Huang Cc: Oliver Neukum , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH v2 25/35] usb: Use kmemdup rather than duplicating its implementation Date: Thu, 4 Jul 2019 00:30:43 +0800 Message-Id: <20190703163043.524-1-huangfq.daxian@gmail.com> X-Mailer: git-send-email 2.11.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in v2: - Fix a typo in commit message (memset -> memcpy) drivers/usb/class/cdc-acm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 183b41753c98..cc4a96d59ffc 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1410,12 +1410,11 @@ static int acm_probe(struct usb_interface *intf, struct usb_cdc_country_functional_desc * cfd = h.usb_cdc_country_functional_desc; - acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); + acm->country_codes = kmemdup((u8 *)&cfd->wCountyCode0, + cfd->bLength - 4, GFP_KERNEL); if (!acm->country_codes) goto skip_countries; acm->country_code_size = cfd->bLength - 4; - memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, - cfd->bLength - 4); acm->country_rel_date = cfd->iCountryCodeRelDate; i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); -- 2.11.0