From: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
To: Borislav Petkov <bp@alien8.de>
Cc: shubhrajyoti.datta@amd.com, tony.luck@intel.com,
linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH 4/5] EDAC/versalnet: Fix device_register() error handling in init_one_mc()
Date: Wed, 1 Apr 2026 18:11:59 +0530 [thread overview]
Message-ID: <c2988216-cb2a-451f-b2a4-6eb5c8631a9f@linux.microsoft.com> (raw)
In-Reply-To: <20260324121656.GAacKAuPpPt9bjj15q@fat_crate.local>
Hi Boris,
On 24-03-2026 17:46, Borislav Petkov wrote:
> On Tue, Mar 24, 2026 at 12:23:12PM +0100, Borislav Petkov wrote:
>> So let's do it another way (totally untested ofc):
>
> AI found a couple of issues, here's v2:
>
> ---
> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
> index b87fe57aa842..953f96c8fd6f 100644
> --- a/drivers/edac/versalnet_edac.c
> +++ b/drivers/edac/versalnet_edac.c
> @@ -772,12 +772,11 @@ static void remove_one_mc(struct mc_priv *priv, int i)
> edac_mc_free(mci);
> }
>
> -static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i)
> +static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, struct device *dev, int i)
> {
> u32 num_chans, rank, dwidth, config;
> struct edac_mc_layer layers[2];
> struct mem_ctl_info *mci;
> - struct device *dev;
> enum dev_type dt;
> char *name;
> int rc;
> @@ -802,7 +801,7 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
> }
>
> if (dt == DEV_UNKNOWN)
> - return 0;
> + return -EINVAL;
>
> /* Find the first enabled device and register that one. */
> layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
> @@ -817,14 +816,10 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
> if (!name)
> return rc;
>
> - dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> - if (!dev)
> - goto err_name_free;
> -
> 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;
> + goto err_name_free;
> }
>
> sprintf(name, "versal-net-ddrmc5-edac-%d", i);
> @@ -856,8 +851,6 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
> device_unregister(mci->pdev);
> err_mc_free:
> edac_mc_free(mci);
> -err_dev_free:
> - kfree(dev);
> err_name_free:
> kfree(name);
>
> @@ -866,18 +859,26 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
>
> static int init_versalnet(struct mc_priv *priv, struct platform_device *pdev)
> {
> - int rc, i;
> + int rc = -ENOMEM, i;
>
> for (i = 0; i < NUM_CONTROLLERS; i++) {
> - rc = init_one_mc(priv, pdev, i);
> - if (rc) {
> - while (i--)
> - remove_one_mc(priv, i);
> + struct device *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> + if (!dev)
> + goto free;
>
> - return rc;
> + rc = init_one_mc(priv, pdev, dev, i);
> + if (rc) {
> + kfree(dev);
> + goto free;
> }
> }
> return 0;
> +
> +free:
> + while (i--)
> + remove_one_mc(priv, i);
> +
> + return rc;
> }
>
> static void remove_versalnet(struct mc_priv *priv)
>
>
Thanks for sharing this.
Without rearranging the code I have simplified the error path and sent v2.
Thanks,
Prasanna Kumar
next prev parent reply other threads:[~2026-04-01 12:42 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-22 13:11 [PATCH 1/5] EDAC/versalnet: Fix teardown ordering in mc_remove() Prasanna Kumar T S M
2026-03-22 13:11 ` [PATCH 2/5] EDAC/versalnet: Release reference to remoteproc device in remove Prasanna Kumar T S M
2026-03-22 15:59 ` Borislav Petkov
2026-03-23 7:25 ` Prasanna Kumar T S M
2026-03-22 13:11 ` [PATCH 3/5] EDAC/versalnet: Fix memory leak in remove and probe error paths Prasanna Kumar T S M
2026-03-22 19:15 ` Borislav Petkov
2026-03-22 13:11 ` [PATCH 4/5] EDAC/versalnet: Fix device_register() error handling in init_one_mc() Prasanna Kumar T S M
2026-03-22 16:10 ` Borislav Petkov
2026-03-23 7:08 ` Prasanna Kumar T S M
2026-03-24 11:23 ` Borislav Petkov
2026-03-24 12:16 ` Borislav Petkov
2026-04-01 12:41 ` Prasanna Kumar T S M [this message]
2026-03-22 13:11 ` [PATCH 5/5] EDAC/versalnet: Fix device name memory leak Prasanna Kumar T S M
2026-03-22 16:15 ` Borislav Petkov
2026-03-23 6:59 ` Prasanna Kumar T S M
2026-03-26 17:23 ` kernel test robot
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=c2988216-cb2a-451f-b2a4-6eb5c8631a9f@linux.microsoft.com \
--to=ptsm@linux.microsoft.com \
--cc=bp@alien8.de \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shubhrajyoti.datta@amd.com \
--cc=stable@vger.kernel.org \
--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