@@ -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);
@@ -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)) {