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

Author: Andreas Glatz <andreasgl...@ruggedcom.com>
Date:   Fri Feb 12 18:36:25 2010 -0500

nucleus: check IRQ object before attaching or detaching it

Added code to check if an interrupt object is attached/detached
right after calling xnintr_irq_attach()/xnintr_irq_detach() to
avoid re-attaching/detaching and interrupt object.

Now xnintr_destroy() returns the return value of xnintr_detach()
as described in the comment.

Signed-off-by: Andreas Glatz <andreasgl...@ruggedcom.com>

---

 ksrc/nucleus/intr.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/ksrc/nucleus/intr.c b/ksrc/nucleus/intr.c
index 50f7945..ace75d5 100644
--- a/ksrc/nucleus/intr.c
+++ b/ksrc/nucleus/intr.c
@@ -426,14 +426,29 @@ static inline xnintr_t *xnintr_shirq_next(xnintr_t *prev)
 
 static inline int xnintr_irq_attach(xnintr_t *intr)
 {
-       return xnarch_hook_irq(intr->irq, &xnintr_irq_handler,
+       int err;
+
+       if (__testbits(intr->flags, XN_ISR_ATTACHED))
+               return -EPERM;
+
+       err = xnarch_hook_irq(intr->irq, &xnintr_irq_handler,
                               (rthal_irq_ackfn_t)intr->iack, intr);
+
+       if (!err)
+               __setbits(intr->flags, XN_ISR_ATTACHED);
+
+       return err;
 }
 
 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);
+
        xnlock_get(&xnirqs[irq].lock);
        err = xnarch_release_irq(irq);
        xnlock_put(&xnirqs[irq].lock);
@@ -659,7 +674,7 @@ EXPORT_SYMBOL_GPL(xnintr_init);
  * @param intr The descriptor address of the interrupt object to
  * destroy.
  *
- * @return 0 is returned on success. Otherwise, -EBUSY is returned if
+ * @return 0 is returned on success. Otherwise, -EINVAL is returned if
  * an error occurred while detaching the interrupt (see
  * xnintr_detach()).
  *
@@ -675,8 +690,7 @@ EXPORT_SYMBOL_GPL(xnintr_init);
 
 int xnintr_destroy(xnintr_t *intr)
 {
-       xnintr_detach(intr);
-       return 0;
+       return xnintr_detach(intr);
 }
 EXPORT_SYMBOL_GPL(xnintr_destroy);
 


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

Reply via email to