Skip to content

Commit

Permalink
gpio: sysfs: only call irq helper if needed
Browse files Browse the repository at this point in the history
Only call irq helper if actually reconfiguring interrupt state.

This is a preparatory step in introducing separate gpio-irq request and
free functions.

Signed-off-by: Johan Hovold <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
jhovold authored and linusw committed May 12, 2015
1 parent a08f5c2 commit b91e180
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions drivers/gpio/gpiolib-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ static int gpio_setup_irq(struct device *dev, unsigned long gpio_flags)
unsigned long irq_flags;
int ret, irq;

if ((desc->flags & GPIO_TRIGGER_MASK) == gpio_flags)
return 0;

irq = gpiod_to_irq(desc);
if (irq < 0)
return -EIO;
Expand Down Expand Up @@ -240,6 +237,9 @@ static ssize_t edge_show(struct device *dev,
static ssize_t edge_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t size)
{
struct gpiod_data *data = dev_get_drvdata(dev);
struct gpio_desc *desc = data->desc;
unsigned long flags;
ssize_t status;
int i;

Expand All @@ -249,12 +249,20 @@ static ssize_t edge_store(struct device *dev,
return -EINVAL;

found:
flags = trigger_types[i].flags;

mutex_lock(&sysfs_lock);

status = gpio_setup_irq(dev, trigger_types[i].flags);
if ((desc->flags & GPIO_TRIGGER_MASK) == flags) {
status = size;
goto out_unlock;
}

status = gpio_setup_irq(dev, flags);
if (!status)
status = size;

out_unlock:
mutex_unlock(&sysfs_lock);

return status;
Expand Down Expand Up @@ -690,7 +698,8 @@ void gpiod_unexport(struct gpio_desc *desc)
* Release irq after deregistration to prevent race with
* edge_store.
*/
gpio_setup_irq(dev, 0);
if (desc->flags & GPIO_TRIGGER_MASK)
gpio_setup_irq(dev, 0);
put_device(dev);
kfree(data);
}
Expand Down

0 comments on commit b91e180

Please sign in to comment.