[PATCH] mtd: fix error handling in uif_init()

Ma Ke make24 at iscas.ac.cn
Thu Mar 13 02:16:09 PDT 2025


Once cdev_device_add() failed, we should call put_device() to decrement
reference count for cleanup. Or it could cause memory leak.

Found by code review.

Cc: stable at vger.kernel.org
Fixes: 493cfaeaa0c9 ("mtd: utilize new cdev_device_add helper function")
Signed-off-by: Ma Ke <make24 at iscas.ac.cn>
---
 drivers/mtd/ubi/build.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index ef6a22f372f9..ca4c54cf9fd4 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -486,6 +486,7 @@ static int uif_init(struct ubi_device *ubi)
 	kill_volumes(ubi);
 	cdev_device_del(&ubi->cdev, &ubi->dev);
 out_unreg:
+	put_device(&ubi->dev);
 	unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1);
 	ubi_err(ubi, "cannot initialize UBI %s, error %d",
 		ubi->ubi_name, err);
-- 
2.25.1




More information about the linux-mtd mailing list