Module: xenomai-3 Branch: wip/rtnet-fixes Commit: 7ffd31e5c576699f62f1e832eee610fd2372ed14 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7ffd31e5c576699f62f1e832eee610fd2372ed14
Author: Philippe Gerum <r...@xenomai.org> Date: Thu Jan 11 15:50:28 2018 +0100 drivers/gpio: pass back allocated GPIO chip descriptor rtdm_gpiochip_alloc() is a way to instantiate a single GPIO descriptor instead of mapping all GPIO controllers defined by the firmware which belong to a particular type. This routine is matched by rtdm_gpiochip_remove() for deallocation. We need the former to return a pointer to the allocated descriptor we may then pass to the latter. --- include/cobalt/kernel/rtdm/gpio.h | 5 +++-- kernel/drivers/gpio/gpio-core.c | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/cobalt/kernel/rtdm/gpio.h b/include/cobalt/kernel/rtdm/gpio.h index 224b562..378a678 100644 --- a/include/cobalt/kernel/rtdm/gpio.h +++ b/include/cobalt/kernel/rtdm/gpio.h @@ -48,8 +48,9 @@ int rtdm_gpiochip_add(struct rtdm_gpio_chip *rgc, struct gpio_chip *gc, int gpio_subclass); -int rtdm_gpiochip_alloc(struct gpio_chip *gc, - int gpio_subclass); +struct rtdm_gpio_chip * +rtdm_gpiochip_alloc(struct gpio_chip *gc, + int gpio_subclass); void rtdm_gpiochip_remove(struct rtdm_gpio_chip *rgc); diff --git a/kernel/drivers/gpio/gpio-core.c b/kernel/drivers/gpio/gpio-core.c index 1bf8a9c..3e97547 100644 --- a/kernel/drivers/gpio/gpio-core.c +++ b/kernel/drivers/gpio/gpio-core.c @@ -376,9 +376,6 @@ int rtdm_gpiochip_add(struct rtdm_gpio_chip *rgc, { int ret; - if (!realtime_core_enabled()) - return 0; - rgc->devclass = class_create(gc->owner, gc->label); if (IS_ERR(rgc->devclass)) { printk(XENO_ERR "cannot create sysfs class\n"); @@ -417,31 +414,32 @@ int rtdm_gpiochip_add(struct rtdm_gpio_chip *rgc, } EXPORT_SYMBOL_GPL(rtdm_gpiochip_add); -int rtdm_gpiochip_alloc(struct gpio_chip *gc, int gpio_subclass) +struct rtdm_gpio_chip * +rtdm_gpiochip_alloc(struct gpio_chip *gc, int gpio_subclass) { struct rtdm_gpio_chip *rgc; size_t asize; int ret; if (gc->ngpio == 0) - return -EINVAL; + return ERR_PTR(-EINVAL); asize = sizeof(*rgc) + gc->ngpio * sizeof(struct rtdm_gpio_pin); rgc = kzalloc(asize, GFP_KERNEL); if (rgc == NULL) - return -ENOMEM; + return ERR_PTR(-ENOMEM); ret = rtdm_gpiochip_add(rgc, gc, gpio_subclass); if (ret) { kfree(rgc); - return ret; + return ERR_PTR(ret); } mutex_lock(&chip_lock); list_add(&rgc->next, &rtdm_gpio_chips); mutex_unlock(&chip_lock); - return 0; + return rgc; } EXPORT_SYMBOL_GPL(rtdm_gpiochip_alloc); @@ -535,8 +533,12 @@ int rtdm_gpiochip_scan_of(struct device_node *from, const char *compat, struct gpiochip_holder *h, *n; struct device_node *np = from; struct platform_device *pdev; + struct rtdm_gpio_chip *rgc; int ret = -ENODEV, _ret; + if (!realtime_core_enabled()) + return 0; + for (;;) { np = of_find_compatible_node(np, NULL, compat); if (np == NULL) @@ -552,7 +554,10 @@ int rtdm_gpiochip_scan_of(struct device_node *from, const char *compat, ret = 0; list_for_each_entry_safe(h, n, &match.list, next) { list_del(&h->next); - _ret = rtdm_gpiochip_alloc(h->chip, type); + _ret = 0; + rgc = rtdm_gpiochip_alloc(h->chip, type); + if (IS_ERR(rgc)) + _ret = PTR_ERR(rgc); kfree(h); if (_ret && !ret) ret = _ret; @@ -570,6 +575,9 @@ void rtdm_gpiochip_remove_of(int type) { struct rtdm_gpio_chip *rgc, *n; + if (!realtime_core_enabled()) + return; + list_for_each_entry_safe(rgc, n, &rtdm_gpio_chips, next) { if (rgc->driver.profile_info.subclass_id == type) { rtdm_gpiochip_remove(rgc); _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org https://xenomai.org/mailman/listinfo/xenomai-git