LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] dmaengine: dw-edma: Fix (and simplify) the probe broken since ecb8c88bd31c
@ 2021-11-09 21:09 Christophe JAILLET
  2021-11-22  6:56 ` Vinod Koul
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2021-11-09 21:09 UTC (permalink / raw)
  To: gustavo.pimentel, vkoul, wangqing
  Cc: dmaengine, linux-kernel, kernel-janitors, Christophe JAILLET

The commit in the Fixes: tag has changed the logic of the code and now it
is likely that the probe will return an early success (0), even if not
completely executed.

This should lead to a crash or similar issue later on when the code
accesses to some never allocated resources.

Change the '!err' into a 'err' when checking if
'dma_set_mask_and_coherent()' has failed or not.

While at it, simplify the code and remove the "can't success code" related
to 32 DMA mask.
As stated in [1], 'dma_set_mask_and_coherent(DMA_BIT_MASK(64))' can't fail
if 'dev->dma_mask' is non-NULL. And if it is NULL, it would fail for the
same reason when tried with DMA_BIT_MASK(32).

[1]: https://lkml.org/lkml/2021/6/7/398

Fixes: ecb8c88bd31c ("dmaengine: dw-edma-pcie: switch from 'pci_' to 'dma_' API")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/dma/dw-edma/dw-edma-pcie.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/dma/dw-edma/dw-edma-pcie.c b/drivers/dma/dw-edma/dw-edma-pcie.c
index 198f6cd8ac1b..cee7aa231d7b 100644
--- a/drivers/dma/dw-edma/dw-edma-pcie.c
+++ b/drivers/dma/dw-edma/dw-edma-pcie.c
@@ -187,17 +187,9 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 
 	/* DMA configuration */
 	err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
-	if (!err) {
+	if (err) {
 		pci_err(pdev, "DMA mask 64 set failed\n");
 		return err;
-	} else {
-		pci_err(pdev, "DMA mask 64 set failed\n");
-
-		err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
-		if (err) {
-			pci_err(pdev, "DMA mask 32 set failed\n");
-			return err;
-		}
 	}
 
 	/* Data structure allocation */
-- 
2.30.2


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

* Re: [PATCH] dmaengine: dw-edma: Fix (and simplify) the probe broken since ecb8c88bd31c
  2021-11-09 21:09 [PATCH] dmaengine: dw-edma: Fix (and simplify) the probe broken since ecb8c88bd31c Christophe JAILLET
@ 2021-11-22  6:56 ` Vinod Koul
  2021-11-22 19:30   ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Vinod Koul @ 2021-11-22  6:56 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: gustavo.pimentel, wangqing, dmaengine, linux-kernel, kernel-janitors

On 09-11-21, 22:09, Christophe JAILLET wrote:
> The commit in the Fixes: tag has changed the logic of the code and now it
> is likely that the probe will return an early success (0), even if not
> completely executed.
> 
> This should lead to a crash or similar issue later on when the code
> accesses to some never allocated resources.
> 
> Change the '!err' into a 'err' when checking if
> 'dma_set_mask_and_coherent()' has failed or not.
> 
> While at it, simplify the code and remove the "can't success code" related
> to 32 DMA mask.
> As stated in [1], 'dma_set_mask_and_coherent(DMA_BIT_MASK(64))' can't fail
> if 'dev->dma_mask' is non-NULL. And if it is NULL, it would fail for the
> same reason when tried with DMA_BIT_MASK(32).

The patch title should describe the changes in the patch and not the
outcome! So I have taken the liberty to update this to:
dmaengine: dw-edma: Fix return value check for dma_set_mask_and_coherent()

-- 
~Vinod

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

* Re: [PATCH] dmaengine: dw-edma: Fix (and simplify) the probe broken since ecb8c88bd31c
  2021-11-22  6:56 ` Vinod Koul
@ 2021-11-22 19:30   ` Christophe JAILLET
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2021-11-22 19:30 UTC (permalink / raw)
  To: Vinod Koul
  Cc: gustavo.pimentel, wangqing, dmaengine, linux-kernel, kernel-janitors

Le 22/11/2021 à 07:56, Vinod Koul a écrit :
> On 09-11-21, 22:09, Christophe JAILLET wrote:
>> The commit in the Fixes: tag has changed the logic of the code and now it
>> is likely that the probe will return an early success (0), even if not
>> completely executed.
>>
>> This should lead to a crash or similar issue later on when the code
>> accesses to some never allocated resources.
>>
>> Change the '!err' into a 'err' when checking if
>> 'dma_set_mask_and_coherent()' has failed or not.
>>
>> While at it, simplify the code and remove the "can't success code" related
>> to 32 DMA mask.
>> As stated in [1], 'dma_set_mask_and_coherent(DMA_BIT_MASK(64))' can't fail
>> if 'dev->dma_mask' is non-NULL. And if it is NULL, it would fail for the
>> same reason when tried with DMA_BIT_MASK(32).
> 
> The patch title should describe the changes in the patch and not the
> outcome! So I have taken the liberty to update this to:
> dmaengine: dw-edma: Fix return value check for dma_set_mask_and_coherent()
> 

Hi,

In fact, this 'bad' patch title was a way for me to express my 
frustration to someone who 'stole' someone else work:
    - without letting him know about it
    - without fixing his broken patch by himself when informed
    - without taking into account others comments (Andy Shevchenko about 
64 DMA mask)

So, thanks for fixing it (and thanks to Wang Qing for pushing in the 
right direction, even if a better communication would have been 
appreciated :) )


If you could just confirmed the 64 DMA mask cleanup, it would be great 
for me. I trust the one who stated that such code could be simplified 
and I've tried to audit code to confirm it by myself.
However, this pattern looks quite common in the kernel, so I'm still 
unsure about it :( !

CJ

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

end of thread, other threads:[~2021-11-22 19:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 21:09 [PATCH] dmaengine: dw-edma: Fix (and simplify) the probe broken since ecb8c88bd31c Christophe JAILLET
2021-11-22  6:56 ` Vinod Koul
2021-11-22 19:30   ` 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).