Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1101855ybi; Wed, 3 Jul 2019 09:31:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwyVIuFU5J95BKbOFPGElU+/V3S980z+Om5jw3+lZytzS2mWUcJrCEP87ym9Ufjl4KLR/MJ X-Received: by 2002:a17:902:724:: with SMTP id 33mr42461430pli.49.1562171476567; Wed, 03 Jul 2019 09:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562171476; cv=none; d=google.com; s=arc-20160816; b=RQJhB/PnFemCcN52w5NLjFwLfzF/1+KJEGv+j3KvL8SLqabzkAw1wipRt0EueSbD1Z Ohz1+XP46R+dzEbU0bGZqj+2KQlBl42r0bGO3cwawCU8YF1v4KGqf4Ci5uSgO65XPOXb 59O8twvNQltJlzLETNBfEfTAK63NHlowVomjCgSF3sW//+R0vjmjM3SUjmKFgy5VHqot MfqeuNIpgOwCbqDVEN1x1CTm/VMgWqAIDG8N9i2KZb/WmzTcie4/iN+D+1QctiJMb3Mt QFIpgOdPxUwbNE0c/0q7KJsT+1sB8zsk0IECtf9LfItaEzz9TOEVXyO++W7GRoTlG/e+ bxNA== 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=sWA+8J2rSgIapxEvPrdhvzsbd/hl1uuQJT8SGPnww+g=; b=re3b0b510tQ9ILIi5VNl81aP7Rw784ueUZyI4frieq8hWFnQUcTyakhbnzsJ+XANbM ATqNR4R/CvufUILISiJ9zl0uTQZ1/PRt8FPOAnIIABXbDn1gZ7J9o7up2f1nBpFuWJtj /9wxxty/jlHQ6P9307Lxx6eTI2E4iy/oueNoVdu0XQHdgf93oCYCJ7Xfj3sZNDLucb8x 6T583/NTD7Wrn9KgqUo7cQ/hoXCbOh+9U6DWeQBngzD2T7KPwmLMCwELwG6c1tgAim9O ZklXmXWNQ/Ovz6f7c50TaXxhPJUV+l5yFWW9fbiGSTsV+nlP9Mqqf/l6pItI1jaE38Mk gmYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=FIZ+QjmO; 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 j16si2513626pff.262.2019.07.03.09.31.00; Wed, 03 Jul 2019 09:31:16 -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=FIZ+QjmO; 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 S1727339AbfGCQaA (ORCPT + 99 others); Wed, 3 Jul 2019 12:30:00 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34668 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbfGCQaA (ORCPT ); Wed, 3 Jul 2019 12:30:00 -0400 Received: by mail-pl1-f195.google.com with SMTP id i2so1533480plt.1; Wed, 03 Jul 2019 09:29:59 -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=sWA+8J2rSgIapxEvPrdhvzsbd/hl1uuQJT8SGPnww+g=; b=FIZ+QjmOinajLJg2asmfCN0UL5nbWAIVO3EZ3yUaJUBmqqc9WUWCY/6EWbCnzxXGMe LwA/1ZpnjqlYHyeggJ3Re9eD+AeoCWKcVk2a+LmOHmf6jhqgIDNailwMLDJDR8OJJaZ4 +4fKc/H01jPaCXf9gy8Sifze4cCTi17+49znbXfqXKPGXcUh7uRT/DzRwrj3YPWeWdMg V2ya/cCRrCjxxuFRrQ6r1bD/MimWhE8kk5dwymljYoMPV+ia+5gc2uBHF4gHQbwuBX0A WoYLz2QPapqy/YMwqW3+7sxsykF3BzXughF4YqwNHCehTk+etRfgNdVgs5luI2cnZEhy DlSQ== 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=sWA+8J2rSgIapxEvPrdhvzsbd/hl1uuQJT8SGPnww+g=; b=NX/w5WDfyyA53gkBlaYx84uw/hWnphJu8yeJ3cxnVBC9PepXmaZq2btQUKgaaitcv1 Am4hMRRsccqK08duN0LXNzOS0DZRXlJabgfFUIPvDhDLMhqx/oxI8d13B8GvxGcncosn r1VuapZXNtMNf0OXRZNMVTSsjsfvtAWXpTHE8HmNk8H7mskMd2C9c1e/yF9hbKSeYMeM OwlmQT1EMY3VfMghApmjP84MctVUpDijsTbG+6ApOS/ZbUrNVREJxMg/GqSwcPs7IH0d e2lfJJWg2of/ONBQ1w/8s/Zd7DZ1hTpwi/mnJbktz7XA/59/yUqmEns+UoIp6ttQOC7L nZug== X-Gm-Message-State: APjAAAVtI6zD/Yo9nPmran7v/FEuvEm0SvvuLJlY1obIqeErJvcWurHO 6iXQ09AIb60EcxFmF8xNO6I= X-Received: by 2002:a17:902:7248:: with SMTP id c8mr6203101pll.162.1562171399475; Wed, 03 Jul 2019 09:29:59 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id p13sm8179907pjb.30.2019.07.03.09.29.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 09:29:59 -0700 (PDT) From: Fuqian Huang Cc: Corentin Chary , Darren Hart , Andy Shevchenko , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH v2 20/35] platform/x86/asus: Use kmemdup rather than duplicating its implementation Date: Thu, 4 Jul 2019 00:29:51 +0800 Message-Id: <20190703162951.32737-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) - Split into two patches. drivers/platform/x86/asus-wmi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 9b18a184e0aa..472b317ad814 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -260,12 +260,11 @@ static int asus_wmi_evaluate_method_agfn(const struct acpi_buffer args) * Copy to dma capable address otherwise memory corruption occurs as * bios has to be able to access it. */ - input.pointer = kzalloc(args.length, GFP_DMA | GFP_KERNEL); + input.pointer = kmemdup(args.pointer, args.length, GFP_DMA | GFP_KERNEL); input.length = args.length; if (!input.pointer) return -ENOMEM; phys_addr = virt_to_phys(input.pointer); - memcpy(input.pointer, args.pointer, args.length); status = asus_wmi_evaluate_method(ASUS_WMI_METHODID_AGFN, phys_addr, 0, &retval); -- 2.11.0