Driver core: Fix device_add_attrs() error code path
diff mbox series

Message ID 1902491.UTh5DYb76O@vostro.rjw.lan
State New, archived
Headers show
Series
  • Driver core: Fix device_add_attrs() error code path
Related show

Commit Message

Rafael J. Wysocki Dec. 12, 2013, 5:11 a.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If the addition of dev_attr_online fails, device_add_attrs() should
remove device attribute groups as well as type and class attribute
groups before returning an error code.  Make that happen.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/base/core.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Comments

Toshi Kani Dec. 12, 2013, 3:27 p.m. UTC | #1
On Thu, 2013-12-12 at 06:11 +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> If the addition of dev_attr_online fails, device_add_attrs() should
> remove device attribute groups as well as type and class attribute
> groups before returning an error code.  Make that happen.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Nice catch!

Acked-by: Toshi Kani <toshi.kani@hp.com>

-Toshi

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Greg Kroah-Hartman Dec. 12, 2013, 11:13 p.m. UTC | #2
On Thu, Dec 12, 2013 at 06:11:02AM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> If the addition of dev_attr_online fails, device_add_attrs() should
> remove device attribute groups as well as type and class attribute
> groups before returning an error code.  Make that happen.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Does this need tob e in 3.13-final?  Or can it wait for 3.14-rc1?  The
odds that this file creation would ever fail is _really_ low, right?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Rafael J. Wysocki Dec. 13, 2013, 5 a.m. UTC | #3
On Thursday, December 12, 2013 03:13:33 PM Greg Kroah-Hartman wrote:
> On Thu, Dec 12, 2013 at 06:11:02AM +0100, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > 
> > If the addition of dev_attr_online fails, device_add_attrs() should
> > remove device attribute groups as well as type and class attribute
> > groups before returning an error code.  Make that happen.
> > 
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Does this need tob e in 3.13-final?  Or can it wait for 3.14-rc1?  The
> odds that this file creation would ever fail is _really_ low, right?

Yeah, it's more of a cleanup than a fix, so 3.14-rc1 should be fine.

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch
diff mbox series

Index: linux-pm/drivers/base/core.c
===================================================================
--- linux-pm.orig/drivers/base/core.c
+++ linux-pm/drivers/base/core.c
@@ -491,11 +491,13 @@  static int device_add_attrs(struct devic
 	if (device_supports_offline(dev) && !dev->offline_disabled) {
 		error = device_create_file(dev, &dev_attr_online);
 		if (error)
-			goto err_remove_type_groups;
+			goto err_remove_dev_groups;
 	}
 
 	return 0;
 
+ err_remove_dev_groups:
+ 	device_remove_groups(dev, dev->groups);
  err_remove_type_groups:
 	if (type)
 		device_remove_groups(dev, type->groups);