* [PATCH 1/3] gpio: sysfs: fix gpio-chip device-attribute leak
[not found] <1421150406-20255-1-git-send-email-johan@kernel.org>
@ 2015-01-13 12:00 ` Johan Hovold
2015-01-25 9:25 ` Alexandre Courbot
2015-01-13 12:00 ` [PATCH 2/3] gpio: sysfs: fix gpio " Johan Hovold
1 sibling, 1 reply; 5+ messages in thread
From: Johan Hovold @ 2015-01-13 12:00 UTC (permalink / raw)
To: Linus Walleij
Cc: Alexandre Courbot, linux-gpio, linux-kernel, Johan Hovold, stable
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: d8f388d8dc8d ("gpio: sysfs interface")
Cc: stable <stable@vger.kernel.org> # v2.6.27+
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpio/gpiolib-sysfs.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 2ac1800b58bb..33cf4bd0ed2d 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -400,16 +400,13 @@ static ssize_t chip_ngpio_show(struct device *dev,
}
static DEVICE_ATTR(ngpio, 0444, chip_ngpio_show, NULL);
-static const struct attribute *gpiochip_attrs[] = {
+static struct attribute *gpiochip_attrs[] = {
&dev_attr_base.attr,
&dev_attr_label.attr,
&dev_attr_ngpio.attr,
NULL,
};
-
-static const struct attribute_group gpiochip_attr_group = {
- .attrs = (struct attribute **) gpiochip_attrs,
-};
+ATTRIBUTE_GROUPS(gpiochip);
/*
* /sys/class/gpio/export ... write-only
@@ -750,13 +747,13 @@ int gpiochip_export(struct gpio_chip *chip)
/* use chip->base for the ID; it's already known to be unique */
mutex_lock(&sysfs_lock);
- dev = device_create(&gpio_class, chip->dev, MKDEV(0, 0), chip,
- "gpiochip%d", chip->base);
- if (!IS_ERR(dev)) {
- status = sysfs_create_group(&dev->kobj,
- &gpiochip_attr_group);
- } else
+ dev = device_create_with_groups(&gpio_class, chip->dev, MKDEV(0, 0),
+ chip, gpiochip_groups,
+ "gpiochip%d", chip->base);
+ if (IS_ERR(dev))
status = PTR_ERR(dev);
+ else
+ status = 0;
chip->exported = (status == 0);
mutex_unlock(&sysfs_lock);
--
2.0.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] gpio: sysfs: fix gpio device-attribute leak
[not found] <1421150406-20255-1-git-send-email-johan@kernel.org>
2015-01-13 12:00 ` [PATCH 1/3] gpio: sysfs: fix gpio-chip device-attribute leak Johan Hovold
@ 2015-01-13 12:00 ` Johan Hovold
2015-01-25 9:27 ` Alexandre Courbot
1 sibling, 1 reply; 5+ messages in thread
From: Johan Hovold @ 2015-01-13 12:00 UTC (permalink / raw)
To: Linus Walleij
Cc: Alexandre Courbot, linux-gpio, linux-kernel, Johan Hovold, stable
The gpio device attributes were never destroyed when the gpio was
unexported (or on export failures).
Use device_create_with_groups() to create the default device attributes
of the gpio class device. Note that this also fixes the
attribute-creation race with userspace for these attributes.
Remove contingent attributes in export error path and on unexport.
Fixes: d8f388d8dc8d ("gpio: sysfs interface")
Cc: stable <stable@vger.kernel.org> # v2.6.27+
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpio/gpiolib-sysfs.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 33cf4bd0ed2d..fd4d9423f6e6 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -128,7 +128,7 @@ static ssize_t gpio_value_store(struct device *dev,
return status;
}
-static const DEVICE_ATTR(value, 0644,
+static DEVICE_ATTR(value, 0644,
gpio_value_show, gpio_value_store);
static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
@@ -353,18 +353,15 @@ static ssize_t gpio_active_low_store(struct device *dev,
return status ? : size;
}
-static const DEVICE_ATTR(active_low, 0644,
+static DEVICE_ATTR(active_low, 0644,
gpio_active_low_show, gpio_active_low_store);
-static const struct attribute *gpio_attrs[] = {
+static struct attribute *gpio_attrs[] = {
&dev_attr_value.attr,
&dev_attr_active_low.attr,
NULL,
};
-
-static const struct attribute_group gpio_attr_group = {
- .attrs = (struct attribute **) gpio_attrs,
-};
+ATTRIBUTE_GROUPS(gpio);
/*
* /sys/class/gpio/gpiochipN/
@@ -561,18 +558,15 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
if (desc->chip->names && desc->chip->names[offset])
ioname = desc->chip->names[offset];
- dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0),
- desc, ioname ? ioname : "gpio%u",
- desc_to_gpio(desc));
+ dev = device_create_with_groups(&gpio_class, desc->chip->dev,
+ MKDEV(0, 0), desc, gpio_groups,
+ ioname ? ioname : "gpio%u",
+ desc_to_gpio(desc));
if (IS_ERR(dev)) {
status = PTR_ERR(dev);
goto fail_unlock;
}
- status = sysfs_create_group(&dev->kobj, &gpio_attr_group);
- if (status)
- goto fail_unregister_device;
-
if (direction_may_change) {
status = device_create_file(dev, &dev_attr_direction);
if (status)
@@ -583,13 +577,15 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
!test_bit(FLAG_IS_OUT, &desc->flags))) {
status = device_create_file(dev, &dev_attr_edge);
if (status)
- goto fail_unregister_device;
+ goto fail_remove_attr_direction;
}
set_bit(FLAG_EXPORT, &desc->flags);
mutex_unlock(&sysfs_lock);
return 0;
+fail_remove_attr_direction:
+ device_remove_file(dev, &dev_attr_direction);
fail_unregister_device:
device_unregister(dev);
fail_unlock:
@@ -723,6 +719,8 @@ void gpiod_unexport(struct gpio_desc *desc)
mutex_unlock(&sysfs_lock);
if (dev) {
+ device_remove_file(dev, &dev_attr_edge);
+ device_remove_file(dev, &dev_attr_direction);
device_unregister(dev);
put_device(dev);
}
--
2.0.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] gpio: sysfs: fix gpio-chip device-attribute leak
2015-01-13 12:00 ` [PATCH 1/3] gpio: sysfs: fix gpio-chip device-attribute leak Johan Hovold
@ 2015-01-25 9:25 ` Alexandre Courbot
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2015-01-25 9:25 UTC (permalink / raw)
To: Johan Hovold
Cc: Linus Walleij, linux-gpio@vger.kernel.org,
Linux Kernel Mailing List, stable
On Tue, Jan 13, 2015 at 9:00 PM, Johan Hovold <johan@kernel.org> wrote:
> 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.
... and it also improves code readability.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] gpio: sysfs: fix gpio device-attribute leak
2015-01-13 12:00 ` [PATCH 2/3] gpio: sysfs: fix gpio " Johan Hovold
@ 2015-01-25 9:27 ` Alexandre Courbot
2015-01-25 9:30 ` Alexandre Courbot
0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Courbot @ 2015-01-25 9:27 UTC (permalink / raw)
To: Johan Hovold
Cc: Linus Walleij, linux-gpio@vger.kernel.org,
Linux Kernel Mailing List, stable
On Tue, Jan 13, 2015 at 9:00 PM, Johan Hovold <johan@kernel.org> wrote:
> The gpio device attributes were never destroyed when the gpio was
> unexported (or on export failures).
>
> Use device_create_with_groups() to create the default device attributes
> of the gpio class device. Note that this also fixes the
> attribute-creation race with userspace for these attributes.
>
> Remove contingent attributes in export error path and on unexport.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] gpio: sysfs: fix gpio device-attribute leak
2015-01-25 9:27 ` Alexandre Courbot
@ 2015-01-25 9:30 ` Alexandre Courbot
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2015-01-25 9:30 UTC (permalink / raw)
To: Johan Hovold
Cc: Linus Walleij, linux-gpio@vger.kernel.org,
Linux Kernel Mailing List, stable
On Sun, Jan 25, 2015 at 6:27 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
> On Tue, Jan 13, 2015 at 9:00 PM, Johan Hovold <johan@kernel.org> wrote:
>> The gpio device attributes were never destroyed when the gpio was
>> unexported (or on export failures).
>>
>> Use device_create_with_groups() to create the default device attributes
>> of the gpio class device. Note that this also fixes the
>> attribute-creation race with userspace for these attributes.
>>
>> Remove contingent attributes in export error path and on unexport.
>
> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Mmm actually this one does not seem to apply to Linus' devel branch.
Seems like something has changed in between - could you rebase and
resend?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-01-25 9:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1421150406-20255-1-git-send-email-johan@kernel.org>
2015-01-13 12:00 ` [PATCH 1/3] gpio: sysfs: fix gpio-chip device-attribute leak Johan Hovold
2015-01-25 9:25 ` Alexandre Courbot
2015-01-13 12:00 ` [PATCH 2/3] gpio: sysfs: fix gpio " Johan Hovold
2015-01-25 9:27 ` Alexandre Courbot
2015-01-25 9:30 ` Alexandre Courbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).