From patchwork Tue Jul 20 21:41:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kanigeri, Hari" X-Patchwork-Id: 113089 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6KLV427032176 for ; Tue, 20 Jul 2010 21:31:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752122Ab0GTVbB (ORCPT ); Tue, 20 Jul 2010 17:31:01 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:60280 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752234Ab0GTVa6 (ORCPT ); Tue, 20 Jul 2010 17:30:58 -0400 Received: from dlep34.itg.ti.com ([157.170.170.115]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id o6KLUs9p005849 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 20 Jul 2010 16:30:55 -0500 Received: from legion.dal.design.ti.com (localhost [127.0.0.1]) by dlep34.itg.ti.com (8.13.7/8.13.7) with ESMTP id o6KLUsb6015500; Tue, 20 Jul 2010 16:30:54 -0500 (CDT) Received: from localhost (matrix.am.dhcp.ti.com [128.247.75.166]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id FBAG6ZP24215; Fri, 10 Dec 1915 11:06:35 -0500 (CDT) From: Hari Kanigeri To: Linux Omap , Tony Lindgren , Hiroshi DOYU Cc: Ohad Ben-Cohen , Hari Kanigeri Subject: [PATCH 1/2] omap:mailbox-make mailbox reference counter atomic Date: Tue, 20 Jul 2010 16:41:35 -0500 Message-Id: <1279662096-3121-2-git-send-email-h-kanigeri2@ti.com> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1279662096-3121-1-git-send-email-h-kanigeri2@ti.com> References: <1279662096-3121-1-git-send-email-h-kanigeri2@ti.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 20 Jul 2010 21:31:05 +0000 (UTC) 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); } }