Skip to contentSkip to conversation

mm-hmm-test-fix-error-handling-in-dmirror_device_init.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Nov 24, 2025

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/hmm/test: fix error handling in dmirror_device_init
has been removed from the -mm tree. Its filename was
mm-hmm-test-fix-error-handling-in-dmirror_device_init.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Ma Ke <[email protected]>
Subject: mm/hmm/test: fix error handling in dmirror_device_init
Date: Sat, 8 Nov 2025 19:53:46 +0800

dmirror_device_init() calls device_initialize() which sets the device reference count to 1, but fails to call put_device() when error occurs after dev_set_name() or cdev_device_add() failures. This results in memory leaks of struct device objects. Additionally, dmirror_device_remove() lacks the final put_device() call to properly release the device reference.

Found by code review.

Fixes 6a760f58c792 ("mm/hmm/test: use char dev with struct device to get device node")
Cc Haoxiang Li <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc John Hubbard <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Mika Penttilä <[email protected]>

---

 lib/test_hmm.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/test_hmm.c renamed from lib/test_hmm.c~mm-hmm-test-fix-error-handling-in-dmirror_device_init +7 -2
@@ -1740,20 +1740,25 @@ static int dmirror_device_init(struct dm
 
 	ret = dev_set_name(&mdevice->device, "hmm_dmirror%u", id);
 	if (ret)
-		return ret;
+		goto put_device;
 
 	ret = cdev_device_add(&mdevice->cdevice, &mdevice->device);
 	if (ret)
-		return ret;
+		goto put_device;
 
 	/* Build a list of free ZONE_DEVICE struct pages */
 	return dmirror_allocate_chunk(mdevice, NULL, false);
+
+put_device:
+	put_device(&mdevice->device);
+	return ret;
 }
 
 static void dmirror_device_remove(struct dmirror_device *mdevice)
 {
 	dmirror_device_remove_chunks(mdevice);
 	cdev_device_del(&mdevice->cdevice, &mdevice->device);
+	put_device(&mdevice->device);
 }
 
 static int __init hmm_dmirror_init(void)

_

Patches currently in -mm which might be from [email protected] are