From: "Pandey, Radhey Shyam" <radheys@amd.com>
To: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>,
linux-edac@vger.kernel.org
Cc: git@amd.com, shubhrajyoti.datta@gmail.com, michal.simek@amd.com,
Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Rob Herring <robh@kernel.org>, Conor Dooley <conor+dt@kernel.org>,
Borislav Petkov <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 07/12] EDAC/versalnet: Initialize MCDI before RPMsg registration
Date: Sat, 21 Nov 2026 21:03:33 +0530 [thread overview]
Message-ID: <8e15faa8-cd1e-4ea2-bd91-fe419cb8b545@amd.com> (raw)
In-Reply-To: <20261118142213.100581-8-shubhrajyoti.datta@amd.com>
On 11/18/2026 7:50 PM, Shubhrajyoti Datta wrote:
> setup_mcdi() currently allocates the MCDI instance, assigns the RPMsg
> endpoint, and retrieves DDR configuration data. The DDR configuration
> path invokes cdx_mcdi_rpc(), which requires a functional RPMsg endpoint.
>
> Split setup_mcdi() so that only MCDI allocation and initialization are
> performed before RPMsg registration. Update the error paths to match
> the new initialization order, ensuring resources are released in
> reverse order of acquisition.
>
All three from the earlier review. setup_mcdi() now precedes
register_rpmsg_driver(), so rpmsg_probe() can't deref a NULL priv->mcdi.
The get_ddr_config() loop moved below the completion wait, so the
endpoint is live before first use. err_init unregisters the rpmsg driver
before cdx_mcdi_finish()/kfree(), so rpmsg_remove() can't write through
freed memory.
I suggest squashing this into the previous patch so that the series
does not introduce a bug that is fixed by a subsequent patch.
> Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR controller")
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
> ---
>
> Changes in v2:
> Update the labels
> this fixes the sashiko comment
> "register_rpmsg_driver() exposes the callback endpoint before setup_mcdi()
> initializes the mcdi pointer. Could this lead to a NULL pointer dereference
> if a response arrives early?"
>
> drivers/edac/versalnet_edac.c | 27 +++++++++++++--------------
> 1 file changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
> index 90918293f76d..046293d54d40 100644
> --- a/drivers/edac/versalnet_edac.c
> +++ b/drivers/edac/versalnet_edac.c
> @@ -605,7 +605,7 @@ static void get_ddr_config(u32 index, u32 *buffer, struct cdx_mcdi *amd_mcdi)
> static int setup_mcdi(struct mc_priv *mc_priv)
> {
> struct cdx_mcdi *amd_mcdi;
> - int ret, i;
> + int ret;
>
> amd_mcdi = kzalloc_obj(*amd_mcdi);
> if (!amd_mcdi)
> @@ -618,12 +618,8 @@ static int setup_mcdi(struct mc_priv *mc_priv)
> return ret;
> }
>
> - amd_mcdi->ept = mc_priv->ept;
> mc_priv->mcdi = amd_mcdi;
>
> - for (i = 0; i < NUM_CONTROLLERS; i++)
> - get_ddr_config(i, &mc_priv->adec[ADEC_NUM * i], amd_mcdi);
> -
> return 0;
> }
>
> @@ -978,7 +974,7 @@ static int mc_probe(struct platform_device *pdev)
> {
> struct mc_priv *priv;
> struct rproc *rp;
> - int rc;
> + int rc, i;
>
> struct device_node *r5_core_node __free(device_node) =
> of_parse_phandle(pdev->dev.of_node, "amd,rproc", 0);
> @@ -1008,16 +1004,16 @@ static int mc_probe(struct platform_device *pdev)
> init_completion(&priv->rpmsg_ready);
> amd_rpmsg_id_table[0].driver_data = (kernel_ulong_t)priv;
>
> + rc = setup_mcdi(priv);
> + if (rc)
> + goto err_alloc;
> +
> rc = register_rpmsg_driver(&amd_rpmsg_driver);
> if (rc) {
> edac_printk(KERN_ERR, EDAC_MC, "Failed to register RPMsg driver: %d\n", rc);
> - goto err_alloc;
> + goto err_reg;
> }
>
> - rc = setup_mcdi(priv);
> - if (rc)
> - goto err_unreg;
> -
> if (!wait_for_completion_timeout(&priv->rpmsg_ready, MCDI_RPC_TIMEOUT)) {
> dev_err(&pdev->dev, "Timed out waiting for RPMsg endpoint\n");
> rc = -ENODEV;
> @@ -1026,6 +1022,9 @@ static int mc_probe(struct platform_device *pdev)
>
> priv->mcdi->r5_rproc = rp;
>
> + for (i = 0; i < NUM_CONTROLLERS; i++)
> + get_ddr_config(i, &priv->adec[ADEC_NUM * i], priv->mcdi);
> +
> rc = init_versalnet(priv, pdev);
> if (rc)
> goto err_init;
> @@ -1040,12 +1039,12 @@ static int mc_probe(struct platform_device *pdev)
> return 0;
>
> err_init:
> + unregister_rpmsg_driver(&amd_rpmsg_driver);
> +
> +err_reg:
> cdx_mcdi_finish(priv->mcdi);
> kfree(priv->mcdi);
>
> -err_unreg:
> - unregister_rpmsg_driver(&amd_rpmsg_driver);
> -
> err_alloc:
> rproc_shutdown(rp);
>
next prev parent reply other threads:[~2026-11-21 15:33 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 14:20 [PATCH v2 00/12] EDAC/versalnet: Fix error handling, teardown, and robustness Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 01/12] EDAC/versalnet: Fix device_register() error handling in init_one_mc() Shubhrajyoti Datta
2026-11-20 13:38 ` Pandey, Radhey Shyam
2026-11-18 14:20 ` [PATCH v2 02/12] EDAC/versalnet: Use designated initializer for rpmsg_channel_info Shubhrajyoti Datta
2026-11-20 13:39 ` Pandey, Radhey Shyam
2026-11-18 14:20 ` [PATCH v2 03/12] EDAC/versalnet: Fix use-after-free in remove_one_mc() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 04/12] EDAC/versalnet: Add bounds validation in rpmsg_cb() Shubhrajyoti Datta
2026-11-18 14:33 ` sashiko-bot
2026-11-20 12:18 ` Datta, Shubhrajyoti
2026-11-20 15:43 ` Pandey, Radhey Shyam
2026-11-18 14:20 ` [PATCH v2 05/12] EDAC/versalnet: Make dwidth per-controller Shubhrajyoti Datta
2026-11-20 16:54 ` Pandey, Radhey Shyam
2026-11-18 14:20 ` [PATCH v2 06/12] EDAC/versalnet: Wait for RPMsg endpoint initialization Shubhrajyoti Datta
2026-11-21 15:28 ` Pandey, Radhey Shyam
2026-11-18 14:20 ` [PATCH v2 07/12] EDAC/versalnet: Initialize MCDI before RPMsg registration Shubhrajyoti Datta
2026-11-21 15:33 ` Pandey, Radhey Shyam [this message]
2026-11-18 14:20 ` [PATCH v2 08/12] EDAC/versalnet: Guard against NULL drvdata in rpmsg_cb() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 09/12] EDAC/versalnet: Move platform_set_drvdata() to mc_probe() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 10/12] dt-bindings: memory: xlnx,versal-net-ddrmc5: Add amd,num-ctrl property Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 11/12] EDAC/versalnet: use device tree property for number of controllers Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 12/12] EDAC/versalnet: Make get_ddr_config() return errors Shubhrajyoti Datta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8e15faa8-cd1e-4ea2-bd91-fe419cb8b545@amd.com \
--to=radheys@amd.com \
--cc=bp@alien8.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=git@amd.com \
--cc=krzk@kernel.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=radhey.shyam.pandey@amd.com \
--cc=robh@kernel.org \
--cc=shubhrajyoti.datta@amd.com \
--cc=shubhrajyoti.datta@gmail.com \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.