Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2365566imj; Mon, 11 Feb 2019 01:22:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IYZXMtSiWKSEqK+D8Fift2xHpIA6zGRjtmoZGD9IQSNV6OF/aL4dF8B0Q4G8+jpbauaSGrV X-Received: by 2002:a62:6e05:: with SMTP id j5mr3823513pfc.158.1549876924295; Mon, 11 Feb 2019 01:22:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549876924; cv=none; d=google.com; s=arc-20160816; b=zNbArLt7OkHsmp0xuEepc6IVR7knaQace2emoGLukRr849XvSy9jgp4bzGjOBQJR3U PMUZezQ86fDi+yqb2CDmUd/ZICs7e3xSDd2KKxV4DqYWQ7zKr7YbU1Gc+us+uAuenjYe sXfsheRM0R66LeHCRwxr9rV91NUoCE2FxDYbr+5S51pgE06Ty3jUnzkNjOkoz6tJAUYU LSNjrUSRkjvDKoliijQQFIiRIqf/TeLmwsxHiPeWV+vQ2/WRPF7Q6zACQe8XR3dtdNGm EB+NhL57jYrlKl5liqo+XoVerBd9HHMek4SjPgsNOIfaiiWv3asySIsJx1/F+FkI9eHG VJvA== 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=UvNOIU5cOmmfy2AIKZHl/vsKXuCkxQU4WL/+WFnP9M8=; b=ew4UMm5ixLbO+18uIZYNoXqWdw114aZBr+Im4rXi/qn5HhJ9fHoF2SDtGkURdeD5uf bq5kUFUgPEgEZHxdC37TLlnAdb6lUK9jcHsNBx0bkWx2XKIrmYx4Q25DF7+vFH5fgwNr WZNYMxVjCLKxRSRstgJBwvldheiTDAPg9g1fvLR3DQ2YHpqa0IAktAykWsEHCIPlxp9h 4y272A4VwyrYceIul/Y3YgrpxeQI2yINMbI6x4rFqnFDqnUDOyjCojnWGGd/L8JutZ83 puY4zKhmLoI2nce8mRDv6RaCHS0UJ+M9+fWa4tJ5pUx83jmYFq8gn0Rhr+cGWgGiNixA YPYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=JDy1AklV; 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=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 6si9929476plc.241.2019.02.11.01.21.47; Mon, 11 Feb 2019 01:22:04 -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=@synopsys.com header.s=mail header.b=JDy1AklV; 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=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727018AbfBKJVE (ORCPT + 99 others); Mon, 11 Feb 2019 04:21:04 -0500 Received: from smtprelay.synopsys.com ([198.182.47.9]:46074 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbfBKJVE (ORCPT ); Mon, 11 Feb 2019 04:21:04 -0500 Received: from mailhost.synopsys.com (dc2-mailhost2.synopsys.com [10.12.135.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtprelay.synopsys.com (Postfix) with ESMTPS id B505024E08D3; Mon, 11 Feb 2019 01:21:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1549876863; bh=EH7VUg+Q6lexcjexkohozI0rSLmhGviJeaDcN1x3nUE=; h=Subject:To:CC:References:From:Date:In-Reply-To:From; b=JDy1AklVuRaUUtc7nbF6kCAoJzU6Ls9VjwmIg9C+v3dywd7RVO2S8ufGGry0mf0uO Fo3lfozgOIbZx4eBJIOe6QMYXjO4p6SE27+4Ujm0Lq6Rw8pbb9demtcXRZSdzIborM oI4B3y6875w2/gOJwFqcaTyEz9/3a+eBUlNZkF7Sr9sQTLcvqTrYq+VQKZLK0Lq8L6 Z5eMFFJx1T9G5p4VMSHSgLXXSbf/LnlwlqTH7kDUthauL9CLUs/qeooXL09mR8ppUU WBwE900QVtL/gDbQpw1m2Z5C7Z+2rG+ZOnW8KF6/SqcqWYzvt2X2lg0Q80bikZQByJ BelbZSs4IJ2vQ== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2.internal.synopsys.com [10.12.239.237]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPS id A963BA009D; Mon, 11 Feb 2019 09:21:00 +0000 (UTC) Received: from DE02WEHTCB.internal.synopsys.com (10.225.19.94) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 11 Feb 2019 01:20:17 -0800 Received: from DE02WEHTCA.internal.synopsys.com (10.225.19.92) by DE02WEHTCB.internal.synopsys.com (10.225.19.94) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 11 Feb 2019 10:20:15 +0100 Received: from [10.107.25.131] (10.107.25.131) by DE02WEHTCA.internal.synopsys.com (10.225.19.80) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 11 Feb 2019 10:20:14 +0100 Subject: Re: [PATCH v2] PCI: endpoint: functions: Use kmemdup instead of duplicating its function To: Kishon Vijay Abraham I , Lorenzo Pieralisi , Wen Yang CC: Bjorn Helgaas , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "zhong.weidong@zte.com.cn" , 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: Gustavo Pimentel Message-ID: Date: Mon, 11 Feb 2019 09:15:14 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.107.25.131] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/02/2019 05:48, Kishon Vijay Abraham I wrote: > 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. Are you considering to use the eDMA driver that I'm developing? > > 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 >>>