Skip to content

Commit 9ce4ed5

Browse files
author
Bartosz Golaszewski
committed
gpiolib: provide and use gpiod_line_state_notify()
Wrap the calls to blocking_notifier_call_chain() for the line state notifier with a helper that allows us to use fewer lines of code and simpler syntax. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]>
1 parent 91043f5 commit 9ce4ed5

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ static long linehandle_set_config(struct linehandle_state *lh,
230230
return ret;
231231
}
232232

233-
blocking_notifier_call_chain(&desc->gdev->line_state_notifier,
234-
GPIO_V2_LINE_CHANGED_CONFIG,
235-
desc);
233+
gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG);
236234
}
237235
return 0;
238236
}
@@ -414,8 +412,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
414412
goto out_free_lh;
415413
}
416414

417-
blocking_notifier_call_chain(&desc->gdev->line_state_notifier,
418-
GPIO_V2_LINE_CHANGED_REQUESTED, desc);
415+
gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED);
419416

420417
dev_dbg(&gdev->dev, "registered chardev handle for line %d\n",
421418
offset);
@@ -1420,9 +1417,7 @@ static long linereq_set_config_unlocked(struct linereq *lr,
14201417

14211418
WRITE_ONCE(line->edflags, edflags);
14221419

1423-
blocking_notifier_call_chain(&desc->gdev->line_state_notifier,
1424-
GPIO_V2_LINE_CHANGED_CONFIG,
1425-
desc);
1420+
gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG);
14261421
}
14271422
return 0;
14281423
}
@@ -1737,8 +1732,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
17371732

17381733
lr->lines[i].edflags = edflags;
17391734

1740-
blocking_notifier_call_chain(&desc->gdev->line_state_notifier,
1741-
GPIO_V2_LINE_CHANGED_REQUESTED, desc);
1735+
gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED);
17421736

17431737
dev_dbg(&gdev->dev, "registered chardev handle for line %d\n",
17441738
offset);
@@ -2156,8 +2150,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
21562150
if (ret)
21572151
goto out_free_le;
21582152

2159-
blocking_notifier_call_chain(&desc->gdev->line_state_notifier,
2160-
GPIO_V2_LINE_CHANGED_REQUESTED, desc);
2153+
gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED);
21612154

21622155
irq = gpiod_to_irq(desc);
21632156
if (irq <= 0) {

drivers/gpio/gpiolib.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,8 +2178,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc)
21782178
}
21792179

21802180
spin_unlock_irqrestore(&gpio_lock, flags);
2181-
blocking_notifier_call_chain(&desc->gdev->line_state_notifier,
2182-
GPIOLINE_CHANGED_RELEASED, desc);
2181+
gpiod_line_state_notify(desc, GPIOLINE_CHANGED_RELEASED);
21832182

21842183
return ret;
21852184
}
@@ -3741,6 +3740,12 @@ int gpiod_set_array_value_cansleep(unsigned int array_size,
37413740
}
37423741
EXPORT_SYMBOL_GPL(gpiod_set_array_value_cansleep);
37433742

3743+
void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action)
3744+
{
3745+
blocking_notifier_call_chain(&desc->gdev->line_state_notifier,
3746+
action, desc);
3747+
}
3748+
37443749
/**
37453750
* gpiod_add_lookup_table() - register GPIO device consumers
37463751
* @table: table of consumers to register
@@ -4008,8 +4013,7 @@ static struct gpio_desc *gpiod_find_and_request(struct device *consumer,
40084013
return ERR_PTR(ret);
40094014
}
40104015

4011-
blocking_notifier_call_chain(&desc->gdev->line_state_notifier,
4012-
GPIOLINE_CHANGED_REQUESTED, desc);
4016+
gpiod_line_state_notify(desc, GPIOLINE_CHANGED_REQUESTED);
40134017

40144018
return desc;
40154019
}

drivers/gpio/gpiolib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
147147
extern spinlock_t gpio_lock;
148148
extern struct list_head gpio_devices;
149149

150+
void gpiod_line_state_notify(struct gpio_desc *desc, unsigned long action);
150151

151152
/**
152153
* struct gpio_desc - Opaque descriptor for a GPIO

0 commit comments

Comments
 (0)