From patchwork Thu Dec 6 12:52:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Yang X-Patchwork-Id: 10715963 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 492BD1731 for ; Thu, 6 Dec 2018 12:52:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38ED72E6B8 for ; Thu, 6 Dec 2018 12:52:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D2F52E6BE; Thu, 6 Dec 2018 12:52:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 174D22E6B8 for ; Thu, 6 Dec 2018 12:52:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729069AbeLFMwq (ORCPT ); Thu, 6 Dec 2018 07:52:46 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:32548 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728482AbeLFMwq (ORCPT ); Thu, 6 Dec 2018 07:52:46 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 98821D6411D58018E514; Thu, 6 Dec 2018 20:52:43 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wB6CqXAW072381; Thu, 6 Dec 2018 20:52:33 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from LIN-A6CB96A0603.zte.intra ([10.90.106.118]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018120620530589-15149764 ; Thu, 6 Dec 2018 20:53:05 +0800 From: Wen Yang To: Kishon Vijay Abraham I , Lorenzo Pieralisi , Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, Wen Yang , Gustavo Pimentel , Niklas Cassel , Greg Kroah-Hartman , Cyrille Pitchen Subject: [PATCH v2] PCI: endpoint: functions: Use kmemdup instead of duplicating its function Date: Thu, 6 Dec 2018 20:52:25 +0800 Message-Id: <20181206125225.9497-1-wen.yang99@zte.com.cn> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-12-06 20:53:05, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-12-06 20:52:21 X-MAIL: mse01.zte.com.cn wB6CqXAW072381 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP kmemdup has implemented the function that kmalloc() + memcpy(). We prefer to kmemdup rather than code opened implementation. This issue was detected with the help of coccinelle. Signed-off-by: Wen Yang CC: Kishon Vijay Abraham I CC: Lorenzo Pieralisi CC: Bjorn Helgaas CC: Gustavo Pimentel CC: Niklas Cassel CC: Greg Kroah-Hartman CC: Cyrille Pitchen CC: linux-pci@vger.kernel.org (open list:PCI ENDPOINT SUBSYSTEM) CC: linux-kernel@vger.kernel.org (open list) --- drivers/pci/endpoint/functions/pci-epf-test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 3e86fa3c7da3..8df6c019f8a2 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -169,14 +169,12 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) goto err_addr; } - buf = kzalloc(reg->size, GFP_KERNEL); + buf = kmemdup(src_addr, reg->size, GFP_KERNEL); if (!buf) { ret = -ENOMEM; goto err_map_addr; } - memcpy(buf, src_addr, reg->size); - crc32 = crc32_le(~0, buf, reg->size); if (crc32 != reg->checksum) ret = -EIO;