Skip to content

Commit 2d805fc

Browse files
bleungatchromiumJassiBrar
authored andcommitted
mailbox: Fix up error handling in mbox_request_channel()
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 <[email protected]> Signed-off-by: Andrew Bresticker <[email protected]> Acked-by: Suman Anna <[email protected]> Reviewed-by: Jon Hunter <[email protected]> Tested-by: Jon Hunter <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent 05ae797 commit 2d805fc

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

drivers/mailbox/mailbox.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
318318
return ERR_PTR(-ENODEV);
319319
}
320320

321-
chan = NULL;
321+
chan = ERR_PTR(-EPROBE_DEFER);
322322
list_for_each_entry(mbox, &mbox_cons, node)
323323
if (mbox->dev->of_node == spec.np) {
324324
chan = mbox->of_xlate(mbox, &spec);
@@ -327,7 +327,12 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
327327

328328
of_node_put(spec.np);
329329

330-
if (!chan || chan->cl || !try_module_get(mbox->dev->driver->owner)) {
330+
if (IS_ERR(chan)) {
331+
mutex_unlock(&con_mutex);
332+
return chan;
333+
}
334+
335+
if (chan->cl || !try_module_get(mbox->dev->driver->owner)) {
331336
dev_dbg(dev, "%s: mailbox not free\n", __func__);
332337
mutex_unlock(&con_mutex);
333338
return ERR_PTR(-EBUSY);
@@ -390,7 +395,7 @@ of_mbox_index_xlate(struct mbox_controller *mbox,
390395
int ind = sp->args[0];
391396

392397
if (ind >= mbox->num_chans)
393-
return NULL;
398+
return ERR_PTR(-EINVAL);
394399

395400
return &mbox->chans[ind];
396401
}

drivers/mailbox/omap-mailbox.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,18 +639,18 @@ static struct mbox_chan *omap_mbox_of_xlate(struct mbox_controller *controller,
639639

640640
mdev = container_of(controller, struct omap_mbox_device, controller);
641641
if (WARN_ON(!mdev))
642-
return NULL;
642+
return ERR_PTR(-EINVAL);
643643

644644
node = of_find_node_by_phandle(phandle);
645645
if (!node) {
646646
pr_err("%s: could not find node phandle 0x%x\n",
647647
__func__, phandle);
648-
return NULL;
648+
return ERR_PTR(-ENODEV);
649649
}
650650

651651
mbox = omap_mbox_device_find(mdev, node->name);
652652
of_node_put(node);
653-
return mbox ? mbox->chan : NULL;
653+
return mbox ? mbox->chan : ERR_PTR(-ENOENT);
654654
}
655655

656656
static int omap_mbox_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)