drm/bridge: samsung-dsim: Fix memory leak in error path
Subsystems (4)
PATCH 1/1 drm/bridge: samsung-dsim: Fix memory leak in error path
In samsung_dsim_host_attach(), drm_bridge_add() is called to add the bridge. However, if samsung_dsim_register_te_irq() or pdata->host_ops->attach() fails afterwards, the function returns without removing the bridge, causing a memory leak.
Fix this by adding proper error handling with goto labels to ensure drm_bridge_remove() is called in all error paths. Also ensure that samsung_dsim_unregister_te_irq() is called if the attach operation fails after the TE IRQ has been registered.
--- drivers/gpu/drm/bridge/samsung-dsim.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/samsung-dsim.c +11 -2
@@ -1881,6 +1881,8 @@ static int samsung_dsim_register_te_irq(struct samsung_dsim *dsi, struct devicereturn 0 ; } +static void samsung_dsim_unregister_te_irq (struct samsung_dsim *dsi); +static int samsung_dsim_host_attach (struct mipi_dsi_host *host,struct mipi_dsi_device *device) {
@@ -1955,13 +1957,13 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO )) { ret =samsung_dsim_register_te_irq (dsi, &device->dev);if (ret) -return ret; + goto err_remove_bridge; }if (pdata->host_ops && pdata->host_ops->attach) { ret = pdata->host_ops->attach (dsi, device);if (ret) -return ret; + goto err_unregister_te_irq; } dsi->lanes = device->lanes;
@@ -1969,6 +1971,13 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host, dsi->mode_flags = device->mode_flags;return 0 ; + +err_unregister_te_irq: +if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO )) +samsung_dsim_unregister_te_irq (dsi); +err_remove_bridge: +drm_bridge_remove (&dsi->bridge); +return ret; }static void samsung_dsim_unregister_te_irq (struct samsung_dsim *dsi)
Signature · 1 line
2.43.0
Luca Ceresoli
reviewerHello Osama,
Quoted 11 lines · Osama Abdelkader
In
samsung_dsim_host_attach(),drm_bridge_add()is called to add the bridge. However, ifsamsung_dsim_register_te_irq()orpdata->host_ops->attach()fails afterwards, the function returns without removing the bridge, causing a memory leak.Fix this by adding proper error handling with goto labels to ensure
drm_bridge_remove()is called in all error paths. Also ensure thatsamsung_dsim_unregister_te_irq()is called if the attach operation fails after the TE IRQ has been registered.Signed-off-by Osama Abdelkader <[email protected]>
Good catch!
However being a fix you need a 'Fixes:' line pointing to the first commit where hte bug exists. At a quick search it looks like f9bfd326f57e, but please double check that. And with a Fixes tag you need Cc: stable, see the docs [0].
drivers/gpu/drm/bridge/samsung-dsim.c static int samsung_dsim_register_te_irq(struct samsung_dsim *dsi, struct device · line 1884
Quoted 7 lines
drivers/gpu/drm/bridge/samsung-dsim.c +1
-0@@ -1881,6 +1881,8 @@ static int samsung_dsim_register_te_irq(struct samsung_dsim *dsi, struct devicereturn 0 ; } +static void samsung_dsim_unregister_te_irq (struct samsung_dsim *dsi);
Please don't add a forward declaration. Just move samsung_dsim_unregister_te_irq() function earlier, perhaps right here. Also mention in the commit message that you have just moved it without changes, to help reviewers: unfortunately code being moved it not very well visualized in a diff.
Otherwise looks good!
It would be great if you please add me in Cc for future patches to this driver. I'm using and touching it [1][2] so I'd like to review patches touching it. Thanks!
[0] https://docs.kernel.org/process/stable-kernel-rules.html
[1] https://lore.kernel.org/lkml/20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-0-8bad3ef90b9f@bootlin.com/
[2] https://lore.kernel.org/lkml/20260206-drm-bridge-atomic-vs-remove-clear_and_put-v1-2-6f1a7d03c45f@bootlin.com/
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Quoted 36 lines · Luca Ceresoli
Hello Osama,
Quoted 11 lines · Osama Abdelkader
In
samsung_dsim_host_attach(),drm_bridge_add()is called to add the bridge. However, ifsamsung_dsim_register_te_irq()orpdata->host_ops->attach()fails afterwards, the function returns without removing the bridge, causing a memory leak.Fix this by adding proper error handling with goto labels to ensure
drm_bridge_remove()is called in all error paths. Also ensure thatsamsung_dsim_unregister_te_irq()is called if the attach operation fails after the TE IRQ has been registered.Signed-off-by Osama Abdelkader <[email protected]>Good catch!
However being a fix you need a 'Fixes:' line pointing to the first commit where hte bug exists. At a quick search it looks like
f9bfd326f57e, but please double check that. And with a Fixes tag you need Cc: stable, see the docs [0].drivers/gpu/drm/bridge/samsung-dsim.c static int samsung_dsim_register_te_irq(struct samsung_dsim *dsi, struct device · line 1884
Quoted 7 lines
drivers/gpu/drm/bridge/samsung-dsim.c +1
-0@@ -1881,6 +1881,8 @@ static int samsung_dsim_register_te_irq(struct samsung_dsim *dsi, struct devicereturn 0 ; } +static void samsung_dsim_unregister_te_irq (struct samsung_dsim *dsi);Please don't add a forward declaration. Just move
samsung_dsim_unregister_te_irq()function earlier, perhaps right here. Also mention in the commit message that you have just moved it without changes, to help reviewers: unfortunately code being moved it not very well visualized in a diff.
Quoted 5 lines
Otherwise looks good!
It would be great if you please add me in Cc for future patches to this driver. I'm using and touching it [1][2] so I'd like to review patches touching it. Thanks!
Sure, I will.
Thanks for letting me know.
Quoted 11 lines
[0] https://docs.kernel.org/process/stable-kernel-rules.html
[1] https://lore.kernel.org/lkml/20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-0-8bad3ef90b9f@bootlin.com/
[2] https://lore.kernel.org/lkml/20260206-drm-bridge-atomic-vs-remove-clear_and_put-v1-2-6f1a7d03c45f@bootlin.com/Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Hello Luca,
Thank you for the review, I just did that in v2.
Thanks,
Osama