* [PATCH] mfd: stm32-timers: depopulate child devices on populate failure
@ 2026-06-15 6:30 Pengpeng Hou
2026-07-01 21:42 ` Lee Jones
0 siblings, 1 reply; 4+ messages in thread
From: Pengpeng Hou @ 2026-06-15 6:30 UTC (permalink / raw)
To: Fabrice Gasnier, Lee Jones, Maxime Coquelin, Alexandre Torgue,
linux-stm32, linux-arm-kernel, linux-kernel
Cc: pengpeng
stm32_timers_probe() releases the timer DMA resources when
of_platform_populate() fails, but it does not depopulate any child
devices that were created before the failure.
The remove path explicitly depopulates child devices before releasing
DMA resources to avoid races with children using DMA. Apply the same
ordering on the populate failure path.
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
drivers/mfd/stm32-timers.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c
index b3dbc02aaf79..1f0aecae83a5 100644
--- a/drivers/mfd/stm32-timers.c
+++ b/drivers/mfd/stm32-timers.c
@@ -329,8 +329,10 @@ static int stm32_timers_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ddata);
ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
- if (ret)
+ if (ret) {
+ of_platform_depopulate(&pdev->dev);
stm32_timers_dma_remove(dev, ddata);
+ }
return ret;
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] mfd: stm32-timers: depopulate child devices on populate failure
2026-06-15 6:30 [PATCH] mfd: stm32-timers: depopulate child devices on populate failure Pengpeng Hou
@ 2026-07-01 21:42 ` Lee Jones
2026-07-03 6:50 ` Pengpeng Hou
0 siblings, 1 reply; 4+ messages in thread
From: Lee Jones @ 2026-07-01 21:42 UTC (permalink / raw)
To: Pengpeng Hou
Cc: Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
linux-arm-kernel, linux-kernel
On Mon, 15 Jun 2026, Pengpeng Hou wrote:
> stm32_timers_probe() releases the timer DMA resources when
> of_platform_populate() fails, but it does not depopulate any child
> devices that were created before the failure.
>
> The remove path explicitly depopulates child devices before releasing
> DMA resources to avoid races with children using DMA. Apply the same
> ordering on the populate failure path.
>
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> ---
> drivers/mfd/stm32-timers.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c
> index b3dbc02aaf79..1f0aecae83a5 100644
> --- a/drivers/mfd/stm32-timers.c
> +++ b/drivers/mfd/stm32-timers.c
> @@ -329,8 +329,10 @@ static int stm32_timers_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, ddata);
>
> ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
> - if (ret)
> + if (ret) {
> + of_platform_depopulate(&pdev->dev);
It's strange to see an un-winder inside the error handling of its
original call. We're used to seeing them called only on success during
a subsequent step.
Wouldn't devm_of_platform_populate() be better here instead?
> stm32_timers_dma_remove(dev, ddata);
> + }
>
> return ret;
> }
> --
> 2.50.1 (Apple Git-155)
>
--
Lee Jones
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mfd: stm32-timers: depopulate child devices on populate failure
2026-07-01 21:42 ` Lee Jones
@ 2026-07-03 6:50 ` Pengpeng Hou
2026-07-03 7:47 ` Lee Jones
0 siblings, 1 reply; 4+ messages in thread
From: Pengpeng Hou @ 2026-07-03 6:50 UTC (permalink / raw)
To: Lee Jones
Cc: Pengpeng Hou, Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue,
linux-stm32, linux-arm-kernel, linux-kernel
Hi Lee,
Thanks for taking a look.
I checked devm_of_platform_populate(), but I don't think it covers this
particular failure path on its own.
devm_of_platform_populate() only installs the devres cleanup after
of_platform_populate() has returned success. If of_platform_populate()
returns an error after creating some earlier children, the helper just
frees its devres record and those partial children are not depopulated.
For stm32-timers, I think we still need the explicit ordering used by
remove: depopulate children before stm32_timers_dma_remove(). The child
drivers get the parent drvdata, and the PWM child can call the parent
stm32_timers_dma_burst_read() helper, so releasing the parent DMA
channels while partially-created children remain would keep the same
ordering problem the remove path avoids.
I agree the inline unwind is not the clearest form. I can send a v2
using a normal goto unwind label and a short comment explaining the
partial-populate case, unless you prefer a different shape.
Thanks,
Pengpeng
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mfd: stm32-timers: depopulate child devices on populate failure
2026-07-03 6:50 ` Pengpeng Hou
@ 2026-07-03 7:47 ` Lee Jones
0 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2026-07-03 7:47 UTC (permalink / raw)
To: Pengpeng Hou
Cc: Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
linux-arm-kernel, linux-kernel
On Fri, 03 Jul 2026, Pengpeng Hou wrote:
> Hi Lee,
>
> Thanks for taking a look.
>
> I checked devm_of_platform_populate(), but I don't think it covers this
> particular failure path on its own.
>
> devm_of_platform_populate() only installs the devres cleanup after
> of_platform_populate() has returned success. If of_platform_populate()
> returns an error after creating some earlier children, the helper just
> frees its devres record and those partial children are not depopulated.
>
> For stm32-timers, I think we still need the explicit ordering used by
> remove: depopulate children before stm32_timers_dma_remove(). The child
> drivers get the parent drvdata, and the PWM child can call the parent
> stm32_timers_dma_burst_read() helper, so releasing the parent DMA
> channels while partially-created children remain would keep the same
> ordering problem the remove path avoids.
>
> I agree the inline unwind is not the clearest form. I can send a v2
> using a normal goto unwind label and a short comment explaining the
> partial-populate case, unless you prefer a different shape.
I'm not concerned about where in the file the call sits. Calls like
this that fail usually do so cleanly. I think this deserves a wider
piece of work that ensures that of_platform_populate() doesn't leave
dangling resources when it fails.
Also, why doesn't every call to of_platform_populate() have this?
--
Lee Jones
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-03 7:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-15 6:30 [PATCH] mfd: stm32-timers: depopulate child devices on populate failure Pengpeng Hou
2026-07-01 21:42 ` Lee Jones
2026-07-03 6:50 ` Pengpeng Hou
2026-07-03 7:47 ` Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox