[PATCH v1] EDAC/synopsys: Fix cleanup on injection sysfs failure

Yuho Choi posted 1 patch 4 days, 11 hours ago
There is a newer version of this series
drivers/edac/synopsys_edac.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
[PATCH v1] EDAC/synopsys: Fix cleanup on injection sysfs failure
Posted by Yuho Choi 4 days, 11 hours ago
edac_create_sysfs_attributes() creates inject_data_error before
inject_data_poison. If the second file creation fails, the first file is
left behind.

The same failure path runs after edac_mc_add_mc() has registered the
memory controller with the EDAC core. Jumping directly to edac_mc_free()
skips edac_mc_del_mc() and leaves the registered controller state
unwound incorrectly.

Remove inject_data_error when inject_data_poison creation fails, and
route the probe failure through edac_mc_del_mc() before freeing mci.

Fixes: 1a81361f75d8 ("EDAC, synopsys: Add Error Injection support for ZynqMP DDR controller")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
---
 drivers/edac/synopsys_edac.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c
index 51143b3257de..c395a1e97a36 100644
--- a/drivers/edac/synopsys_edac.c
+++ b/drivers/edac/synopsys_edac.c
@@ -1120,8 +1120,10 @@ static int edac_create_sysfs_attributes(struct mem_ctl_info *mci)
 	if (rc < 0)
 		return rc;
 	rc = device_create_file(&mci->dev, &dev_attr_inject_data_poison);
-	if (rc < 0)
+	if (rc < 0) {
+		device_remove_file(&mci->dev, &dev_attr_inject_data_error);
 		return rc;
+	}
 	return 0;
 }
 
@@ -1431,7 +1433,7 @@ static int mc_probe(struct platform_device *pdev)
 		if (rc) {
 			edac_printk(KERN_ERR, EDAC_MC,
 					"Failed to create sysfs entries\n");
-			goto free_edac_mc;
+			goto del_mc;
 		}
 	}
 
@@ -1448,6 +1450,10 @@ static int mc_probe(struct platform_device *pdev)
 
 	return rc;
 
+#ifdef CONFIG_EDAC_DEBUG
+del_mc:
+	edac_mc_del_mc(&pdev->dev);
+#endif
 free_edac_mc:
 	edac_mc_free(mci);
 
-- 
2.43.0
Re: [PATCH v1] EDAC/synopsys: Fix cleanup on injection sysfs failure
Posted by Michal Simek 2 days, 23 hours ago

On 6/3/26 22:47, Yuho Choi wrote:
> edac_create_sysfs_attributes() creates inject_data_error before
> inject_data_poison. If the second file creation fails, the first file is
> left behind.
> 
> The same failure path runs after edac_mc_add_mc() has registered the
> memory controller with the EDAC core. Jumping directly to edac_mc_free()
> skips edac_mc_del_mc() and leaves the registered controller state
> unwound incorrectly.
> 
> Remove inject_data_error when inject_data_poison creation fails, and
> route the probe failure through edac_mc_del_mc() before freeing mci.
> 
> Fixes: 1a81361f75d8 ("EDAC, synopsys: Add Error Injection support for ZynqMP DDR controller")
> Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
> ---
>   drivers/edac/synopsys_edac.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/edac/synopsys_edac.c b/drivers/edac/synopsys_edac.c
> index 51143b3257de..c395a1e97a36 100644
> --- a/drivers/edac/synopsys_edac.c
> +++ b/drivers/edac/synopsys_edac.c
> @@ -1120,8 +1120,10 @@ static int edac_create_sysfs_attributes(struct mem_ctl_info *mci)
>   	if (rc < 0)
>   		return rc;
>   	rc = device_create_file(&mci->dev, &dev_attr_inject_data_poison);
> -	if (rc < 0)
> +	if (rc < 0) {
> +		device_remove_file(&mci->dev, &dev_attr_inject_data_error);
>   		return rc;
> +	}
>   	return 0;
>   }
>   
> @@ -1431,7 +1433,7 @@ static int mc_probe(struct platform_device *pdev)
>   		if (rc) {
>   			edac_printk(KERN_ERR, EDAC_MC,
>   					"Failed to create sysfs entries\n");
> -			goto free_edac_mc;
> +			goto del_mc;
>   		}
>   	}
>   
> @@ -1448,6 +1450,10 @@ static int mc_probe(struct platform_device *pdev)
>   
>   	return rc;
>   
> +#ifdef CONFIG_EDAC_DEBUG

I don't think this is nice way how to do it. I would do it above to avoid using 
ifdefs here.

like this
    		if (rc) {
    			edac_printk(KERN_ERR, EDAC_MC,
    					"Failed to create sysfs entries\n");
			edac_mc_del_mc(&pdev->dev);
			goto free_edac_mc;

    		}
    	}

The patch itself is correct.

Thanks,
Michal
Re: [PATCH v1] EDAC/synopsys: Fix cleanup on injection sysfs failure
Posted by 최유호 2 days, 20 hours ago
Dear Michal

I appreciate your time reviewing this.

On Fri, 5 Jun 2026 at 05:03, Michal Simek <michal.simek@amd.com> wrote:

> I don't think this is nice way how to do it. I would do it above to avoid using
> ifdefs here.
>
> like this
>                 if (rc) {
>                         edac_printk(KERN_ERR, EDAC_MC,
>                                         "Failed to create sysfs entries\n");
>                         edac_mc_del_mc(&pdev->dev);
>                         goto free_edac_mc;
>
>                 }
>         }
>
Yes, that is cleaner.
I'll update it as suggested and send v2.

Thanks,
Yuho