Skip to content

Commit 121b6a7

Browse files
jhovoldlinusw
authored andcommitted
gpio: sysfs: fix gpio-chip device-attribute leak
The gpio-chip device attributes were never destroyed when the device was removed. Fix by using device_create_with_groups() to create the device attributes of the chip class device. Note that this also fixes the attribute-creation race with userspace. Fixes: d8f388d ("gpio: sysfs interface") 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>
1 parent 01cca93 commit 121b6a7

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/gpio/gpiolib-sysfs.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,13 @@ static ssize_t chip_ngpio_show(struct device *dev,
400400
}
401401
static DEVICE_ATTR(ngpio, 0444, chip_ngpio_show, NULL);
402402

403-
static const struct attribute *gpiochip_attrs[] = {
403+
static struct attribute *gpiochip_attrs[] = {
404404
&dev_attr_base.attr,
405405
&dev_attr_label.attr,
406406
&dev_attr_ngpio.attr,
407407
NULL,
408408
};
409-
410-
static const struct attribute_group gpiochip_attr_group = {
411-
.attrs = (struct attribute **) gpiochip_attrs,
412-
};
409+
ATTRIBUTE_GROUPS(gpiochip);
413410

414411
/*
415412
* /sys/class/gpio/export ... write-only
@@ -750,13 +747,13 @@ int gpiochip_export(struct gpio_chip *chip)
750747

751748
/* use chip->base for the ID; it's already known to be unique */
752749
mutex_lock(&sysfs_lock);
753-
dev = device_create(&gpio_class, chip->dev, MKDEV(0, 0), chip,
754-
"gpiochip%d", chip->base);
755-
if (!IS_ERR(dev)) {
756-
status = sysfs_create_group(&dev->kobj,
757-
&gpiochip_attr_group);
758-
} else
750+
dev = device_create_with_groups(&gpio_class, chip->dev, MKDEV(0, 0),
751+
chip, gpiochip_groups,
752+
"gpiochip%d", chip->base);
753+
if (IS_ERR(dev))
759754
status = PTR_ERR(dev);
755+
else
756+
status = 0;
760757
chip->exported = (status == 0);
761758
mutex_unlock(&sysfs_lock);
762759

0 commit comments

Comments
 (0)