Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2213940imj; Sun, 10 Feb 2019 21:50:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IaOhPDOY3NsIhijfPqzBXhhEx8HliRxQN7iHn4ES3hfLQD37mJDa6YlxC1eo1XBOZDaRW+N X-Received: by 2002:a63:a:: with SMTP id 10mr28045180pga.121.1549864212116; Sun, 10 Feb 2019 21:50:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549864212; cv=none; d=google.com; s=arc-20160816; b=dQhiSbKVBoVvx0dBEKapOflZJs5jS+Um0/vB5Jgh3FJaD6Mpgx0TTbPWN0nqY+225j MvXUFS8q3RPExh+57CLWCeTq7SUwvVBUzDh4gl2IlN+JnG0UsCYxr+nrY4tPPDAgyKdf /pmJT6R8IzTIwVh8UDPFKjFpLo6zKqa0uCAFEFeBZWOHPEf+jfNUSM4BdVFSxvFER1e7 RxUB2eOe66MFeNjv0SRPKPrCNE809cMqfCAKb3Zhh5x/l3NNYa63VyZs4tKTD20Xt/wx ME1m7OR97u4QG+8N0d6XE/Ib/fot7ZRFcGYLZ086OyVPdGZcmEejAMP6tIoezMkT4Kpc 8szA== 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=qiqXLGy/wp1zD1QJmnuAlOFLiFkxWPZmqOodvt6seNY=; b=aLPEdwCktxLGmA2iJ5QoQdwhUQUwnzxjgJKQ/qk8Kwr2PF0vJFzT8dxYb/Zr8SdlKb ROo7xmJ4dw1BI0U2Bs0gbXPssJnWcgdQPO+wo1lE2N+R8B41Ip4579sjIHdGcgwnl8JC cmUHZudHDWrPCoWm8bsC+NGj9kaXq98mloseDJRGKuDV8aB2bFun+qn5NeEBufA1jqfH mXtJ71EKuG1T8EwfaH6FOVBXKPLqwB5BNW2sFq9kYFw9UUzPjDK4M3nKaGxeci/OUhLy 532CzVrZmPlqB57J8stLi4RjvvgDdUHNXO0VZGKRD0MVYOsJkqs83RS938kvoF/fGbJY aJFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=BTAFReVx; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e25si6039716pgv.486.2019.02.10.21.49.55; Sun, 10 Feb 2019 21:50:12 -0800 (PST) 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=@ti.com header.s=ti-com-17Q1 header.b=BTAFReVx; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726053AbfBKFtP (ORCPT + 99 others); Mon, 11 Feb 2019 00:49:15 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:48712 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725931AbfBKFtP (ORCPT ); Mon, 11 Feb 2019 00:49:15 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x1B5n4eg080661; Sun, 10 Feb 2019 23:49:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1549864144; bh=qiqXLGy/wp1zD1QJmnuAlOFLiFkxWPZmqOodvt6seNY=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=BTAFReVxLuhkfhKAI6KR3HMU2YOElcSiQ4Dzaiaj/jVUc51Z7OdBOX2Kd8HPGW5i8 LxUcflnwG7Sy8hRuz/4O8H1cETSPGUxWJqJ84V3J5MlQehh50I5XB/UiXSuV2sCnJp MvMW+zX6zPqQPe4yi6B5dEP0eu5Ej2oX7GjO3eGI= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x1B5n3xB001406 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 10 Feb 2019 23:49:04 -0600 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Sun, 10 Feb 2019 23:49:03 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Sun, 10 Feb 2019 23:49:03 -0600 Received: from [172.24.190.233] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id x1B5mxBU027901; Sun, 10 Feb 2019 23:49:00 -0600 Subject: Re: [PATCH v2] PCI: endpoint: functions: Use kmemdup instead of duplicating its function To: Lorenzo Pieralisi , Wen Yang CC: Bjorn Helgaas , , , , Gustavo Pimentel , Niklas Cassel , Greg Kroah-Hartman , Cyrille Pitchen References: <20181206125225.9497-1-wen.yang99@zte.com.cn> <20190208122027.GE13009@e107981-ln.cambridge.arm.com> From: Kishon Vijay Abraham I Message-ID: Date: Mon, 11 Feb 2019 11:18:25 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190208122027.GE13009@e107981-ln.cambridge.arm.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lorenzo, On 08/02/19 5:50 PM, Lorenzo Pieralisi wrote: > On Thu, Dec 06, 2018 at 08:52:25PM +0800, Wen Yang wrote: >> 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(-) > > Kishon, > > this looks OK to me, anything I am missing ? For the existing code this might seem the right thing to do but ideally the memcpy here should be changed to memcpy_fromio/memcpy_toio. Also later when we plan to use DMA (on the endpoint) for data transfer, we have to use kzalloc and dma_map_single APIs. So maybe the right thing would be to just fix it to use memcpy_fromio here. Thanks Kishon > > Lorenzo > >> 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; >> -- >> 2.19.1 >>