All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/base: fix iterator cleanup in attribute_container
@ 2025-02-26 18:27 Ayaan Mirza Baig
  2025-02-26 19:16 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Ayaan Mirza Baig @ 2025-02-26 18:27 UTC (permalink / raw)
  To: gregkh; +Cc: dakr, linux-kernel, Ayaan Mirza Baig

This patch addresses a long-standing FIXME in
dirvers/base/attribute_container.c, where the function
failed to call klist_iter_exit() before breaking
out of the loop when a matching class device was found.

The code is now refactored to use a goto-based cleanup approach
that ensure klist_iter_exit() is invoked exactly once regardless
of the exit path.

In addition, checkpatch.pl warnings were fixed along with this change.

Tested on a minimal Debian System in QEMU with GDB attached.
No regressions or errors were observed.

Signed-off-by: Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>
---
 drivers/base/attribute_container.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index b6f941a6ab69..1e7af328dd49 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -5,7 +5,7 @@
  * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
  *
  * The basic idea here is to enable a device to be attached to an
- * aritrary numer of classes without having to allocate storage for them.
+ * aritrary number of classes without having to allocate storage for them.
  * Instead, the contained classes select the devices they need to attach
  * to via a matching function.
  */
@@ -21,7 +21,8 @@
 #include "base.h"
 
 /* This is a private structure used to tie the classdev and the
- * container .. it should never be visible outside this file */
+ * container .. it should never be visible outside this file
+ */
 struct internal_container {
 	struct klist_node node;
 	struct attribute_container *cont;
@@ -42,7 +43,6 @@ static void internal_container_klist_put(struct klist_node *n)
 	put_device(&ic->classdev);
 }
 
-
 /**
  * attribute_container_classdev_to_container - given a classdev, return the container
  *
@@ -449,7 +449,7 @@ attribute_container_remove_attrs(struct device *classdev)
 
 	if (cont->grp) {
 		sysfs_remove_group(&classdev->kobj, cont->grp);
-		return ;
+		return;
 	}
 
 	for (i = 0; attrs[i]; i++)
@@ -491,12 +491,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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-03-01  7:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26 18:27 [PATCH] drivers/base: fix iterator cleanup in attribute_container Ayaan Mirza Baig
2025-02-26 19:16 ` Greg KH
2025-02-27 12:41   ` [PATCH 1/2] drivers/base: fix checkpatch.pl warnings in attribute_container.c (v2) Ayaan Mirza Baig
2025-03-01  7:31     ` Greg KH
2025-02-27 12:41   ` [PATCH 2/2] drivers/base: fix iterator cleanup in attribute_container_find_class_device (v2) Ayaan Mirza Baig
2025-03-01  7:34     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.