gpiolib: provide and use gpiod_line_state_notify()
PATCH 1/1 gpiolib: provide and use gpiod_line_state_notify()
From: Bartosz Golaszewski <[email protected]>
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.
--- drivers/gpio/gpiolib-cdev.c | 17 +++++------------ drivers/gpio/gpiolib.c | 12 ++++++++---- drivers/gpio/gpiolib.h | 1 + 3 files changed, 14 insertions(+), 16 deletions(-)
drivers/gpio/gpiolib-cdev.c +5 -12
@@ -230,9 +230,7 @@ static long linehandle_set_config(struct linehandle_state *lh,return ret; } -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_CONFIG , - desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); }return 0 ; }
@@ -414,8 +412,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) goto out_free_lh; } -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_REQUESTED , desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_REQUESTED );dev_dbg (&gdev->dev,"registered chardev handle for line %d\n" , offset);
@@ -1420,9 +1417,7 @@ static long linereq_set_config_unlocked(struct linereq *lr,WRITE_ONCE (line->edflags, edflags); -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_CONFIG , - desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); }return 0 ; }
@@ -1737,8 +1732,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) lr->lines[i].edflags = edflags; -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_REQUESTED , desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_REQUESTED );dev_dbg (&gdev->dev,"registered chardev handle for line %d\n" , offset);
@@ -2156,8 +2150,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)if (ret) goto out_free_le; -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_REQUESTED , desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_REQUESTED ); irq =gpiod_to_irq (desc);if (irq <=0 ) {
drivers/gpio/gpiolib.c +8 -4
@@ -2160,8 +2160,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc) }spin_unlock_irqrestore (&gpio_lock, flags); -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIOLINE_CHANGED_RELEASED , desc); +gpiod_line_state_notify (desc,GPIOLINE_CHANGED_RELEASED );return ret; }
@@ -3729,6 +3728,12 @@ int gpiod_set_array_value_cansleep(unsigned int array_size, }EXPORT_SYMBOL_GPL (gpiod_set_array_value_cansleep); +void gpiod_line_state_notify (struct gpio_desc *desc,unsigned long action) +{ +blocking_notifier_call_chain (&desc->gdev->line_state_notifier, + action, desc); +} +/** * gpiod_add_lookup_table() - register GPIO device consumers * @table: table of consumers to register
@@ -3996,8 +4001,7 @@ static struct gpio_desc *gpiod_find_and_request(struct device *consumer,return ERR_PTR (ret); } -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIOLINE_CHANGED_REQUESTED , desc); +gpiod_line_state_notify (desc,GPIOLINE_CHANGED_REQUESTED );return desc; }
drivers/gpio/gpiolib.h +1 -0
@@ -146,6 +146,7 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,extern spinlock_t gpio_lock;extern struct list_head gpio_devices; +void gpiod_line_state_notify (struct gpio_desc *desc,unsigned long action);/** * struct gpio_desc - Opaque descriptor for a GPIO
Signature · 1 line
2.39.2
Quoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
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.
This change I like, no questions asked.
Quoted 78 lines
Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpiolib-cdev.c | 17 +++++------------ drivers/gpio/gpiolib.c | 12 ++++++++---- drivers/gpio/gpiolib.h | 1 + 3 files changed, 14 insertions(+), 16 deletions(-)drivers/gpio/gpiolib-cdev.c +5
-12@@ -230,9 +230,7 @@ static long linehandle_set_config(struct linehandle_state *lh,return ret; } -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_CONFIG , - desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); }return 0 ; }@@ -414,8 +412,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) goto out_free_lh; } -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_REQUESTED , desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_REQUESTED );dev_dbg (&gdev->dev,"registered chardev handle for line %d\n" , offset);@@ -1420,9 +1417,7 @@ static long linereq_set_config_unlocked(struct linereq *lr,WRITE_ONCE (line->edflags, edflags); -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_CONFIG , - desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); }return 0 ; }@@ -1737,8 +1732,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) lr->lines[i].edflags = edflags; -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_REQUESTED , desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_REQUESTED );dev_dbg (&gdev->dev,"registered chardev handle for line %d\n" , offset);@@ -2156,8 +2150,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)if (ret) goto out_free_le; -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIO_V2_LINE_CHANGED_REQUESTED , desc); +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_REQUESTED ); irq =gpiod_to_irq (desc);if (irq <=0 ) {drivers/gpio/gpiolib.c +1
-2@@ -2160,8 +2160,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc) }spin_unlock_irqrestore (&gpio_lock, flags); -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIOLINE_CHANGED_RELEASED , desc); +gpiod_line_state_notify (desc,GPIOLINE_CHANGED_RELEASED );return ret; }
drivers/gpio/gpiolib.c int gpiod_set_array_value_cansleep(unsigned int array_size, · line 3734
Quoted 7 lines
drivers/gpio/gpiolib.c +4
-0@@ -3729,6 +3728,12 @@ int gpiod_set_array_value_cansleep(unsigned int array_size, }EXPORT_SYMBOL_GPL (gpiod_set_array_value_cansleep); +void gpiod_line_state_notify (struct gpio_desc *desc,unsigned long action) +{ +blocking_notifier_call_chain (&desc->gdev->line_state_notifier, + action, desc);
action can be on previous line, but this is the logical split, so fine as is.
Quoted 30 lines
drivers/gpio/gpiolib.c +3
-2+} +/** * gpiod_add_lookup_table() - register GPIO device consumers * @table: table of consumers to register @@ -3996,8 +4001,7 @@ static struct gpio_desc *gpiod_find_and_request(struct device *consumer,return ERR_PTR (ret); } -blocking_notifier_call_chain (&desc->gdev->line_state_notifier, -GPIOLINE_CHANGED_REQUESTED , desc); +gpiod_line_state_notify (desc,GPIOLINE_CHANGED_REQUESTED );return desc; }drivers/gpio/gpiolib.h +1
-0@@ -146,6 +146,7 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,extern spinlock_t gpio_lock;extern struct list_head gpio_devices; +void gpiod_line_state_notify (struct gpio_desc *desc,unsigned long action);/** * struct gpio_desc - Opaque descriptor for a GPIO Signature · 1 line
2.39.2
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
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]>
Not to mention easier to read the code and understand what is going on. I would have made it into a static inline in the header file, maybe, but who cares about such details.
Yours,
Linus Walleij