mailbox: Fix up error handling in mbox_request_channel()
authorBenson Leung <bleung@chromium.org>
Mon, 4 May 2015 17:36:36 +0000 (10:36 -0700)
committerJassi Brar <jaswinder.singh@linaro.org>
Tue, 12 May 2015 03:48:21 +0000 (09:18 +0530)
mbox_request_channel() currently returns EBUSY in the event the controller
is not present or if of_xlate() fails, but in neither case is EBUSY really
appropriate.  Return EPROBE_DEFER if the controller is not yet present
and change of_xlate() to return an ERR_PTR instead of NULL so that the
error can be propagated back to the caller of mbox_request_channel().

Signed-off-by: Benson Leung <bleung@chromium.org>
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Acked-by: Suman Anna <s-anna@ti.com>
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
drivers/mailbox/mailbox.c
drivers/mailbox/omap-mailbox.c

index 19b491d2964f313744513920803e1c327305d7f9..c3c42d42d017c64b319c0b1ae1069da644cf46a2 100644 (file)
@@ -318,7 +318,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
                return ERR_PTR(-ENODEV);
        }
 
-       chan = NULL;
+       chan = ERR_PTR(-EPROBE_DEFER);
        list_for_each_entry(mbox, &mbox_cons, node)
                if (mbox->dev->of_node == spec.np) {
                        chan = mbox->of_xlate(mbox, &spec);
@@ -327,7 +327,12 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
 
        of_node_put(spec.np);
 
-       if (!chan || chan->cl || !try_module_get(mbox->dev->driver->owner)) {
+       if (IS_ERR(chan)) {
+               mutex_unlock(&con_mutex);
+               return chan;
+       }
+
+       if (chan->cl || !try_module_get(mbox->dev->driver->owner)) {
                dev_dbg(dev, "%s: mailbox not free\n", __func__);
                mutex_unlock(&con_mutex);
                return ERR_PTR(-EBUSY);
@@ -390,7 +395,7 @@ of_mbox_index_xlate(struct mbox_controller *mbox,
        int ind = sp->args[0];
 
        if (ind >= mbox->num_chans)
-               return NULL;
+               return ERR_PTR(-EINVAL);
 
        return &mbox->chans[ind];
 }
index 03f8545ba0371488abbc33b5252dab29def02828..a3dbfd9c647994ec6794701cfc25a327739640ad 100644 (file)
@@ -639,18 +639,18 @@ static struct mbox_chan *omap_mbox_of_xlate(struct mbox_controller *controller,
 
        mdev = container_of(controller, struct omap_mbox_device, controller);
        if (WARN_ON(!mdev))
-               return NULL;
+               return ERR_PTR(-EINVAL);
 
        node = of_find_node_by_phandle(phandle);
        if (!node) {
                pr_err("%s: could not find node phandle 0x%x\n",
                       __func__, phandle);
-               return NULL;
+               return ERR_PTR(-ENODEV);
        }
 
        mbox = omap_mbox_device_find(mdev, node->name);
        of_node_put(node);
-       return mbox ? mbox->chan : NULL;
+       return mbox ? mbox->chan : ERR_PTR(-ENOENT);
 }
 
 static int omap_mbox_probe(struct platform_device *pdev)