diff mbox

[1/2] omap:mailbox-make mailbox reference counter atomic

Message ID 1279662096-3121-2-git-send-email-h-kanigeri2@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kanigeri, Hari July 20, 2010, 9:41 p.m. UTC
None
diff mbox

Patch

diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c
index b06d3de..baac315 100644
--- a/arch/arm/plat-omap/mailbox.c
+++ b/arch/arm/plat-omap/mailbox.c
@@ -35,7 +35,7 @@  static struct omap_mbox *mboxes;
 static DEFINE_SPINLOCK(mboxes_lock);
 static bool rq_full;
 
-static int mbox_configured;
+static atomic_t mbox_refcount = ATOMIC_INIT(0);
 
 /* Mailbox FIFO handle functions */
 static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
@@ -243,16 +243,13 @@  static int omap_mbox_startup(struct omap_mbox *mbox)
 	struct omap_mbox_queue *mq;
 
 	if (likely(mbox->ops->startup)) {
-		spin_lock(&mboxes_lock);
-		if (!mbox_configured)
+		if (atomic_inc_return(&mbox_refcount) == 1)
 			ret = mbox->ops->startup(mbox);
 
 		if (unlikely(ret)) {
-			spin_unlock(&mboxes_lock);
+			atomic_dec(&mbox_refcount);
 			return ret;
 		}
-		mbox_configured++;
-		spin_unlock(&mboxes_lock);
 	}
 
 	ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
@@ -284,8 +281,10 @@  static int omap_mbox_startup(struct omap_mbox *mbox)
  fail_alloc_txq:
 	free_irq(mbox->irq, mbox);
  fail_request_irq:
-	if (likely(mbox->ops->shutdown))
-		mbox->ops->shutdown(mbox);
+	if (likely(mbox->ops->shutdown)) {
+		if (atomic_dec_return(&mbox_refcount) == 0)
+			mbox->ops->shutdown(mbox);
+	}
 
 	return ret;
 }
@@ -298,12 +297,8 @@  static void omap_mbox_fini(struct omap_mbox *mbox)
 	free_irq(mbox->irq, mbox);
 
 	if (likely(mbox->ops->shutdown)) {
-		spin_lock(&mboxes_lock);
-		if (mbox_configured > 0)
-			mbox_configured--;
-		if (!mbox_configured)
+		if (atomic_dec_return(&mbox_refcount) == 0)
 			mbox->ops->shutdown(mbox);
-		spin_unlock(&mboxes_lock);
 	}
 }