Module: xenomai-rpm
Branch: for-upstream
Commit: e7b857548a9fde5889c89dcb112b968a14897230
URL:    
http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=e7b857548a9fde5889c89dcb112b968a14897230

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Mar  4 23:12:18 2010 +0100

nucleus/intr: factor out consistency checks

---

 ksrc/nucleus/intr.c |   86 ++++++++++++++++++++++++++-------------------------
 1 files changed, 44 insertions(+), 42 deletions(-)

diff --git a/ksrc/nucleus/intr.c b/ksrc/nucleus/intr.c
index ace75d5..be403b3 100644
--- a/ksrc/nucleus/intr.c
+++ b/ksrc/nucleus/intr.c
@@ -316,12 +316,6 @@ static inline int xnintr_irq_attach(xnintr_t *intr)
        xnintr_t *prev, **p = &shirq->handlers;
        int err;
 
-       if (intr->irq >= XNARCH_NR_IRQS)
-               return -EINVAL;
-
-       if (__testbits(intr->flags, XN_ISR_ATTACHED))
-               return -EPERM;
-
        if ((prev = *p) != NULL) {
                /* Check on whether the shared mode is allowed. */
                if (!(prev->flags & intr->flags & XN_ISR_SHARED) ||
@@ -371,14 +365,6 @@ static inline int xnintr_irq_detach(xnintr_t *intr)
        xnintr_t *e, **p = &shirq->handlers;
        int err = 0;
 
-       if (intr->irq >= XNARCH_NR_IRQS)
-               return -EINVAL;
-
-       if (!__testbits(intr->flags, XN_ISR_ATTACHED))
-               return -EPERM;
-
-       __clrbits(intr->flags, XN_ISR_ATTACHED);
-
        while ((e = *p) != NULL) {
                if (e == intr) {
                        /* Remove the given interrupt object from the list. */
@@ -426,36 +412,29 @@ static inline xnintr_t *xnintr_shirq_next(xnintr_t *prev)
 
 static inline int xnintr_irq_attach(xnintr_t *intr)
 {
-       int err;
-
-       if (__testbits(intr->flags, XN_ISR_ATTACHED))
-               return -EPERM;
+       int ret;
 
-       err = xnarch_hook_irq(intr->irq, &xnintr_irq_handler,
-                              (rthal_irq_ackfn_t)intr->iack, intr);
+       ret = xnarch_hook_irq(intr->irq, &xnintr_irq_handler,
+                             (rthal_irq_ackfn_t)intr->iack, intr);
+       if (ret)
+               return ret;
 
-       if (!err)
-               __setbits(intr->flags, XN_ISR_ATTACHED);
+       __setbits(intr->flags, XN_ISR_ATTACHED);
 
-       return err;
+       return 0;
 }
 
 static inline int xnintr_irq_detach(xnintr_t *intr)
 {
-       int irq = intr->irq, err;
-
-       if (!__testbits(intr->flags, XN_ISR_ATTACHED))
-               return -EPERM;
-
-       __clrbits(intr->flags, XN_ISR_ATTACHED);
+       int irq = intr->irq, ret;
 
        xnlock_get(&xnirqs[irq].lock);
-       err = xnarch_release_irq(irq);
+       ret = xnarch_release_irq(irq);
        xnlock_put(&xnirqs[irq].lock);
 
        xnintr_sync_stat_references(intr);
 
-       return err;
+       return ret;
 }
 
 #endif /* !CONFIG_XENO_OPT_SHIRQ */
@@ -732,7 +711,7 @@ EXPORT_SYMBOL_GPL(xnintr_destroy);
 
 int xnintr_attach(xnintr_t *intr, void *cookie)
 {
-       int err;
+       int ret;
        spl_t s;
 
        trace_mark(xn_nucleus, irq_attach, "irq %u name %s",
@@ -747,14 +726,25 @@ int xnintr_attach(xnintr_t *intr, void *cookie)
 
        xnlock_get_irqsave(&intrlock, s);
 
-       err = xnintr_irq_attach(intr);
+       if (intr->irq >= XNARCH_NR_IRQS) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (__testbits(intr->flags, XN_ISR_ATTACHED)) {
+               ret = -EPERM;
+               goto out;
+       }
 
-       if (!err)
-               xnintr_stat_counter_inc();
+       ret = xnintr_irq_attach(intr);
+       if (ret)
+               goto out;
 
+       xnintr_stat_counter_inc();
+out:
        xnlock_put_irqrestore(&intrlock, s);
 
-       return err;
+       return ret;
 }
 EXPORT_SYMBOL_GPL(xnintr_attach);
 
@@ -788,24 +778,36 @@ EXPORT_SYMBOL_GPL(xnintr_attach);
  *
  * Rescheduling: never.
  */
-
 int xnintr_detach(xnintr_t *intr)
 {
-       int err;
+       int ret;
        spl_t s;
 
        trace_mark(xn_nucleus, irq_detach, "irq %u", intr->irq);
 
        xnlock_get_irqsave(&intrlock, s);
 
-       err = xnintr_irq_detach(intr);
+       if (intr->irq >= XNARCH_NR_IRQS) {
+               ret = -EINVAL;
+               goto out;
+       }
 
-       if (!err)
-               xnintr_stat_counter_dec();
+       if (!__testbits(intr->flags, XN_ISR_ATTACHED)) {
+               ret = -EPERM;
+               goto out;
+       }
 
+       __clrbits(intr->flags, XN_ISR_ATTACHED);
+
+       ret = xnintr_irq_detach(intr);
+       if (ret)
+               goto out;
+
+       xnintr_stat_counter_dec();
+ out:
        xnlock_put_irqrestore(&intrlock, s);
 
-       return err;
+       return ret;
 }
 EXPORT_SYMBOL_GPL(xnintr_detach);
 


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

Reply via email to