mm/hmm/test: fix error handling in dmirror_device_init
authorMa Ke <make24@iscas.ac.cn>
Sat, 8 Nov 2025 11:53:46 +0000 (19:53 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 24 Nov 2025 23:08:50 +0000 (15:08 -0800)
commitfe9d31fd1ab6cb53e45d9d6b0bb7a62d8365fe2b
treed28d27e1bb5145193c9f4466a7b9a0f97df4a423
parent50d0598cf2c9d33e1f08c3b1a357752ea8a9b94a
mm/hmm/test: fix error handling in dmirror_device_init

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.

Link: https://lkml.kernel.org/r/20251108115346.6368-1-make24@iscas.ac.cn
Fixes: 6a760f58c792 ("mm/hmm/test: use char dev with struct device to get device node")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Cc: Haoxiang Li <make24@iscas.ac.cn>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Mika Penttilä <mpenttil@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/test_hmm.c