[PATCH v8 02/22] EDAC: ghes: avoid traversing the GHES device list

From: Ahmed Tiba

Date: Thu Dec 03 2026 - 08:40:43 EST


ghes_edac_init() and ghes_edac_exit() walk the global GHES device list
without the mutex used by GHES probe and removal. Concurrent device
removal can therefore invalidate an entry while EDAC is traversing it.

GHES EDAC exposes one logical memory controller and receives reports
through the global GHES notifier chain, so it only needs one GHES device
as the parent of the controller. Find a device bound to the built-in
GHES driver through the driver core and retain the device reference until
module exit. This removes the EDAC dependency on the lifetime of struct
ghes and the associated list entry.

Reported-by: sashiko-bot@xxxxxxxxxx
Link: https://sashiko.dev/#/message/20260708141859.0FA971F000E9%40smtp.kernel.org
Fixes: 802e7f1dfed7 ("EDAC/ghes: Make ghes_edac a proper module")
Signed-off-by: Ahmed Tiba <ahmed.tiba@xxxxxxx>
---
drivers/edac/ghes_edac.c | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index d80c88818691..df36b3b9d8dd 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -15,6 +15,8 @@
#include "edac_module.h"
#include <ras/ras_event.h>
#include <linux/notifier.h>
+#include <linux/device/driver.h>
+#include <linux/platform_device.h>
#include <linux/string.h>

#define OTHER_DETAIL_LEN 400
@@ -57,7 +59,7 @@ static DEFINE_SPINLOCK(ghes_lock);

static bool system_scanned;

-static struct list_head *ghes_devs;
+static struct device *ghes_dev;

/* Memory Device - Type 17 of SMBIOS spec */
struct memdev_dmi_entry {
@@ -505,7 +507,7 @@ static int ghes_edac_register(struct device *dev)
return rc;
}

-static void ghes_edac_unregister(struct ghes *ghes)
+static void ghes_edac_unregister(void)
{
struct mem_ctl_info *mci;
unsigned long flags;
@@ -541,32 +543,34 @@ static void ghes_edac_unregister(struct ghes *ghes)

static int __init ghes_edac_init(void)
{
- struct ghes *g, *g_tmp;
+ struct device_driver *drv;
+ int ret;

- ghes_devs = ghes_get_devices();
- if (!ghes_devs)
+ if (!ghes_get_devices())
return -ENODEV;

- if (list_empty(ghes_devs)) {
- pr_info("GHES probing device list is empty\n");
+ /* GHES is built in, so the driver cannot be unloaded. */
+ drv = driver_find("GHES", &platform_bus_type);
+ if (!drv)
return -ENODEV;
- }

- list_for_each_entry_safe(g, g_tmp, ghes_devs, elist) {
- ghes_edac_register(g->dev);
- }
+ /* All GHES sources share one logical EDAC controller. */
+ ghes_dev = driver_find_next_device(drv, NULL);
+ if (!ghes_dev)
+ return -ENODEV;

- return 0;
+ ret = ghes_edac_register(ghes_dev);
+ if (ret)
+ put_device(ghes_dev);
+
+ return ret;
}
module_init(ghes_edac_init);

static void __exit ghes_edac_exit(void)
{
- struct ghes *g, *g_tmp;
-
- list_for_each_entry_safe(g, g_tmp, ghes_devs, elist) {
- ghes_edac_unregister(g);
- }
+ ghes_edac_unregister();
+ put_device(ghes_dev);
}
module_exit(ghes_edac_exit);


--
2.43.0