[PATCH 2/2] scsi: target: tcmu: Fix memory leak by using new uio callback
From: Bodo Stroesser
Date: Wed Feb 10 2021 - 14:43:40 EST
Use new uio_info->late_release callback to fix memory leak.
If userspace daemon still holds uio device open or mmap'ed while
tcmu device is removed from configFS, refcount of the tcmu device
never drops down to 0, because uio does not call
uio_info->release - which is tcmu_release - after tcmu had
executed uio_unregister_device. So tcmu device and its allocated
resources are not freed in this situation.
tcmu now sets uio_info->late_release which is called by uio in
the described situation. That way the memory leak is fixed.
Signed-off-by: Bodo Stroesser <bostroesser@xxxxxxxxx>
---
drivers/target/target_core_user.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 6b171fff007b..bf61705ca92b 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -2092,6 +2092,7 @@ static int tcmu_configure_device(struct se_device *dev)
info->mmap = tcmu_mmap;
info->open = tcmu_open;
info->release = tcmu_release;
+ info->late_release = tcmu_release;
ret = uio_register_device(tcmu_root_device, info);
if (ret)
--
2.12.3