Skip to contentSkip to conversation

PCI: endpoint: IS_ERR() vs NULL bug in pci_epf_test_init_dma_chan()

PATCH Superseded Dan Carpenter 2 participants 3 messages Jul 8, 2022 – Jul 12, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: endpoint: IS_ERR() vs NULL bug in pci_epf_test_init_dma_chan()

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

---
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(-)
drivers/pci/endpoint/functions/pci-epf-test.c +1 -1
index 34aac220dd4c..eed6638ab71d 100644
@@ -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;
 	}
Signature · 1 line
2.35.1
#1 lore raw

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 <[email protected]>:

Quoted 29 lines

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

---
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(-)
drivers/pci/endpoint/functions/pci-epf-test.c +1 -2
index 34aac220dd4c..eed6638ab71d 100644
@@ -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;
        }
--
Quoted 2 lines

2.35.1

Thanks,
Shunsuke.

#2 lore raw
Quoted 4 lines · Shunsuke Mie

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