* [PATCH v3] drm: renesas: rz-du: mipi_dsi: Fix return path on error
@ 2026-05-01 13:21 Chris Brandt
2026-05-04 23:27 ` Claude review: " Claude Code Review Bot
2026-05-04 23:27 ` Claude Code Review Bot
0 siblings, 2 replies; 5+ messages in thread
From: Chris Brandt @ 2026-05-01 13:21 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
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>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
---
V2->V3:
- Removed Acked-by because it was for V1 (Hugo)
- Added Reviewed-by (Biju)
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] 5+ messages in thread* Claude review: drm: renesas: rz-du: mipi_dsi: Fix return path on error
2026-05-01 13:21 [PATCH v3] drm: renesas: rz-du: mipi_dsi: Fix return path on error Chris Brandt
@ 2026-05-04 23:27 ` Claude Code Review Bot
2026-05-04 23:27 ` Claude Code Review Bot
1 sibling, 0 replies; 5+ messages in thread
From: Claude Code Review Bot @ 2026-05-04 23:27 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: 1
Reviewed: 2026-05-05T09:27:22.127017
---
This is a single-patch series (v3) that fixes an error-handling bug in the Renesas RZ MIPI DSI probe path. The original code had two problems:
1. **Missing error unwind**: The `dma_alloc_coherent()` call was placed after `mipi_dsi_host_register()`, and on failure it did `return -ENOMEM` directly — skipping the `err_pm_disable` cleanup label, which means `pm_runtime_disable()` and `mipi_dsi_host_unregister()` were never called on that error path.
2. **Leaked DMA allocation**: Since plain `dma_alloc_coherent()` was used, any other error path that went through the `err_phy` / `err_pm_disable` labels would also leak the DMA buffer (though in practice this was unreachable since the alloc came last).
The fix is clean and correct: switch to `dmam_alloc_coherent()` (device-managed) and move it earlier in the probe function — before `platform_set_drvdata()` and `pm_runtime_enable()` — so that on failure, a simple `return -ENOMEM` is sufficient (no cleanup needed at that point), and the buffer is automatically freed on device removal. The corresponding `dma_free_coherent()` in `remove()` is correctly dropped.
The patch has a `Fixes:` tag, a `Reviewed-by` from Biju Das, is on its third revision addressing prior review feedback, and the changelog is well documented. **Recommend: Accept.**
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 5+ messages in thread
* Claude review: drm: renesas: rz-du: mipi_dsi: Fix return path on error
2026-05-01 13:21 [PATCH v3] drm: renesas: rz-du: mipi_dsi: Fix return path on error Chris Brandt
2026-05-04 23:27 ` Claude review: " Claude Code Review Bot
@ 2026-05-04 23:27 ` Claude Code Review Bot
1 sibling, 0 replies; 5+ messages in thread
From: Claude Code Review Bot @ 2026-05-04 23:27 UTC (permalink / raw)
To: dri-devel-reviews
Patch Review
**Bug analysis**: In the original code, `dma_alloc_coherent()` was the last operation in `rzg2l_mipi_dsi_probe()`, placed after `mipi_dsi_host_register()`. On allocation failure it executed:
```c
return -ENOMEM;
```
This bypassed the error cleanup labels (`err_phy`, `err_pm_disable`), leaking the `pm_runtime_enable()` state and the registered MIPI DSI host.
**Fix correctness**:
The allocation is moved to before `platform_set_drvdata()` and `pm_runtime_enable()`:
```c
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;
```
At this point in the probe function, only `devm_*` managed resources have been acquired (clocks, resets, ioremap), so a plain `return` is safe — `devm` teardown handles everything. The switch from `dma_alloc_coherent` to `dmam_alloc_coherent` is the right choice: it's the device-managed variant, so the buffer is automatically freed when the device is unbound, eliminating the need for the explicit `dma_free_coherent()` in `remove()`.
**Remove path**: The `dma_free_coherent()` call is correctly removed from `rzg2l_mipi_dsi_remove()` since `dmam_alloc_coherent()` handles cleanup automatically.
**Device argument consistency**: The original code used `dsi->host.dev` as the device for `dma_alloc_coherent()` / `dma_free_coherent()`, while the new code uses `dsi->dev`. Looking at the probe function, `dsi->host.dev` is assigned to `dsi->dev` later in the function (line 1475: `dsi->host.dev = dsi->dev`), so using `dsi->dev` directly is correct and actually necessary since `dsi->host.dev` isn't set yet at the new call site.
**No issues found.** The patch is minimal, well-targeted, and correctly fixes both the immediate error-path bug and the broader resource management concern by using the managed API.
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] drm: renesas: rz-du: mipi_dsi: Fix return path on error
@ 2026-04-22 14:51 Chris Brandt
2026-04-22 21:31 ` Claude review: " Claude Code Review Bot
2026-04-22 21:31 ` Claude Code Review Bot
0 siblings, 2 replies; 5+ 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] 5+ messages in thread* Claude review: drm: renesas: rz-du: mipi_dsi: Fix return path on error
2026-04-22 14:51 [PATCH v2] " Chris Brandt
@ 2026-04-22 21:31 ` Claude Code Review Bot
2026-04-22 21:31 ` Claude Code Review Bot
1 sibling, 0 replies; 5+ 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] 5+ messages in thread* Claude review: drm: renesas: rz-du: mipi_dsi: Fix return path on error
2026-04-22 14:51 [PATCH v2] " Chris Brandt
2026-04-22 21:31 ` Claude review: " Claude Code Review Bot
@ 2026-04-22 21:31 ` Claude Code Review Bot
1 sibling, 0 replies; 5+ 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] 5+ messages in thread
end of thread, other threads:[~2026-05-04 23:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-01 13:21 [PATCH v3] drm: renesas: rz-du: mipi_dsi: Fix return path on error Chris Brandt
2026-05-04 23:27 ` Claude review: " Claude Code Review Bot
2026-05-04 23:27 ` Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-04-22 14:51 [PATCH v2] " Chris Brandt
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