From patchwork Wed Jun 23 00:11:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ohad Ben Cohen X-Patchwork-Id: 107519 X-Patchwork-Delegate: hiroshi.doyu@nokia.com 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 o5N0C8TS022157 for ; Wed, 23 Jun 2010 00:12:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752953Ab0FWALs (ORCPT ); Tue, 22 Jun 2010 20:11:48 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:40371 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752914Ab0FWALq (ORCPT ); Tue, 22 Jun 2010 20:11:46 -0400 Received: by wyi11 with SMTP id 11so338218wyi.19 for ; Tue, 22 Jun 2010 17:11:45 -0700 (PDT) Received: by 10.216.89.202 with SMTP id c52mr5250402wef.66.1277251905253; Tue, 22 Jun 2010 17:11:45 -0700 (PDT) Received: from localhost.localdomain (89-139-43-41.bb.netvision.net.il [89.139.43.41]) by mx.google.com with ESMTPS id d37sm5042171wej.42.2010.06.22.17.11.43 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 22 Jun 2010 17:11:44 -0700 (PDT) From: Ohad Ben-Cohen To: Cc: Hiroshi Doyu , Omar Ramirez Luna , Ohad Ben-Cohen Subject: [PATCH 2/4] omap mailbox: prevent multiple concurrent receivers race Date: Wed, 23 Jun 2010 03:11:34 +0300 Message-Id: <1277251896-6890-2-git-send-email-ohad@wizery.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1277251896-6890-1-git-send-email-ohad@wizery.com> References: <1277251896-6890-1-git-send-email-ohad@wizery.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]); Wed, 23 Jun 2010 00:12:09 +0000 (UTC) diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h index 0b45664..5df35b4 100644 --- a/arch/arm/plat-omap/include/plat/mailbox.h +++ b/arch/arm/plat-omap/include/plat/mailbox.h @@ -57,6 +57,7 @@ struct omap_mbox { struct omap_mbox_ops *ops; struct device *dev; void *priv; + atomic_t count; }; int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg); diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 14b716d..aafa63f 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -320,9 +320,17 @@ struct omap_mbox *omap_mbox_get(const char *name, int (*callback)(void *)) if (!mbox) return ERR_PTR(-ENOENT); + if (atomic_inc_return(&mbox->count) > 1) { + pr_err("%s: mbox %s already in use\n", __func__, name); + atomic_dec(&mbox->count); + return ERR_PTR(-EBUSY); + } + ret = omap_mbox_startup(mbox); - if (ret) + if (ret) { + atomic_dec(&mbox->count); return ERR_PTR(-ENODEV); + } mbox->rxq->callback = callback; @@ -333,6 +341,7 @@ EXPORT_SYMBOL(omap_mbox_get); void omap_mbox_put(struct omap_mbox *mbox) { omap_mbox_fini(mbox); + atomic_dec(&mbox->count); } EXPORT_SYMBOL(omap_mbox_put); @@ -349,6 +358,7 @@ int omap_mbox_register(struct device *parent, struct omap_mbox **list) for (i = 0; mboxes[i]; i++) { struct omap_mbox *mbox = mboxes[i]; + atomic_set(&mbox->count, 0); mbox->dev = device_create(&omap_mbox_class, parent, 0, mbox, "%s", mbox->name); if (IS_ERR(mbox->dev)) {