[PATCH 5/9] EDAC/versalnet: Use dev_set_name() instead of sprintf with init_name
From: Shubhrajyoti Datta
Date: Fri Jul 24 2026 - 13:26:03 EST
The previous code used sprintf() to format a device name into a local
stack buffer and then assigned it to dev->init_name. Since kobject
cleanup can be deferred asynchronously (e.g. when
CONFIG_DEBUG_KOBJECT_RELEASE is enabled), dev_name(dev) could be
accessed after init_one_mc() returns and the stack frame containing the
name buffer is gone, resulting in a use-after-free.
This is fixed by switching to dev_set_name(), which dynamically
allocates and manages the name string internally, but the now-unused
local char name[MC_NAME_LEN] buffer and the MC_NAME_LEN macro are
not needed so remove them.
Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xxxxxxx>
---
drivers/edac/versalnet_edac.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
index 3c9eaea5a106..1caaba653fc0 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.
@@ -782,7 +780,6 @@ static int init_one_mc(struct mc_priv *priv, 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 = -ENOMEM;
@@ -821,9 +818,7 @@ static int init_one_mc(struct mc_priv *priv, int i)
if (!dev)
return rc;
- sprintf(name, "versal-net-ddrmc5-edac-%d", i);
- dev->init_name = name;
dev->release = versal_edac_release;
device_initialize(dev);
@@ -833,6 +828,10 @@ static int init_one_mc(struct mc_priv *priv, int i)
goto err_put_dev;
}
+ rc = dev_set_name(dev, "versal-net-ddrmc5-edac-%d", i);
+ if (rc)
+ goto err_mc_free;
+
rc = device_add(dev);
if (rc)
goto err_mc_free;
--
2.34.1