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 01/12] EDAC/versalnet: Fix device_register() error handling in init_one_mc()
Date: Fri, 20 Nov 2026 19:08:59 +0530 [thread overview]
Message-ID: <a25ac945-a2e4-44a4-9da6-948966db62a3@amd.com> (raw)
In-Reply-To: <20261118142213.100581-2-shubhrajyoti.datta@amd.com>
On 11/18/2026 7:50 PM, Shubhrajyoti Datta wrote:
> From: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
>
> When device_register() fails, it must be followed by put_device()
> rather than kfree(), because device_register() calls
> device_initialize() which sets up the device refcount. The matching
> release function versal_edac_release() handles the actual kfree().
>
> To simplify error handling and avoid complex unwinding, split
> device_register() into device_initialize() and device_add().
> Initialize the device early so put_device() can be used in all
> error paths.
>
> Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR controller")
> Cc: stable@vger.kernel.org
> Signed-off-by: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
> Co-developed-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Thanks!
> ---
>
> Changes in v2:
> Add the codeveloped tag and remove the non standard signature
> fix the name stack warning
>
> drivers/edac/versalnet_edac.c | 36 +++++++++++++++++------------------
> 1 file changed, 18 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
> index eae9fea60db1..89672d4d17c9 100644
> --- a/drivers/edac/versalnet_edac.c
> +++ b/drivers/edac/versalnet_edac.c
> @@ -70,8 +70,6 @@
> #define XDDR5_BUS_WIDTH_32 1
> #define XDDR5_BUS_WIDTH_16 2
>
> -#define MC_NAME_LEN 32
> -
> /**
> * struct ecc_error_info - ECC error log information.
> * @burstpos: Burst position.
> @@ -777,7 +775,6 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
> u32 num_chans, rank, dwidth, config;
> struct edac_mc_layer layers[2];
> struct mem_ctl_info *mci;
> - char name[MC_NAME_LEN];
> struct device *dev;
> enum dev_type dt;
> int rc;
> @@ -817,28 +814,31 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
> if (!dev)
> return rc;
>
> + dev->release = versal_edac_release;
> + device_initialize(dev);
> +
> + rc = dev_set_name(dev, "versal-net-ddrmc5-edac-%d", i);
> + if (rc)
> + goto err_put_dev;
> +
> + rc = device_add(dev);
> + if (rc)
> + goto err_put_dev;
> +
> mci = edac_mc_alloc(i, ARRAY_SIZE(layers), layers, sizeof(struct mc_priv));
> if (!mci) {
> edac_printk(KERN_ERR, EDAC_MC, "Failed memory allocation for MC%d\n", i);
> - goto err_dev_free;
> + rc = -ENOMEM;
> + goto err_dev_del;
> }
>
> - sprintf(name, "versal-net-ddrmc5-edac-%d", i);
> -
> - dev->init_name = name;
> - dev->release = versal_edac_release;
> -
> - rc = device_register(dev);
> - if (rc)
> - goto err_mc_free;
> -
> mci->pdev = dev;
> mc_init(mci, dev);
>
> rc = edac_mc_add_mc(mci);
> if (rc) {
> edac_printk(KERN_ERR, EDAC_MC, "Failed to register MC%d with EDAC core\n", i);
> - goto err_unreg;
> + goto err_mc_free;
> }
>
> priv->mci[i] = mci;
> @@ -848,12 +848,12 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
>
> return 0;
>
> -err_unreg:
> - device_unregister(mci->pdev);
> err_mc_free:
> edac_mc_free(mci);
> -err_dev_free:
> - kfree(dev);
> +err_dev_del:
> + device_del(dev);
> +err_put_dev:
> + put_device(dev);
>
> return rc;
> }
next prev parent reply other threads:[~2026-11-20 13:39 UTC|newest]
Thread overview: 16+ 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 [this message]
2026-11-18 14:20 ` [PATCH v2 02/12] EDAC/versalnet: Use designated initializer for rpmsg_channel_info Shubhrajyoti Datta
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-18 14:20 ` [PATCH v2 05/12] EDAC/versalnet: Make dwidth per-controller Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 06/12] EDAC/versalnet: Wait for RPMsg endpoint initialization Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 07/12] EDAC/versalnet: Initialize MCDI before RPMsg registration Shubhrajyoti Datta
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=a25ac945-a2e4-44a4-9da6-948966db62a3@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox