mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] driver: call devinfo_del() during free_device_res()
@ 2025-11-27 11:34 Sascha Hauer
  2025-11-27 11:34 ` [PATCH 2/3] driver: call free_device_res() from unregister_device() Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-11-27 11:34 UTC (permalink / raw)
  To: Barebox List

devinfo_del() can safely be called mutiple times. Call it from
free_device_res() so that remaining resources are freed before the
device goes out of scope.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/base/driver.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index eca23d7c30..eefed4b1a5 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -348,6 +348,7 @@ EXPORT_SYMBOL(unregister_device);
  */
 void free_device_res(struct device *dev)
 {
+	devinfo_del(dev, NULL);
 	free(dev->unique_name);
 	dev->unique_name = NULL;
 	free(dev->deferred_probe_reason);
@@ -825,10 +826,11 @@ void devinfo_del(struct device *dev, void (*info)(struct device *))
 	devinfo_init(dev);
 
 	list_for_each_entry_safe(cb, tmp, &dev->info_list, list) {
-		if (cb->info == info) {
-			list_del(&cb->list);
-			free(cb);
-		}
+		if (info && cb->info != info)
+			continue;
+
+		list_del(&cb->list);
+		free(cb);
 	}
 }
 
-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] driver: call free_device_res() from unregister_device()
  2025-11-27 11:34 [PATCH 1/3] driver: call devinfo_del() during free_device_res() Sascha Hauer
@ 2025-11-27 11:34 ` Sascha Hauer
  2025-11-27 11:34 ` [PATCH 3/3] dm: fix memory leak Sascha Hauer
  2025-11-28  7:11 ` [PATCH 1/3] driver: call devinfo_del() during free_device_res() Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-11-27 11:34 UTC (permalink / raw)
  To: Barebox List

free_device_res() frees dynamically allocated resources allocated during
device lifetime. These are no longer needed when the device is
unregistered, so we can free them in unregister_device(). With this
free_device_res() might be called multiple times, so set
dev->deferred_probe_reason to NULL after freeing it to avoid double
frees.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/base/driver.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index eefed4b1a5..753e06963b 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -335,6 +335,8 @@ int unregister_device(struct device *old_dev)
 	if (np && np->dev == old_dev)
 		np->dev = NULL;
 
+	free_device_res(old_dev);
+
 	return 0;
 }
 EXPORT_SYMBOL(unregister_device);
@@ -352,6 +354,7 @@ void free_device_res(struct device *dev)
 	free(dev->unique_name);
 	dev->unique_name = NULL;
 	free(dev->deferred_probe_reason);
+	dev->deferred_probe_reason = NULL;
 }
 EXPORT_SYMBOL(free_device_res);
 
-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] dm: fix memory leak
  2025-11-27 11:34 [PATCH 1/3] driver: call devinfo_del() during free_device_res() Sascha Hauer
  2025-11-27 11:34 ` [PATCH 2/3] driver: call free_device_res() from unregister_device() Sascha Hauer
@ 2025-11-27 11:34 ` Sascha Hauer
  2025-11-28  7:11 ` [PATCH 1/3] driver: call devinfo_del() during free_device_res() Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-11-27 11:34 UTC (permalink / raw)
  To: Barebox List

The cdev name is never freed, add missing free.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/block/dm/dm-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/block/dm/dm-core.c b/drivers/block/dm/dm-core.c
index fd7ed0d84e..18e4fd2440 100644
--- a/drivers/block/dm/dm-core.c
+++ b/drivers/block/dm/dm-core.c
@@ -443,6 +443,7 @@ void dm_destroy(struct dm_device *dm)
 	struct dm_target *ti, *tmp;
 
 	blockdevice_unregister(&dm->blk);
+	free(dm->blk.cdev.name);
 
 	list_for_each_entry_safe_reverse(ti, tmp, &dm->targets, list) {
 		ti->ops->destroy(ti);
-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] driver: call devinfo_del() during free_device_res()
  2025-11-27 11:34 [PATCH 1/3] driver: call devinfo_del() during free_device_res() Sascha Hauer
  2025-11-27 11:34 ` [PATCH 2/3] driver: call free_device_res() from unregister_device() Sascha Hauer
  2025-11-27 11:34 ` [PATCH 3/3] dm: fix memory leak Sascha Hauer
@ 2025-11-28  7:11 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-11-28  7:11 UTC (permalink / raw)
  To: Barebox List, Sascha Hauer


On Thu, 27 Nov 2025 12:34:14 +0100, Sascha Hauer wrote:
> devinfo_del() can safely be called mutiple times. Call it from
> free_device_res() so that remaining resources are freed before the
> device goes out of scope.
> 
> 

Applied, thanks!

[1/3] driver: call devinfo_del() during free_device_res()
      https://git.pengutronix.de/cgit/barebox/commit/?id=cc7a9c100cac (link may not be stable)
[2/3] driver: call free_device_res() from unregister_device()
      https://git.pengutronix.de/cgit/barebox/commit/?id=d7a298c1cdb4 (link may not be stable)
[3/3] dm: fix memory leak
      https://git.pengutronix.de/cgit/barebox/commit/?id=5d0acf308a31 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-28  7:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-27 11:34 [PATCH 1/3] driver: call devinfo_del() during free_device_res() Sascha Hauer
2025-11-27 11:34 ` [PATCH 2/3] driver: call free_device_res() from unregister_device() Sascha Hauer
2025-11-27 11:34 ` [PATCH 3/3] dm: fix memory leak Sascha Hauer
2025-11-28  7:11 ` [PATCH 1/3] driver: call devinfo_del() during free_device_res() Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox