drivers/base/attribute_container.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
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
On Wed, Feb 26, 2025 at 11:57:52PM +0530, Ayaan Mirza Baig wrote:
> 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.
Nit, why change this in this commit?
> * 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
> + */
Same for this one?
> 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);
> }
>
> -
> /**
And this?
I stopped reading here, please, if you are going to make logic changes,
just do that, don't mix things up in one larger commit, that's not how
we handle kernel patches at all.
Also, did you test a system that uses container devices?
thanks,
greg k-h
This patch applies only cosmetic changes such as
whitespace fixes, formatting and typos. These
changes are flagged by checkpatch.pl
Signed-off-by: Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>
---
drivers/base/attribute_container.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index b6f941a6ab69..69637b2ec3bc 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;
@@ -449,7 +450,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++)
--
2.47.1
On Thu, Feb 27, 2025 at 06:11:28PM +0530, Ayaan Mirza Baig wrote:
> This patch applies only cosmetic changes such as
> whitespace fixes, formatting and typos. These
> changes are flagged by checkpatch.pl
>
> Signed-off-by: Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>
> ---
> drivers/base/attribute_container.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
> index b6f941a6ab69..69637b2ec3bc 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;
> @@ -449,7 +450,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++)
> --
> 2.47.1
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- This looks like a new version of a previously submitted patch, but you
did not list below the --- line any changes from the previous version.
Please read the section entitled "The canonical patch format" in the
kernel file, Documentation/process/submitting-patches.rst for what
needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
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@gmail.com>
Signed-off-by: Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>
---
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
On Thu, Feb 27, 2025 at 06:11:29PM +0530, Ayaan Mirza Baig wrote:
> 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@gmail.com>
> Signed-off-by: Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>
No need to duplicate this here, if you sign-off it's implicit that you
tested it :)
> ---
> 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);
Are you sure this actually does something different? Why is the FIXME
there and why does this "simple" change solve the issue? I don't
understand how this change resolves the problem.
In other words, you're going to have to document this a lot better in
the changelog message please.
thanks,
greg k-h
© 2016 - 2026 Red Hat, Inc.