struct gpiod_data {
struct gpio_desc *desc;
+ struct kernfs_node *value_kn;
};
-static DEFINE_IDR(dirent_idr);
-
-
/* lock protects against unexport_gpio() being called while
* sysfs files are active.
*/
static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
{
- struct kernfs_node *value_sd = priv;
+ struct gpiod_data *data = priv;
+
+ sysfs_notify_dirent(data->value_kn);
- sysfs_notify_dirent(value_sd);
return IRQ_HANDLED;
}
{
struct gpiod_data *data = dev_get_drvdata(dev);
struct gpio_desc *desc = data->desc;
- struct kernfs_node *value_sd;
unsigned long irq_flags;
- int ret, irq, id;
+ int ret, irq;
if ((desc->flags & GPIO_TRIGGER_MASK) == gpio_flags)
return 0;
if (irq < 0)
return -EIO;
- id = desc->flags >> ID_SHIFT;
- value_sd = idr_find(&dirent_idr, id);
- if (value_sd)
- free_irq(irq, value_sd);
+ if (data->value_kn)
+ free_irq(irq, data);
desc->flags &= ~GPIO_TRIGGER_MASK;
if (!gpio_flags) {
gpiochip_unlock_as_irq(desc->chip, gpio_chip_hwgpio(desc));
ret = 0;
- goto free_id;
+ goto free_kn;
}
irq_flags = IRQF_SHARED;
irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
- if (!value_sd) {
- value_sd = sysfs_get_dirent(dev->kobj.sd, "value");
- if (!value_sd) {
+ if (!data->value_kn) {
+ data->value_kn = sysfs_get_dirent(dev->kobj.sd, "value");
+ if (!data->value_kn) {
ret = -ENODEV;
goto err_out;
}
-
- ret = idr_alloc(&dirent_idr, value_sd, 1, 0, GFP_KERNEL);
- if (ret < 0)
- goto free_sd;
- id = ret;
-
- desc->flags &= GPIO_FLAGS_MASK;
- desc->flags |= (unsigned long)id << ID_SHIFT;
-
- if (desc->flags >> ID_SHIFT != id) {
- ret = -ERANGE;
- goto free_id;
- }
}
/*
*/
ret = gpiochip_lock_as_irq(desc->chip, gpio_chip_hwgpio(desc));
if (ret < 0)
- goto free_id;
+ goto free_kn;
ret = request_any_context_irq(irq, gpio_sysfs_irq, irq_flags,
- "gpiolib", value_sd);
+ "gpiolib", data);
if (ret < 0)
goto err_unlock;
err_unlock:
gpiochip_unlock_as_irq(desc->chip, gpio_chip_hwgpio(desc));
-free_id:
- idr_remove(&dirent_idr, id);
- desc->flags &= GPIO_FLAGS_MASK;
-free_sd:
- if (value_sd)
- sysfs_put(value_sd);
+free_kn:
+ if (data->value_kn) {
+ sysfs_put(data->value_kn);
+ data->value_kn = NULL;
+ }
err_out:
return ret;
}