Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp897034ybi; Wed, 3 Jul 2019 06:20:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLQXFFLNugZyLC2lDAG7LI31YCEeybu2CfQo31DfvRrM2cNrgaLfjWEx271dJtyvpvMfgV X-Received: by 2002:a63:1d53:: with SMTP id d19mr37208726pgm.152.1562160040245; Wed, 03 Jul 2019 06:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562160040; cv=none; d=google.com; s=arc-20160816; b=Z8qnAxyNmp11B8Nk2bkDJsjVJ/MSQKILWLswCl9DMGR8wAzJZB3LLas91YaVPrtuvV vdvo5g0aSq0vpWH326ZzUxVghlqTNox++SwiMT0douKcYqNXnzI8o1h8Tn1hiboJ1Erf t2eL8K8QOwDQ4LxZRc8UBJB6H3j1X7GBA0rpEFbJPVhV10pW3QicJYcCyvQZ84w0cf8s ylRwYlXcHOM4cJsJGbpToiWCadFhF9SCsLt0uG7KdCeM8FeytKo/Pfes0FpVe8MWeAZ5 i9jZequwpeIC/tiAwauVEa4TDt4q9aath2SLsDI4mu1QugjQ9W+chSFFv0WwfSNkLu2v Tk3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=jgQROG+UEH6/opA6KH5Z7+riscQwAjL4quybFcDWmgk=; b=H37N6Zzq1pKQMrhwGUQSsQBXUWg1NwAHTLvc7JvO4bQ1LY0ClyP/7t2v4ZC5viM9Qq QuzAktCLNj90rJjrBGbf0AKCB4BVpAodAsyDle+a6MivKlZwRhbjmZ31eVZeJCxlSXyB Oigobu3KJRO+djmVl3gP3Vzjez0jacScgyhbZ6fIio7/f2QNcf1NnSnqKJC3VcaGGpMb AScoW6sLMfLQ+78CK5DihqeBjTqjbr5HwFFo1+E+liMrrsDey66FDB5NGhUrS/kHNBEm Is5RS6lSkoWxROJk77v8bLYLrFLxlofB1UH4ozRGRThNzELZ9sPisbD34Cl4ooQpTCFo n7eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=rUe2uflj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l125si2515688pgl.63.2019.07.03.06.20.25; Wed, 03 Jul 2019 06:20:40 -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=pass header.i=@c-s.fr header.s=mail header.b=rUe2uflj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727026AbfGCNUC (ORCPT + 99 others); Wed, 3 Jul 2019 09:20:02 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:23453 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbfGCNUC (ORCPT ); Wed, 3 Jul 2019 09:20:02 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 45f1tQ3cLGz9v01x; Wed, 3 Jul 2019 15:19:58 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=rUe2uflj; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id iKri1vSda-LR; Wed, 3 Jul 2019 15:19:58 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 45f1tQ2YQzz9v01w; Wed, 3 Jul 2019 15:19:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1562159998; bh=jgQROG+UEH6/opA6KH5Z7+riscQwAjL4quybFcDWmgk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=rUe2ufljgQWRO0cVg4/ZfJuTFMKu/q27D4zizFbvQKzj72busF8AJLTiuA7789/mJ Bhn3nszxOJm9oNl8AR3cwwDd0eyy09eNtdu2vh7UJkq1EEsJ9MfMo1OevAs4uNyN5i 1UgsFWWcKDnFg8xNDQc5WySBFMZ3ddFXKDt8yAdQ= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C860F8B815; Wed, 3 Jul 2019 15:19:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id y3m8qO8lx4v5; Wed, 3 Jul 2019 15:19:59 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 81E668B811; Wed, 3 Jul 2019 15:19:59 +0200 (CEST) Subject: Re: [PATCH 09/30] macintosh: Use kmemdup rather than duplicating its implementation To: Fuqian Huang Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20190703131452.25085-1-huangfq.daxian@gmail.com> From: Christophe Leroy Message-ID: Date: Wed, 3 Jul 2019 15:19:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190703131452.25085-1-huangfq.daxian@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 03/07/2019 à 15:14, Fuqian Huang a écrit : > kmemdup is introduced to duplicate a region of memory in a neat way. > Rather than kmalloc/kzalloc + memset, 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 + memset. s/memset/memcpy/ > > Signed-off-by: Fuqian Huang > --- > drivers/macintosh/adbhid.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c > index 75482eeab2c4..5d14bebfb58f 100644 > --- a/drivers/macintosh/adbhid.c > +++ b/drivers/macintosh/adbhid.c > @@ -789,7 +789,8 @@ adbhid_input_register(int id, int default_id, int original_handler_id, > > switch (default_id) { > case ADB_KEYBOARD: > - hid->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL); > + hid->keycode = kmemdup(adb_to_linux_keycodes, > + sizeof(adb_to_linux_keycodes), GFP_KERNEL); > if (!hid->keycode) { > err = -ENOMEM; > goto fail; > @@ -797,8 +798,6 @@ adbhid_input_register(int id, int default_id, int original_handler_id, > > sprintf(hid->name, "ADB keyboard"); > > - memcpy(hid->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes)); > - > switch (original_handler_id) { > default: > keyboard_type = ""; >