Re: [PATCH v4 1/3] misc: fastrpc: iterate CB nodes manually instead of of_platform_populate
From: Ekansh Gupta
Date: Mon Sep 21 2026 - 05:24:44 EST
On 26-08-2026 18:55, Vinayak Katoch wrote:
> of_platform_populate() only guarantees that child devices are registered,
> not that their probes have completed before it returns. This creates a
> window where fastrpc_cb_init() may not have run for all context bank
> nodes, leaving the channel context partially initialised.
>
> Iterate over the child device tree nodes directly, initialising each
> qcom,fastrpc-compute-cb device synchronously. This ensures all context
> banks are fully initialised before fastrpc_rpmsg_probe() returns. Since
> fastrpc_cb_driver is no longer needed as an independent platform driver,
> remove it along with its match table and remove callback. Set
> OF_POPULATED_BUS on the rpmsg node so that of_platform_depopulate()
> correctly removes the manually created CB devices on teardown.
>
> Signed-off-by: Vinayak Katoch <vinayak.katoch@xxxxxxxxxxxxxxxx>
> ---
> drivers/misc/fastrpc.c | 83 ++++++++++++++++++--------------------------------
> 1 file changed, 29 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index d4fac2caca86..a153107d0085 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -2363,7 +2363,7 @@ static const struct file_operations fastrpc_fops = {
> .compat_ioctl = fastrpc_device_ioctl,
> };
>
> -static int fastrpc_cb_probe(struct platform_device *pdev)
> +static int fastrpc_cb_init(struct platform_device *pdev)
> {
> struct fastrpc_channel_ctx *cctx;
> struct fastrpc_session_ctx *sess;
> @@ -2385,7 +2385,7 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
> spin_lock_irqsave(&cctx->lock, flags);
> if (cctx->sesscount >= FASTRPC_MAX_SESSIONS) {
> spin_unlock_irqrestore(&cctx->lock, flags);
> - dev_err(&pdev->dev, "too many sessions\n");
> + dev_err(dev, "too many sessions\n");
> return -ENOSPC;
> }
> dma_bits = cctx->soc_data->dma_addr_bits_default;
> @@ -2419,38 +2419,6 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
> return 0;
> }
>
> -static void fastrpc_cb_remove(struct platform_device *pdev)
> -{
> - struct fastrpc_channel_ctx *cctx = dev_get_drvdata(pdev->dev.parent);
> - struct fastrpc_session_ctx *sess = dev_get_drvdata(&pdev->dev);
> - unsigned long flags;
> - int i;
> -
> - spin_lock_irqsave(&cctx->lock, flags);
> - for (i = 0; i < FASTRPC_MAX_SESSIONS; i++) {
> - if (cctx->session[i].sid == sess->sid) {
> - cctx->session[i].valid = false;
> - cctx->sesscount--;
> - }
> - }
> - spin_unlock_irqrestore(&cctx->lock, flags);
> -}
> -
> -static const struct of_device_id fastrpc_match_table[] = {
> - { .compatible = "qcom,fastrpc-compute-cb" },
> - { }
> -};
> -
> -static struct platform_driver fastrpc_cb_driver = {
> - .probe = fastrpc_cb_probe,
> - .remove = fastrpc_cb_remove,
> - .driver = {
> - .name = "qcom,fastrpc-cb",
> - .of_match_table = fastrpc_match_table,
> - .suppress_bind_attrs = true,
> - },
> -};
> -
> static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctx *cctx,
> bool is_secured, const char *domain)
> {
> @@ -2642,12 +2610,29 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
> data->rpdev = rpdev;
> dev_set_drvdata(&rpdev->dev, data);
>
> - err = of_platform_populate(rdev->of_node, NULL, NULL, rdev);
> - if (err)
> - goto err_deregister_fdev;
> + of_node_set_flag(rdev->of_node, OF_POPULATED_BUS);
> +
> + for_each_available_child_of_node_scoped(rdev->of_node, np) {
> + struct platform_device *pdev;
> +
> + if (!of_device_is_compatible(np, "qcom,fastrpc-compute-cb"))
> + continue;
> +
> + pdev = of_platform_device_create(np, NULL, rdev);
> + if (!pdev) {
> + err = -EINVAL;
> + goto err_depopulate;
> + }
> +
> + err = fastrpc_cb_init(pdev);
> + if (err)
> + goto err_depopulate;
> + }
>
> return 0;
>
> +err_depopulate:
> + of_platform_depopulate(rdev);
> err_deregister_fdev:
> if (data->fdevice)
> misc_deregister(&data->fdevice->miscdev);
> @@ -2677,6 +2662,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
> struct fastrpc_buf *buf, *b;
> struct fastrpc_user *user;
> unsigned long flags;
> + int i;
>
> /* No invocations past this point */
> spin_lock_irqsave(&cctx->lock, flags);
> @@ -2697,6 +2683,11 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
> if (cctx->remote_heap)
> fastrpc_buf_free(cctx->remote_heap);
>
> + spin_lock_irqsave(&cctx->lock, flags);
> + for (i = 0; i < FASTRPC_MAX_SESSIONS; i++)
> + cctx->session[i].valid = false;
> + spin_unlock_irqrestore(&cctx->lock, flags);
> +
> of_platform_depopulate(&rpdev->dev);
should this also be removed?>
> fastrpc_channel_ctx_put(cctx);
> @@ -2786,28 +2777,12 @@ static struct rpmsg_driver fastrpc_driver = {
>
> static int fastrpc_init(void)
> {
> - int ret;
> -
> - ret = platform_driver_register(&fastrpc_cb_driver);
> - if (ret < 0) {
> - pr_err("fastrpc: failed to register cb driver\n");
> - return ret;
> - }
> -
> - ret = register_rpmsg_driver(&fastrpc_driver);
> - if (ret < 0) {
> - pr_err("fastrpc: failed to register rpmsg driver\n");
> - platform_driver_unregister(&fastrpc_cb_driver);
> - return ret;
> - }
> -
> - return 0;
> + return register_rpmsg_driver(&fastrpc_driver);
> }
> module_init(fastrpc_init);
can you use module_rpmsg_driver() instead?>
> static void fastrpc_exit(void)
> {
> - platform_driver_unregister(&fastrpc_cb_driver);
> unregister_rpmsg_driver(&fastrpc_driver);
> }
> module_exit(fastrpc_exit);
>