linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
To: Kishon Vijay Abraham I <kishon@ti.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Wen Yang <wen.yang99@zte.com.cn>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"zhong.weidong@zte.com.cn" <zhong.weidong@zte.com.cn>,
	Gustavo Pimentel <gustavo.pimentel@synopsys.com>,
	Niklas Cassel <niklas.cassel@axis.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
Subject: Re: [PATCH v2] PCI: endpoint: functions: Use kmemdup instead of duplicating its function
Date: Mon, 11 Feb 2019 09:15:14 +0000	[thread overview]
Message-ID: <ba5489d4-671b-5b52-3917-ea478f7233e0@synopsys.com> (raw)
In-Reply-To: <aa4280f5-9750-05e9-7737-044d8f127521@ti.com>

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 <wen.yang99@zte.com.cn>
>>> CC: Kishon Vijay Abraham I <kishon@ti.com>
>>> CC: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>>> CC: Bjorn Helgaas <bhelgaas@google.com>
>>> CC: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
>>> CC: Niklas Cassel <niklas.cassel@axis.com>
>>> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>> CC: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
>>> 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
>>>


  reply	other threads:[~2019-02-11  9:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06 12:52 [PATCH v2] PCI: endpoint: functions: Use kmemdup instead of duplicating its function Wen Yang
2019-02-08 12:20 ` Lorenzo Pieralisi
2019-02-11  5:48   ` Kishon Vijay Abraham I
2019-02-11  9:15     ` Gustavo Pimentel [this message]
2019-02-11 12:37       ` Kishon Vijay Abraham I

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ba5489d4-671b-5b52-3917-ea478f7233e0@synopsys.com \
    --to=gustavo.pimentel@synopsys.com \
    --cc=bhelgaas@google.com \
    --cc=cyrille.pitchen@free-electrons.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=niklas.cassel@axis.com \
    --cc=wen.yang99@zte.com.cn \
    --cc=zhong.weidong@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).