Module: xenomai-3
Branch: next
Commit: c79073b77e4995356726b53948478c69808c3d91
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=c79073b77e4995356726b53948478c69808c3d91

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Tue Sep 29 01:41:26 2015 +0200

rtdm/devices: avoid incomplete device cleanup

when unregister_driver() is called from rtdm_dev_unregister(),
__rtdm_put_device() has already decreased the driver reference count, so
the result of atomic_dec_and_test() is always false and unregister_driver()
does not finish the cleanup. Fix this by moving the atomic_dec_and_test()
test to the only other call site of unregister_driver():
the rtdm_dev_regiter() error path.

---

 kernel/cobalt/rtdm/device.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 1c602c2..9af2221 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -303,6 +303,7 @@ static int register_driver(struct rtdm_driver *drv)
 
        drv->named.major = MAJOR(rdev);
        atomic_set(&drv->refcount, 1);
+
 done:
        drv->nb_statechange.notifier_call = state_change_notifier;
        drv->nb_statechange.priority = 0;
@@ -321,9 +322,6 @@ static void unregister_driver(struct rtdm_driver *drv)
 {
        XENO_BUG_ON(COBALT, drv->profile_info.magic != RTDM_CLASS_MAGIC);
 
-       if (!atomic_dec_and_test(&drv->refcount))
-               return;
-
        cobalt_remove_notifier_chain(&drv->nb_statechange);
        
        if (drv->device_flags & RTDM_NAMED_DEVICE) {
@@ -452,7 +450,8 @@ fail:
        if (kdev)
                device_destroy(rtdm_class, rdev);
 
-       unregister_driver(drv);
+       if (atomic_dec_and_test(&drv->refcount))
+               unregister_driver(drv);
 
        mutex_unlock(&register_lock);
 


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

Reply via email to