* [PATCH v2] drm: renesas: rz-du: mipi_dsi: Fix return path on error
@ 2026-04-22 14:51 Chris Brandt
2026-04-22 15:02 ` Hugo Villeneuve
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Chris Brandt @ 2026-04-22 14:51 UTC (permalink / raw)
To: Biju Das, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Pavel Machek, Hugo Villeneuve
Cc: linux-renesas-soc, dri-devel, Chris Brandt, Hugo Villeneuve
In case of error, we should unwind correctly.
Switching to using dmam_ instead of dma_ and moving the code earlier
fixes the issue.
Fixes: 6f392f371650 ("drm: renesas: rz-du: Implement MIPI DSI host transfers")
Suggested-by: Pavel Machek <pavel@nabladev.com>
Signed-off-by: Chris Brandt <chris.brandt@renesas.com>
Acked-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
V1->V2:
- Need to take into account mipi_dsi_host_register was already called (Geert)
- Switch to using dmam_alloc_coherent to automate unwinding (Chris)
- Added Acked-by (Hugo)
---
drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
index 29f2b7d24fe5..b908e702b607 100644
--- a/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
+++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
@@ -1442,6 +1442,11 @@ static int rzg2l_mipi_dsi_probe(struct platform_device *pdev)
return dev_err_probe(dsi->dev, PTR_ERR(dsi->prstc),
"failed to get prst\n");
+ dsi->dcs_buf_virt = dmam_alloc_coherent(dsi->dev, RZG2L_DCS_BUF_SIZE,
+ &dsi->dcs_buf_phys, GFP_KERNEL);
+ if (!dsi->dcs_buf_virt)
+ return -ENOMEM;
+
platform_set_drvdata(pdev, dsi);
pm_runtime_enable(dsi->dev);
@@ -1474,11 +1479,6 @@ static int rzg2l_mipi_dsi_probe(struct platform_device *pdev)
if (ret < 0)
goto err_pm_disable;
- dsi->dcs_buf_virt = dma_alloc_coherent(dsi->host.dev, RZG2L_DCS_BUF_SIZE,
- &dsi->dcs_buf_phys, GFP_KERNEL);
- if (!dsi->dcs_buf_virt)
- return -ENOMEM;
-
return 0;
err_phy:
@@ -1493,8 +1493,6 @@ static void rzg2l_mipi_dsi_remove(struct platform_device *pdev)
{
struct rzg2l_mipi_dsi *dsi = platform_get_drvdata(pdev);
- dma_free_coherent(dsi->host.dev, RZG2L_DCS_BUF_SIZE, dsi->dcs_buf_virt,
- dsi->dcs_buf_phys);
mipi_dsi_host_unregister(&dsi->host);
pm_runtime_disable(&pdev->dev);
}
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm: renesas: rz-du: mipi_dsi: Fix return path on error
2026-04-22 14:51 [PATCH v2] drm: renesas: rz-du: mipi_dsi: Fix return path on error Chris Brandt
@ 2026-04-22 15:02 ` Hugo Villeneuve
2026-04-22 21:31 ` Claude review: " Claude Code Review Bot
2026-04-22 21:31 ` Claude Code Review Bot
2 siblings, 0 replies; 4+ messages in thread
From: Hugo Villeneuve @ 2026-04-22 15:02 UTC (permalink / raw)
To: Chris Brandt
Cc: Biju Das, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Pavel Machek, linux-renesas-soc,
dri-devel, Hugo Villeneuve
Hi Chris,
On Wed, 22 Apr 2026 10:51:46 -0400
Chris Brandt <chris.brandt@renesas.com> wrote:
> In case of error, we should unwind correctly.
> Switching to using dmam_ instead of dma_ and moving the code earlier
> fixes the issue.
>
> Fixes: 6f392f371650 ("drm: renesas: rz-du: Implement MIPI DSI host transfers")
> Suggested-by: Pavel Machek <pavel@nabladev.com>
> Signed-off-by: Chris Brandt <chris.brandt@renesas.com>
> Acked-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
>
> ---
> V1->V2:
> - Need to take into account mipi_dsi_host_register was already called (Geert)
> - Switch to using dmam_alloc_coherent to automate unwinding (Chris)
> - Added Acked-by (Hugo)
You should not add "Acked-by" tags if you make
modifications _after_ someone has given its Ack (unless it is just a
minor cosmetic or coding style change)...
In other words, my ack was for V1, not V2 which is quite different from
V1 :)
Don't resend a V3 just for that, I will have a look later at V2...
> ---
> drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
> index 29f2b7d24fe5..b908e702b607 100644
> --- a/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
> +++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_mipi_dsi.c
> @@ -1442,6 +1442,11 @@ static int rzg2l_mipi_dsi_probe(struct platform_device *pdev)
> return dev_err_probe(dsi->dev, PTR_ERR(dsi->prstc),
> "failed to get prst\n");
>
> + dsi->dcs_buf_virt = dmam_alloc_coherent(dsi->dev, RZG2L_DCS_BUF_SIZE,
> + &dsi->dcs_buf_phys, GFP_KERNEL);
> + if (!dsi->dcs_buf_virt)
> + return -ENOMEM;
> +
> platform_set_drvdata(pdev, dsi);
>
> pm_runtime_enable(dsi->dev);
> @@ -1474,11 +1479,6 @@ static int rzg2l_mipi_dsi_probe(struct platform_device *pdev)
> if (ret < 0)
> goto err_pm_disable;
>
> - dsi->dcs_buf_virt = dma_alloc_coherent(dsi->host.dev, RZG2L_DCS_BUF_SIZE,
> - &dsi->dcs_buf_phys, GFP_KERNEL);
> - if (!dsi->dcs_buf_virt)
> - return -ENOMEM;
> -
> return 0;
>
> err_phy:
> @@ -1493,8 +1493,6 @@ static void rzg2l_mipi_dsi_remove(struct platform_device *pdev)
> {
> struct rzg2l_mipi_dsi *dsi = platform_get_drvdata(pdev);
>
> - dma_free_coherent(dsi->host.dev, RZG2L_DCS_BUF_SIZE, dsi->dcs_buf_virt,
> - dsi->dcs_buf_phys);
> mipi_dsi_host_unregister(&dsi->host);
> pm_runtime_disable(&pdev->dev);
> }
> --
> 2.52.0
>
>
--
Hugo Villeneuve
^ permalink raw reply [flat|nested] 4+ messages in thread
* Claude review: drm: renesas: rz-du: mipi_dsi: Fix return path on error
2026-04-22 14:51 [PATCH v2] drm: renesas: rz-du: mipi_dsi: Fix return path on error Chris Brandt
2026-04-22 15:02 ` Hugo Villeneuve
2026-04-22 21:31 ` Claude review: " Claude Code Review Bot
@ 2026-04-22 21:31 ` Claude Code Review Bot
2 siblings, 0 replies; 4+ messages in thread
From: Claude Code Review Bot @ 2026-04-22 21:31 UTC (permalink / raw)
To: dri-devel-reviews
Overall Series Review
Subject: drm: renesas: rz-du: mipi_dsi: Fix return path on error
Author: Chris Brandt <chris.brandt@renesas.com>
Patches: 2
Reviewed: 2026-04-23T07:31:41.505756
---
This is a single-patch fix for a resource leak bug in the RZ/G2L MIPI DSI driver's probe function. The original code calls `dma_alloc_coherent` after `mipi_dsi_host_register` and `pm_runtime_enable`, but on failure returns `-ENOMEM` directly — skipping the cleanup of the host registration and pm_runtime. The fix takes a clean approach: switch to the device-managed `dmam_alloc_coherent` and move the allocation earlier in probe, before any resources that would need unwinding. This is a well-structured v2 addressing reviewer feedback.
**Verdict: Looks good to merge.**
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 4+ messages in thread
* Claude review: drm: renesas: rz-du: mipi_dsi: Fix return path on error
2026-04-22 14:51 [PATCH v2] drm: renesas: rz-du: mipi_dsi: Fix return path on error Chris Brandt
2026-04-22 15:02 ` Hugo Villeneuve
@ 2026-04-22 21:31 ` Claude Code Review Bot
2026-04-22 21:31 ` Claude Code Review Bot
2 siblings, 0 replies; 4+ messages in thread
From: Claude Code Review Bot @ 2026-04-22 21:31 UTC (permalink / raw)
To: dri-devel-reviews
Patch Review
**The bug (confirmed in tree):** In the current code at line 1476-1479 of `rzg2l_mipi_dsi.c`:
```c
dsi->dcs_buf_virt = dma_alloc_coherent(dsi->host.dev, RZG2L_DCS_BUF_SIZE,
&dsi->dcs_buf_phys, GFP_KERNEL);
if (!dsi->dcs_buf_virt)
return -ENOMEM;
```
This bare `return -ENOMEM` leaks two resources:
1. The `mipi_dsi_host_register` at line 1472 is never unregistered.
2. The `pm_runtime_enable` at line 1446 is never disabled.
**The fix is correct and clean:**
1. **`dma_alloc_coherent` → `dmam_alloc_coherent`**: The managed variant ties the DMA buffer lifetime to the device via devres, so no explicit free is needed. This eliminates the `dma_free_coherent` call in `rzg2l_mipi_dsi_remove`, which is correct.
2. **Moving allocation before `platform_set_drvdata` / `pm_runtime_enable`**: At this point in probe, only `devm_`-managed resources (clocks, resets, ioremap) have been acquired. A plain `return -ENOMEM` is safe here — all prior allocations are device-managed and will be cleaned up automatically. The DMA buffer isn't used until actual DSI host transfers, so early allocation is fine.
3. **Device parameter change**: The original used `dsi->host.dev`, the new code uses `dsi->dev`. This is correct because `dsi->host.dev` hasn't been assigned yet at the new call site, and they are set to the same value anyway (line 1470: `dsi->host.dev = dsi->dev`).
**Minor observations (not blocking):**
- The commit message could be slightly more explicit about *what* was leaking (host registration + pm_runtime), but "unwind correctly" is adequate for a Fixes patch.
- The ordering in `remove` now has `mipi_dsi_host_unregister` first and `pm_runtime_disable` second, with the DMA free handled by devres (which runs after `remove` returns). This ordering is correct — devres cleanup happens during device unbind after the driver's remove callback.
**No issues found. Patch is ready.**
Reviewed-by: Dave Airlie <airlied@gmail.com>
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-22 21:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-22 14:51 [PATCH v2] drm: renesas: rz-du: mipi_dsi: Fix return path on error Chris Brandt
2026-04-22 15:02 ` Hugo Villeneuve
2026-04-22 21:31 ` Claude review: " Claude Code Review Bot
2026-04-22 21:31 ` Claude Code Review Bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox