Skip to contentSkip to conversation

usb: host: fsl-mph-dr-of: check return of dma_set_mask()

PATCH In review Ran Wang 2 participants 3 messages Oct 10, 2020 – Oct 14, 2020 USB

lore
Share & tools
lore

Ran Wang

author
#0 lore raw

PATCH 1/1 usb: host: fsl-mph-dr-of: check return of dma_set_mask()

fsl_usb2_device_register() should stop init if dma_set_mask() return error.

Fixes cae058610465 ("drivers/usb/host: fsl: Set DMA_MASK of usb platform device")
---
 drivers/usb/host/fsl-mph-dr-of.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/usb/host/fsl-mph-dr-of.c +6 -3
index ae8f60f..44a7e58 100644
@@ -94,10 +94,13 @@ static struct platform_device *fsl_usb2_device_register(
 
 	pdev->dev.coherent_dma_mask = ofdev->dev.coherent_dma_mask;
 
-	if (!pdev->dev.dma_mask)
+	if (!pdev->dev.dma_mask) {
 		pdev->dev.dma_mask = &ofdev->dev.coherent_dma_mask;
-	else
-		dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+	} else {
+		retval = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+		if (retval)
+			goto error;
+	}
 
 	retval = platform_device_add_data(pdev, pdata, sizeof(*pdata));
 	if (retval)
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Ran Wang

fsl_usb2_device_register() should stop init if dma_set_mask() return error.

Fixes cae058610465 ("drivers/usb/host: fsl: Set DMA_MASK of usb platform device")
---
 drivers/usb/host/fsl-mph-dr-of.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/usb/host/fsl-mph-dr-of.c +6 -3
index ae8f60f..44a7e58 100644
@@ -94,10 +94,13 @@ static struct platform_device *fsl_usb2_device_register(
 
 	pdev->dev.coherent_dma_mask = ofdev->dev.coherent_dma_mask;
 
-	if (!pdev->dev.dma_mask)
+	if (!pdev->dev.dma_mask) {
 		pdev->dev.dma_mask = &ofdev->dev.coherent_dma_mask;
-	else
-		dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+	} else {
+		retval = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+		if (retval)
+			goto error;
+	}
 
 	retval = platform_device_add_data(pdev, pdata, sizeof(*pdata));
 	if (retval)
Signature · 1 line
2.7.4

One more place need to fix, if platform_device_alloc returns NULL, it should not call platform_device_put to release platform device memory.

	pdev = platform_device_alloc(name, id);
	if (!pdev) {
		retval = -ENOMEM;
		goto error;
	}
	...
error:
	platform_device_put(pdev);
	return ERR_PTR(retval);
Signature · 2 lines
Thanks,
Peter Chen
author
#2 lore raw

Hi Peter,

Quoted 45 lines · Peter Chen
Quoted 32 lines · Ran Wang

fsl_usb2_device_register() should stop init if dma_set_mask() return error.

Fixes cae058610465 ("drivers/usb/host: fsl: Set DMA_MASK of usb

platform device")

---
 drivers/usb/host/fsl-mph-dr-of.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/usb/host/fsl-mph-dr-of.c +6 -3
index ae8f60f..44a7e58 100644
@@ -94,10 +94,13 @@ static struct platform_device
 *fsl_usb2_device_register(
 
 	pdev->dev.coherent_dma_mask = ofdev->dev.coherent_dma_mask;
 
-	if (!pdev->dev.dma_mask)
+	if (!pdev->dev.dma_mask) {
 		pdev->dev.dma_mask = &ofdev->dev.coherent_dma_mask;
-	else
-		dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+	} else {
+		retval = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+		if (retval)
+			goto error;
+	}
 
 	retval = platform_device_add_data(pdev, pdata, sizeof(*pdata));
Quoted 4 lines

if (retval)
--
2.7.4

One more place need to fix, if platform_device_alloc returns NULL, it should not call platform_device_put to release platform device memory.

Quoted 9 lines
	pdev = platform_device_alloc(name, id);
	if (!pdev) {
		retval = -ENOMEM;
		goto error;
	}
	...
error:
	platform_device_put(pdev);
	return ERR_PTR(retval);

Got it, let me check this later.

Thanks & Regards,
Ran