Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp892094ybi; Wed, 3 Jul 2019 06:16:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxj1X9ZzDy9nPBpyxLBtH4VvKsBiJ4F6GG8G1PI5VmADzKbpQtKYjTaTT+O6V1aLQaDbOgZ X-Received: by 2002:a17:90a:a489:: with SMTP id z9mr12306108pjp.24.1562159780720; Wed, 03 Jul 2019 06:16:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562159780; cv=none; d=google.com; s=arc-20160816; b=i5fLTsbYOTKT+FMon9f0P5hjXZXyze9k9PJ57yPPvc6QIvWnhqatfG/CwY0RTdQuwu +mG+D6fbI+CQuInXXZSqHLM7aToFaF3S/tCEi27zenrN0uElxRmQjyEdGBgNAXiHhOS1 oCdXctXOCNjCWlh9YceDR5bWgccgNq/+UVfMJStFDIp0uAzVsEiJS7B8oza5hnEhrggL NORPS/dm27WbX7XLcZM49RdrtYWcEKYhb2bw7xWsceA4ae64VqmrkUFFiqYtiA26Vd6+ cnLr1oS9tnsq1TzqNr6Bd6CgkvRrtKeutqQSjQgYEPqD17lSdNjp6OxJnR3MHX4AZthh zExQ== 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=TOAiuu/wlD5D7o5/mqIHnTG4uZtldrOoIUofef28WiU=; b=hQp3wfIt0+wijWvkKvN5jkBWSrfJiQ8ELlZ9SPbHPwmCNycbJgnvgob/mC2cdFF9+l S9z8in/mq4xRI3rw4RMJxiKhP7xoVjqzRXvCjDujTLNYxXMWbOGfLTLrfOJH796mI6ph 2R+FW9QRSfZqlL8AVIXibiC/zR8r95p1H6PYCWN7n3RH2JLLY9zCmSOiRx2KZsvdZYxR wDpnvhUXw9a0fibnXUfUFk1oqLi1B6m1j611ZBCpXT8OIk5ByC8SIgRg05BjVc44xzY7 W39U3FyU97Zk6fwoMO67Tu+xRHvz5RIBp3QYAZzNJ/CLyHlyFOHrkm0mLMU/Gzt8PeNk UdUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=lfIH0IUL; 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 v11si2040007pjn.44.2019.07.03.06.16.04; Wed, 03 Jul 2019 06:16: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=lfIH0IUL; 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 S1727168AbfGCNPB (ORCPT + 99 others); Wed, 3 Jul 2019 09:15:01 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38706 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbfGCNPA (ORCPT ); Wed, 3 Jul 2019 09:15:00 -0400 Received: by mail-pf1-f193.google.com with SMTP id y15so1274582pfn.5 for ; Wed, 03 Jul 2019 06:15:00 -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=TOAiuu/wlD5D7o5/mqIHnTG4uZtldrOoIUofef28WiU=; b=lfIH0IUL8bnlFMDRimVxIwkNQ/20moehxMR8XeG6e1vo0CHjFIa7S4/IFzeJrzgJlU q2EJ1FOEjXJguDQSyMFXH7k3X9n1scvRb7MkJjtKkRBfWxe8gnqZdhJTTVtiiemk1hZ8 JEsWEwZyeYK5LrcZYxqtxqYOB84MaPfNmB0WpIoCWpbsKR17eWSZ/DL4BpVsMdWBspi3 XBGVX5QsFJ2A9jlFpjBiIrBKWiWS6s+R4q4WHhiK4NP1F7C+nhehr4iK/vSnZH9RFSc2 eCufZv73Y0MyVNOl+ObekcnzpEHus2zpOUjXEVq9ou6kVad7pijQPkngK46W9dWsm/zJ axEg== 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=TOAiuu/wlD5D7o5/mqIHnTG4uZtldrOoIUofef28WiU=; b=dlCJUpaLSBycb3zmPLm52W//v+wEVMco7F2oaAaZ1W/6jxZT+d4PHEgh4pT27P7U2F lqWukXv7qoG1cXiN+tNd2bwzTpTZ8HtxUSe8hNwdqr+XidptKWvIaf5inYWobfpYgZvU nyp87wq20i4R7ODTeHM6yLTJVMeMyVoca49ZWaZnpcob0T5LLrA7mV+kNbOqEPuXbkCC BVXmZ6awyov1zgNirm2B3GUYX4bUiVRKv/3DeYgqXDv/RFibHh+Tc2SNINDQ3MyC4ZrL z7T9cKUJyKI31YTufg/VRbAcLxZa0Dq18vAaxNcA2D9aoXSB1jo86C6XWbm3gpzXuOg3 Nkug== X-Gm-Message-State: APjAAAV4enyNDeqXcpYpPM/6+bmuGYV0YpWMk7SS6xBvl3MlJaFbiaRh DRTJiH5Ci+tyaF5isRDAT70= X-Received: by 2002:a63:f510:: with SMTP id w16mr37865515pgh.0.1562159700244; Wed, 03 Jul 2019 06:15:00 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id j14sm2877028pfn.120.2019.07.03.06.14.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 06:14:59 -0700 (PDT) From: Fuqian Huang Cc: Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH 09/30] macintosh: Use kmemdup rather than duplicating its implementation Date: Wed, 3 Jul 2019 21:14:52 +0800 Message-Id: <20190703131452.25085-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 + 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. 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 = ""; -- 2.11.0