Skip to content

Commit b972fdb

Browse files
shijujose4suryasaimadhu
authored andcommitted
EDAC/ghes: Fix NULL pointer dereference in ghes_edac_register()
After b9cae27 ("EDAC/ghes: Scan the system once on driver init") and with CONFIG_DEBUG_TEST_DRIVER_REMOVE enabled, ghes_hw.dimms becomes a NULL pointer after the second ->probe() (aka ghes_edac_register()) which the config option causes to be called. This happens because the static variable which holds down whether the system has been scanned already, doesn't get reset in ghes_edac_unregister(). Then, on the second probe, ghes_scan_system() doesn't get to enumerate the DIMMs, leading to ghes_hw.dimms remaining NULL. Clear the variable and rename it to something more descriptive so that a second probe succeeds. [ bp: Rewrite commit message. ] Fixes: b9cae27 ("EDAC/ghes: Scan the system once on driver init") Suggested-by: Borislav Petkov <[email protected]> Signed-off-by: Shiju Jose <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent d012a71 commit b972fdb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/edac/ghes_edac.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static DEFINE_SPINLOCK(ghes_lock);
5555
static bool __read_mostly force_load;
5656
module_param(force_load, bool, 0);
5757

58+
static bool system_scanned;
59+
5860
/* Memory Device - Type 17 of SMBIOS spec */
5961
struct memdev_dmi_entry {
6062
u8 type;
@@ -225,14 +227,12 @@ static void enumerate_dimms(const struct dmi_header *dh, void *arg)
225227

226228
static void ghes_scan_system(void)
227229
{
228-
static bool scanned;
229-
230-
if (scanned)
230+
if (system_scanned)
231231
return;
232232

233233
dmi_walk(enumerate_dimms, &ghes_hw);
234234

235-
scanned = true;
235+
system_scanned = true;
236236
}
237237

238238
void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err)
@@ -631,6 +631,8 @@ void ghes_edac_unregister(struct ghes *ghes)
631631

632632
mutex_lock(&ghes_reg_mutex);
633633

634+
system_scanned = false;
635+
634636
if (!refcount_dec_and_test(&ghes_refcount))
635637
goto unlock;
636638

0 commit comments

Comments
 (0)