[PATCH 2/2] drivers/base: fix iterator cleanup in attribute_container_find_class_device (v2)
From: Ayaan Mirza Baig
Date: Thu Feb 27 2025 - 07:45:46 EST
This patch fixes a long-standing FIXME by refactoring
the function to ensure klist_iter_exit() is always
invoked once via a unified cleanup path
The patch has been tested thoroughly with a minimal
Debain System and scsi devices and GDB.
Tested-by: Ayaan Mirza Baig <ayaanmirzabaig85@xxxxxxxxx>
Signed-off-by: Ayaan Mirza Baig <ayaanmirzabaig85@xxxxxxxxx>
---
drivers/base/attribute_container.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 69637b2ec3bc..fbf7fd45651e 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -492,12 +492,11 @@ attribute_container_find_class_device(struct attribute_container *cont,
klist_for_each_entry(ic, &cont->containers, node, &iter) {
if (ic->classdev.parent == dev) {
cdev = &ic->classdev;
- /* FIXME: must exit iterator then break */
- klist_iter_exit(&iter);
- break;
+ goto out;
}
}
-
+out:
+ klist_iter_exit(&iter);
return cdev;
}
EXPORT_SYMBOL_GPL(attribute_container_find_class_device);
--
2.47.1