Module: xenomai-forge
Branch: master
Commit: c65cafc78bbd8e1e3dea8984ae8031d29f82fd8f
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=c65cafc78bbd8e1e3dea8984ae8031d29f82fd8f

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Jan  9 16:59:40 2014 +0100

cobalt/posix/sem: fix detection of named sema4 reinit

---

 kernel/cobalt/posix/nsem.c |    1 +
 kernel/cobalt/posix/sem.c  |   10 ++++------
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
index c19faaf..271af49 100644
--- a/kernel/cobalt/posix/nsem.c
+++ b/kernel/cobalt/posix/nsem.c
@@ -121,6 +121,7 @@ nsem_open(struct __shadow_sem __user *ushadow, const char 
*name,
                if ((oflags & O_CREAT) == 0)
                        return ERR_PTR(-ENOENT);
 
+               shadow.magic = 0;
                sem = cobalt_sem_init_inner
                        (&name[1], &shadow, SEM_PSHARED, value);
                if (IS_ERR(sem)) {
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index b898d65..6f2b40c 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -87,7 +87,6 @@ struct cobalt_sem *
 cobalt_sem_init_inner(const char *name, struct __shadow_sem *sm, 
                      int flags, unsigned int value)
 {
-       struct list_head *semq;
        struct cobalt_sem *sem, *osem;
        struct cobalt_kqueues *kq;
        struct xnsys_ppd *sys_ppd;
@@ -113,12 +112,12 @@ cobalt_sem_init_inner(const char *name, struct 
__shadow_sem *sm,
 
        xnlock_get_irqsave(&nklock, s);
 
-       if (sm->magic != COBALT_SEM_MAGIC &&
-           sm->magic != COBALT_NAMED_SEM_MAGIC)
+       kq = cobalt_kqueues(!!(flags & SEM_PSHARED));
+       if (list_empty(&kq->semq))
                goto do_init;
 
-       semq = &cobalt_kqueues(!!(flags & SEM_PSHARED))->semq;
-       if (list_empty(semq))
+       if (sm->magic != COBALT_SEM_MAGIC &&
+           sm->magic != COBALT_NAMED_SEM_MAGIC)
                goto do_init;
 
        /*
@@ -151,7 +150,6 @@ cobalt_sem_init_inner(const char *name, struct __shadow_sem 
*sm,
                goto err_lock_put;
 
        sem->magic = COBALT_SEM_MAGIC;
-       kq = cobalt_kqueues(!!(flags & SEM_PSHARED));
        list_add_tail(&sem->link, &kq->semq);
        sflags = flags & SEM_FIFO ? 0 : XNSYNCH_PRIO;
        xnsynch_init(&sem->synchbase, sflags, NULL);


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

Reply via email to