Skip to content

Commit dd61b29

Browse files
committed
gpiolib: provide gpiod_remove_hogs()
Currently all users of gpiod_add_hogs() call it only once at system init so there never was any need for a mechanism allowing to remove them. Now the upcoming gpio-sim will need to tear down chips with hogged lines so provide a function that allows to remove hogs. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Acked-by: Linus Walleij <[email protected]>
1 parent ab39d69 commit dd61b29

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

drivers/gpio/gpiolib.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,6 +3557,17 @@ void gpiod_add_hogs(struct gpiod_hog *hogs)
35573557
}
35583558
EXPORT_SYMBOL_GPL(gpiod_add_hogs);
35593559

3560+
void gpiod_remove_hogs(struct gpiod_hog *hogs)
3561+
{
3562+
struct gpiod_hog *hog;
3563+
3564+
mutex_lock(&gpio_machine_hogs_mutex);
3565+
for (hog = &hogs[0]; hog->chip_label; hog++)
3566+
list_del(&hog->list);
3567+
mutex_unlock(&gpio_machine_hogs_mutex);
3568+
}
3569+
EXPORT_SYMBOL_GPL(gpiod_remove_hogs);
3570+
35603571
static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev)
35613572
{
35623573
const char *dev_id = dev ? dev_name(dev) : NULL;

include/linux/gpio/machine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
100100
void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
101101
void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
102102
void gpiod_add_hogs(struct gpiod_hog *hogs);
103+
void gpiod_remove_hogs(struct gpiod_hog *hogs);
103104
#else /* ! CONFIG_GPIOLIB */
104105
static inline
105106
void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
@@ -108,6 +109,7 @@ void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
108109
static inline
109110
void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
110111
static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {}
112+
static inline void gpiod_remove_hogs(struct gpiod_hog *hogs) {}
111113
#endif /* CONFIG_GPIOLIB */
112114

113115
#endif /* __LINUX_GPIO_MACHINE_H */

0 commit comments

Comments
 (0)