linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: endpoint: IS_ERR() vs NULL bug in pci_epf_test_init_dma_chan()
@ 2022-07-08  8:41 Dan Carpenter
  2022-07-11  5:50 ` Shunsuke Mie
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2022-07-08  8:41 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Frank Li, dmaengine
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Bjorn Helgaas,
	Shunsuke Mie, Hou Zhiqiang, Li Chen, Manivannan Sadhasivam,
	linux-pci, kernel-janitors

The dma_request_channel() function doesn't return error pointers, it
returns NULL.

Fixes: fff86dfbbf82 ("PCI: endpoint: Enable DMA tests for endpoints with DMA capabilities")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
It's surprising and unfortunate that dma_request_channel() returns NULL
while dma_request_chan_by_mask() returns error pointers.  These days
static checkers will catch this so it's not as bad as it could be but
still not ideal.

 drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 34aac220dd4c..eed6638ab71d 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -221,7 +221,7 @@ static int pci_epf_test_init_dma_chan(struct pci_epf_test *epf_test)
 	filter.dma_mask = BIT(DMA_MEM_TO_DEV);
 	dma_chan = dma_request_channel(mask, epf_dma_filter_fn, &filter);
 
-	if (IS_ERR(dma_chan)) {
+	if (!dma_chan) {
 		dev_info(dev, "Failed to get private DMA tx channel. Falling back to generic one\n");
 		goto fail_back_rx;
 	}
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: endpoint: IS_ERR() vs NULL bug in pci_epf_test_init_dma_chan()
  2022-07-08  8:41 [PATCH] PCI: endpoint: IS_ERR() vs NULL bug in pci_epf_test_init_dma_chan() Dan Carpenter
@ 2022-07-11  5:50 ` Shunsuke Mie
  2022-07-12  7:43   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Shunsuke Mie @ 2022-07-11  5:50 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Kishon Vijay Abraham I, Frank Li, dmaengine, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Bjorn Helgaas, Hou Zhiqiang, Li Chen,
	Manivannan Sadhasivam, linux-pci, kernel-janitors

This patch changes for a tx dma channel. There is a similar problem for a
 rx one too. The code doesn't cause an error, but it is likely better to
change to just NULL checking.

2022年7月8日(金) 17:41 Dan Carpenter <dan.carpenter@oracle.com>:

>
> The dma_request_channel() function doesn't return error pointers, it
> returns NULL.
>
> Fixes: fff86dfbbf82 ("PCI: endpoint: Enable DMA tests for endpoints with DMA capabilities")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> It's surprising and unfortunate that dma_request_channel() returns NULL
> while dma_request_chan_by_mask() returns error pointers.  These days
> static checkers will catch this so it's not as bad as it could be but
> still not ideal.
>
>  drivers/pci/endpoint/functions/pci-epf-test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
> index 34aac220dd4c..eed6638ab71d 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
> @@ -221,7 +221,7 @@ static int pci_epf_test_init_dma_chan(struct pci_epf_test *epf_test)
>         filter.dma_mask = BIT(DMA_MEM_TO_DEV);
>         dma_chan = dma_request_channel(mask, epf_dma_filter_fn, &filter);
>
> -       if (IS_ERR(dma_chan)) {
> +       if (!dma_chan) {
>                 dev_info(dev, "Failed to get private DMA tx channel. Falling back to generic one\n");
>                 goto fail_back_rx;
>         }
> --
> 2.35.1
>

Thanks,
Shunsuke.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: endpoint: IS_ERR() vs NULL bug in pci_epf_test_init_dma_chan()
  2022-07-11  5:50 ` Shunsuke Mie
@ 2022-07-12  7:43   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-07-12  7:43 UTC (permalink / raw)
  To: Shunsuke Mie
  Cc: Kishon Vijay Abraham I, Frank Li, dmaengine, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Bjorn Helgaas, Hou Zhiqiang, Li Chen,
	Manivannan Sadhasivam, linux-pci, kernel-janitors

On Mon, Jul 11, 2022 at 02:50:14PM +0900, Shunsuke Mie wrote:
> This patch changes for a tx dma channel. There is a similar problem for a
>  rx one too. The code doesn't cause an error, but it is likely better to
> change to just NULL checking.
> 

Yep.  Thanks.  I will resend.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-12  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08  8:41 [PATCH] PCI: endpoint: IS_ERR() vs NULL bug in pci_epf_test_init_dma_chan() Dan Carpenter
2022-07-11  5:50 ` Shunsuke Mie
2022-07-12  7:43   ` Dan Carpenter

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).