dma_set_mask_and_coherent() can fail when platform DMA operations do not
support the requested 40-bit address mask. Ignoring the error leaves the
previous DMA configuration in place. Probe then continues without ensuring
that DMA addresses are suitable for the NPU.

Return the error so the driver does not bind with an unsupported DMA
configuration.

Fixes: 5a5e9c0228e6 ("accel: Add Arm Ethos-U NPU driver")
Cc: [email protected]
Reported-by: Sashiko <[email protected]>
Link: 
https://sashiko.dev/#/patchset/[email protected]?part=1
Signed-off-by: GuoHan Zhao <[email protected]>
---
New in v2.

Sashiko report:

> This is a pre-existing issue, but does this code ignore the return value of
> dma_set_mask_and_coherent() which is called earlier in ethosu_probe()?
>
> If the platform only supports 32-bit DMA and the call fails, the default
> 32-bit mask is retained. The DRM core and driver might proceed assuming
> 40-bit DMA is active, handing the NPU physical addresses greater than 4 GB,
> which could lead to silent DMA address truncation and memory corruption.

 drivers/accel/ethosu/ethosu_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/ethosu/ethosu_drv.c 
b/drivers/accel/ethosu/ethosu_drv.c
index ed9c748a54ad..f3920185389d 100644
--- a/drivers/accel/ethosu/ethosu_drv.c
+++ b/drivers/accel/ethosu/ethosu_drv.c
@@ -339,7 +339,9 @@ static int ethosu_probe(struct platform_device *pdev)
                return -ENOMEM;
        platform_set_drvdata(pdev, ethosudev);
 
-       dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
+       ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
+       if (ret)
+               return ret;
 
        ethosudev->regs = devm_platform_ioremap_resource(pdev, 0);
 
-- 
2.43.0

Reply via email to