summaryrefslogtreecommitdiffstats
path: root/drivers/mailbox
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2018-12-20 12:19:44 -0500
committerJassi Brar <jaswinder.singh@linaro.org>2018-12-21 17:49:25 -0500
commite898d9cdd3a9f105863d63dd3b46443742a4757c (patch)
tree48a3a80b84cc3a18b1589454d129c8b70cf18841 /drivers/mailbox
parente2affdbef2aca880f4b9e758779c72540db5f168 (diff)
mailbox: Add device-managed registration functions
Add device-managed equivalents of the mbox_controller_register() and mbox_controller_unregister() functions that can be used to have the devres infrastructure automatically unregister mailbox controllers on driver probe failure or driver removal. This can help remove a lot of boiler plate code from drivers. Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
Diffstat (limited to 'drivers/mailbox')
-rw-r--r--drivers/mailbox/mailbox.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 674b35f402f5..08ce9a1ab53a 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -515,3 +515,73 @@ void mbox_controller_unregister(struct mbox_controller *mbox)
515 mutex_unlock(&con_mutex); 515 mutex_unlock(&con_mutex);
516} 516}
517EXPORT_SYMBOL_GPL(mbox_controller_unregister); 517EXPORT_SYMBOL_GPL(mbox_controller_unregister);
518
519static void __devm_mbox_controller_unregister(struct device *dev, void *res)
520{
521 struct mbox_controller **mbox = res;
522
523 mbox_controller_unregister(*mbox);
524}
525
526static int devm_mbox_controller_match(struct device *dev, void *res, void *data)
527{
528 struct mbox_controller **mbox = res;
529
530 if (WARN_ON(!mbox || !*mbox))
531 return 0;
532
533 return *mbox == data;
534}
535
536/**
537 * devm_mbox_controller_register() - managed mbox_controller_register()
538 * @dev: device owning the mailbox controller being registered
539 * @mbox: mailbox controller being registered
540 *
541 * This function adds a device-managed resource that will make sure that the
542 * mailbox controller, which is registered using mbox_controller_register()
543 * as part of this function, will be unregistered along with the rest of
544 * device-managed resources upon driver probe failure or driver removal.
545 *
546 * Returns 0 on success or a negative error code on failure.
547 */
548int devm_mbox_controller_register(struct device *dev,
549 struct mbox_controller *mbox)
550{
551 struct mbox_controller **ptr;
552 int err;
553
554 ptr = devres_alloc(__devm_mbox_controller_unregister, sizeof(*ptr),
555 GFP_KERNEL);
556 if (!ptr)
557 return -ENOMEM;
558
559 err = mbox_controller_register(mbox);
560 if (err < 0) {
561 devres_free(ptr);
562 return err;
563 }
564
565 devres_add(dev, ptr);
566 *ptr = mbox;
567
568 return 0;
569}
570EXPORT_SYMBOL_GPL(devm_mbox_controller_register);
571
572/**
573 * devm_mbox_controller_unregister() - managed mbox_controller_unregister()
574 * @dev: device owning the mailbox controller being unregistered
575 * @mbox: mailbox controller being unregistered
576 *
577 * This function unregisters the mailbox controller and removes the device-
578 * managed resource that was set up to automatically unregister the mailbox
579 * controller on driver probe failure or driver removal. It's typically not
580 * necessary to call this function.
581 */
582void devm_mbox_controller_unregister(struct device *dev, struct mbox_controller *mbox)
583{
584 WARN_ON(devres_release(dev, __devm_mbox_controller_unregister,
585 devm_mbox_controller_match, mbox));
586}
587EXPORT_SYMBOL_GPL(devm_mbox_controller_unregister);