Skip to contentSkip to conversation

misc: pci_endpoint_test: Refactor dma_set_mask_and_coherent() logic

PATCH Applied Frank Li 3 participants 3 messages May 2, 2024 – May 17, 2024

Subsystems (4)
lore
Share & tools
lore

Frank Li

author maintainer
#0 lore raw

PATCH v2 1/1 misc: pci_endpoint_test: Refactor dma_set_mask_and_coherent() logic

dma_set_mask_and_coherent() should never fail when the mask is >= 32bit, unless the architecture has no DMA support. So no need check for the error and also no need to set dma_set_mask_and_coherent(32) as a fallback.

Even if dma_set_mask_and_coherent(48) fails due to the lack of DMA support (theoretically), then dma_set_mask_and_coherent(32) will also fail for the same reason. So the fallback doesn't make sense.

Due to the above reasons, let's simplify the code by setting the streaming and coherent DMA mask to 48 bits.

---

Notes:
Change from v1 to v2:
- Rework commit message according to mani's feedback.
- Not sure why set to 48bit at original patch.

Ref: https://lore.kernel.org/linux-pci/[email protected]/T/#u

for document change patch. DMA document sample code is miss leading. fixed patch already accepted:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=f7ae20f2fc4e6a5e32f43c4fa2acab3281a61c81

 drivers/misc/pci_endpoint_test.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/misc/pci_endpoint_test.c +1 -5
index c38a6083f0a73..56ac6969a8f59 100644
@@ -824,11 +824,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,
 	init_completion(&test->irq_raised);
 	mutex_init(&test->mutex);
 
-	if ((dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48)) != 0) &&
-	    dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
-		dev_err(dev, "Cannot set DMA mask\n");
-		return -EINVAL;
-	}
+	dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48));
 
 	err = pci_enable_device(pdev);
 	if (err) {
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Frank Li

dma_set_mask_and_coherent() should never fail when the mask is >= 32bit, unless the architecture has no DMA support. So no need check for the error and also no need to set dma_set_mask_and_coherent(32) as a fallback.

Even if dma_set_mask_and_coherent(48) fails due to the lack of DMA support (theoretically), then dma_set_mask_and_coherent(32) will also fail for the same reason. So the fallback doesn't make sense.

Quoted 6 lines

Due to the above reasons, let's simplify the code by setting the streaming and coherent DMA mask to 48 bits.

---

#2 lore raw
In reply to Frank Li

Hello,

Quoted 10 lines

dma_set_mask_and_coherent() should never fail when the mask is >= 32bit, unless the architecture has no DMA support. So no need check for the error and also no need to set dma_set_mask_and_coherent(32) as a fallback.

Even if dma_set_mask_and_coherent(48) fails due to the lack of DMA support (theoretically), then dma_set_mask_and_coherent(32) will also fail for the same reason. So the fallback doesn't make sense.

Due to the above reasons, let's simplify the code by setting the streaming and coherent DMA mask to 48 bits.

Applied to misc, thank you!

[1/1] misc: pci_endpoint_test: Refactor dma_set_mask_and_coherent() logic

      https://git.kernel.org/pci/pci/c/27ea748a3abd

	Krzysztof