Module: xenomai-3
Branch: wip/drivers
Commit: 1fbc7013634d51d807ef950d9059e911dd0fc578
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=1fbc7013634d51d807ef950d9059e911dd0fc578

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Jun 17 16:12:27 2016 +0200

drivers/gpio: serialize access to per-chip pin list

---

 kernel/drivers/gpio/gpio-core.c |    9 +++++++++
 kernel/drivers/gpio/gpio-core.h |    1 +
 2 files changed, 10 insertions(+)

diff --git a/kernel/drivers/gpio/gpio-core.c b/kernel/drivers/gpio/gpio-core.c
index 4f707b8..319d5c7 100644
--- a/kernel/drivers/gpio/gpio-core.c
+++ b/kernel/drivers/gpio/gpio-core.c
@@ -175,15 +175,21 @@ static void delete_pin_devices(struct rtdm_gpio_chip *rgc)
        struct rtdm_gpio_pin *pin, *n;
        struct rtdm_device *dev;
 
+       rtdm_lock_get(&rgc->lock);
+       
        list_for_each_entry_safe(pin, n, &rgc->pins, next) {
                list_del(&pin->next);
+               rtdm_lock_put(&rgc->lock);
                dev = &pin->dev;
                rtdm_dev_unregister(dev);
                rtdm_event_destroy(&pin->event);
                kfree(dev->label);
                kfree(pin->name);
                kfree(pin);
+               rtdm_lock_get(&rgc->lock);
        }
+
+       rtdm_lock_put(&rgc->lock);
 }
 
 static int create_pin_devices(struct rtdm_gpio_chip *rgc)
@@ -217,7 +223,9 @@ static int create_pin_devices(struct rtdm_gpio_chip *rgc)
                if (ret)
                        goto fail_register;
                rtdm_event_init(&pin->event, 0);
+               rtdm_lock_get(&rgc->lock);
                list_add_tail(&pin->next, &rgc->pins);
+               rtdm_lock_put(&rgc->lock);
        }
 
        return 0;
@@ -277,6 +285,7 @@ int rtdm_gpiochip_add(struct rtdm_gpio_chip *rgc,
 
        rgc->gc = gc;
        INIT_LIST_HEAD(&rgc->pins);
+       rtdm_lock_init(&rgc->lock);
 
        ret = create_pin_devices(rgc);
        if (ret)
diff --git a/kernel/drivers/gpio/gpio-core.h b/kernel/drivers/gpio/gpio-core.h
index 3fa7867..d4dd28a 100644
--- a/kernel/drivers/gpio/gpio-core.h
+++ b/kernel/drivers/gpio/gpio-core.h
@@ -31,6 +31,7 @@ struct rtdm_gpio_chip {
        struct class *devclass;
        struct list_head pins;
        struct list_head next;
+       rtdm_lock_t lock;
 };
 
 int rtdm_gpiochip_add(struct rtdm_gpio_chip *rgc,


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to