mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Joe Perches <joe@perches.com>,
	mchehab@kernel.org, akpm@linux-foundation.org, rppt@kernel.org,
	hverkuil-cisco@xs4all.nl
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 2/2] media: bt8xx: avoid a useless memset
Date: Tue, 28 Jul 2020 10:05:08 +0200	[thread overview]
Message-ID: <d5759bd3-5e8a-a557-cd3e-0a2ae4d124e9@wanadoo.fr> (raw)
In-Reply-To: <30618c986727e5f8a9806f663b4e6f4aa80065ae.camel@perches.com>

Le 27/07/2020 à 18:16, Joe Perches a écrit :
> On Mon, 2020-07-27 at 09:09 -0700, Joe Perches wrote:
>> On Mon, 2020-07-27 at 15:51 +0200, Christophe JAILLET wrote:
>>> Avoid a memset after a call to 'dma_alloc_coherent()'.
>>> This is useless since
>>> commit 518a2f1925c3 ("dma-mapping: zero memory returned from dma_alloc_*")
>> []
>>> diff --git a/drivers/media/pci/bt8xx/btcx-risc.c b/drivers/media/pci/bt8xx/btcx-risc.c
>> []
>>> @@ -73,7 +73,6 @@ int btcx_riscmem_alloc(struct pci_dev *pci,
>>>   		dprintk("btcx: riscmem alloc [%d] dma=%lx cpu=%p size=%d\n",
>>>   			memcnt, (unsigned long)dma, cpu, size);
>>>   	}
>>> -	memset(risc->cpu,0,risc->size);
>>>   	return 0;
>>>   }
>>
>> Likely NAK.
>>
>> This is not useless as risc->cpu may be reused
>> and the alloc may not have been done.
> 
> Perhaps a little rewrite for clarity:
> ---
>   drivers/media/pci/bt8xx/btcx-risc.c | 24 +++++++++++++-----------
>   1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/pci/bt8xx/btcx-risc.c b/drivers/media/pci/bt8xx/btcx-risc.c
> index 51257980f539..311f4ca2a108 100644
> --- a/drivers/media/pci/bt8xx/btcx-risc.c
> +++ b/drivers/media/pci/bt8xx/btcx-risc.c
> @@ -56,24 +56,26 @@ int btcx_riscmem_alloc(struct pci_dev *pci,
>   		       struct btcx_riscmem *risc,
>   		       unsigned int size)
>   {
> -	__le32 *cpu;
> -	dma_addr_t dma = 0;
> -
> -	if (NULL != risc->cpu && risc->size < size)
> -		btcx_riscmem_free(pci,risc);
> -	if (NULL == risc->cpu) {
> -		cpu = pci_alloc_consistent(pci, size, &dma);
> -		if (NULL == cpu)
> +	if (risc->cpu && risc->size < size)
> +		btcx_riscmem_free(pci, risc);
> +
> +	if (risc->cpu) {
> +		memset(risc->cpu, 0, risc->size);
> +	} else {
> +		dma_addr_t dma = 0;
> +
> +		risc->cpu = pci_alloc_consistent(pci, size, &dma);
> +		if (!risc->cpu)
>   			return -ENOMEM;
> -		risc->cpu  = cpu;
> +
>   		risc->dma  = dma;
>   		risc->size = size;
>   
>   		memcnt++;
>   		dprintk("btcx: riscmem alloc [%d] dma=%lx cpu=%p size=%d\n",
> -			memcnt, (unsigned long)dma, cpu, size);
> +			memcnt, (unsigned long)dma, risc->cpu, size);
>   	}
> -	memset(risc->cpu,0,risc->size);
> +
>   	return 0;
>   }
>   
> 
> 
Looks good to me.

Just note, that this will not apply after patch 1/2 is applied, because 
it turns pci_alloc_consistent() into dma_alloc_coherent().

CJ

  reply	other threads:[~2020-07-28  8:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 13:51 Christophe JAILLET
2020-07-27 16:09 ` Joe Perches
2020-07-27 16:16   ` Joe Perches
2020-07-28  8:05     ` Christophe JAILLET [this message]
2020-07-28  9:25       ` Joe Perches
2020-07-28  8:01   ` Christophe JAILLET

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=d5759bd3-5e8a-a557-cd3e-0a2ae4d124e9@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=akpm@linux-foundation.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=joe@perches.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rppt@kernel.org \
    /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

all inboxes | Powered by JetHome®