Remove contingent attributes in export error path and on unexport.
Fixes: d8f388d8dc8d ("gpio: sysfs interface")
-Cc: stable <stable@vger.kernel.org> # v2.6.27+
+Cc: stable <stable@vger.kernel.org> # v2.6.27+
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-[johan: fix leaks without device_create_with_groups, which wasn't
-introduced until 3.11 ]
-Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
static const struct attribute_group gpio_attr_group = {
- .attrs = (struct attribute **) gpio_attrs,
-+ .attrs = gpio_attrs,
++ .attrs = gpio_attrs,
};
/*
fail_unregister_device:
device_unregister(dev);
fail_unlock:
-@@ -962,6 +966,9 @@ static void gpiod_unexport(struct gpio_d
+@@ -971,6 +975,9 @@ static void gpiod_unexport(struct gpio_d
+ mutex_unlock(&sysfs_lock);
- dev = class_find_device(&gpio_class, NULL, desc, match_export);
- if (dev) {
-+ device_remove_file(dev, &dev_attr_edge);
-+ device_remove_file(dev, &dev_attr_direction);
-+ sysfs_remove_group(&dev->kobj, &gpio_attr_group);
- gpio_setup_irq(desc, dev, 0);
- clear_bit(FLAG_EXPORT, &desc->flags);
- } else
+ if (dev) {
++ device_remove_file(dev, &dev_attr_edge);
++ device_remove_file(dev, &dev_attr_direction);
++ sysfs_remove_group(&dev->kobj, &gpio_attr_group);
+ device_unregister(dev);
+ put_device(dev);
+ }