Message ID | 20200727135151.54757-1-christophe.jaillet@wanadoo.fr (mailing list archive) |
---|---|
State | Accepted, archived |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1k03Sp-00FJ4P-9R; Mon, 27 Jul 2020 13:46:47 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728711AbgG0Nvz (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Mon, 27 Jul 2020 09:51:55 -0400 Received: from smtp11.smtpout.orange.fr ([80.12.242.133]:34738 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728577AbgG0Nvy (ORCPT <rfc822;linux-media@vger.kernel.org>); Mon, 27 Jul 2020 09:51:54 -0400 Received: from localhost.localdomain ([93.23.198.229]) by mwinf5d90 with ME id 8Drs230084xT3VZ03Drsf6; Mon, 27 Jul 2020 15:51:53 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 27 Jul 2020 15:51:53 +0200 X-ME-IP: 93.23.198.229 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: 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, Christophe JAILLET <christophe.jaillet@wanadoo.fr> Subject: [PATCH 2/2] media: bt8xx: avoid a useless memset Date: Mon, 27 Jul 2020 15:51:51 +0200 Message-Id: <20200727135151.54757-1-christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.4 (--) X-LSpam-Report: No, score=-2.4 required=5.0 tests=BAYES_00=-1.9,FREEMAIL_FORGED_FROMDOMAIN=0.001,FREEMAIL_FROM=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
Series |
[1/2] media: bt8xx: switch from 'pci_' to 'dma_' API
|
|
Commit Message
Christophe JAILLET
July 27, 2020, 1:51 p.m. UTC
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(-)
Comments
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.
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; }
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
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
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.
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; }