* [PATCH 2/2] media: bt8xx: avoid a useless memset
@ 2020-07-27 13:51 Christophe JAILLET
2020-07-27 16:09 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Christophe JAILLET @ 2020-07-27 13:51 UTC (permalink / raw)
To: mchehab, akpm, rppt, hverkuil-cisco
Cc: linux-media, linux-kernel, kernel-janitors, Christophe JAILLET
Avoid a memset after a call to 'dma_alloc_coherent()'.
This is useless since
commit 518a2f1925c3 ("dma-mapping: zero memory returned from dma_alloc_*")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/media/pci/bt8xx/btcx-risc.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/media/pci/bt8xx/btcx-risc.c b/drivers/media/pci/bt8xx/btcx-risc.c
index 13bb1490a568..b3179038b900 100644
--- 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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] media: bt8xx: avoid a useless memset
2020-07-27 13:51 [PATCH 2/2] media: bt8xx: avoid a useless memset Christophe JAILLET
@ 2020-07-27 16:09 ` Joe Perches
2020-07-27 16:16 ` Joe Perches
2020-07-28 8:01 ` Christophe JAILLET
0 siblings, 2 replies; 6+ messages in thread
From: Joe Perches @ 2020-07-27 16:09 UTC (permalink / raw)
To: Christophe JAILLET, mchehab, akpm, rppt, hverkuil-cisco
Cc: linux-media, linux-kernel, kernel-janitors
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] media: bt8xx: avoid a useless memset
2020-07-27 16:09 ` Joe Perches
@ 2020-07-27 16:16 ` Joe Perches
2020-07-28 8:05 ` Christophe JAILLET
2020-07-28 8:01 ` Christophe JAILLET
1 sibling, 1 reply; 6+ messages in thread
From: Joe Perches @ 2020-07-27 16:16 UTC (permalink / raw)
To: Christophe JAILLET, mchehab, akpm, rppt, hverkuil-cisco
Cc: linux-media, linux-kernel, kernel-janitors
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;
}
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] media: bt8xx: avoid a useless memset
2020-07-27 16:09 ` Joe Perches
2020-07-27 16:16 ` Joe Perches
@ 2020-07-28 8:01 ` Christophe JAILLET
1 sibling, 0 replies; 6+ messages in thread
From: Christophe JAILLET @ 2020-07-28 8:01 UTC (permalink / raw)
To: Joe Perches, mchehab, akpm, rppt, hverkuil-cisco
Cc: linux-media, linux-kernel, kernel-janitors
Le 27/07/2020 à 18:09, Joe Perches a écrit :
> 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.
>
>
>
Agreed.
This 2/2 patch should be NAK'ed.
I've been a bit too fast on this one.
Thanks for the review Joe.
CJ
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] media: bt8xx: avoid a useless memset
2020-07-27 16:16 ` Joe Perches
@ 2020-07-28 8:05 ` Christophe JAILLET
2020-07-28 9:25 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Christophe JAILLET @ 2020-07-28 8:05 UTC (permalink / raw)
To: Joe Perches, mchehab, akpm, rppt, hverkuil-cisco
Cc: linux-media, linux-kernel, kernel-janitors
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] media: bt8xx: avoid a useless memset
2020-07-28 8:05 ` Christophe JAILLET
@ 2020-07-28 9:25 ` Joe Perches
0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2020-07-28 9:25 UTC (permalink / raw)
To: Christophe JAILLET, mchehab, akpm, rppt, hverkuil-cisco
Cc: linux-media, linux-kernel, kernel-janitors
On Tue, 2020-07-28 at 10:05 +0200, Christophe JAILLET wrote:
> 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().
Just a suggestion.
As it's dependent on your first patch, perhaps
you could make the appropriate change.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-07-28 9:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 13:51 [PATCH 2/2] media: bt8xx: avoid a useless memset Christophe JAILLET
2020-07-27 16:09 ` Joe Perches
2020-07-27 16:16 ` Joe Perches
2020-07-28 8:05 ` Christophe JAILLET
2020-07-28 9:25 ` Joe Perches
2020-07-28 8:01 ` Christophe JAILLET
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).