Skip to content

Commit

Permalink
EDAC/ghes: Fix NULL pointer dereference in ghes_edac_register()
Browse files Browse the repository at this point in the history
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 <bp@suse.de>
Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200827140450.1620-1-shiju.jose@huawei.com
  • Loading branch information
shijujose4 authored and suryasaimadhu committed Aug 27, 2020
1 parent d012a71 commit b972fdb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/edac/ghes_edac.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static DEFINE_SPINLOCK(ghes_lock);
static bool __read_mostly force_load;
module_param(force_load, bool, 0);

static bool system_scanned;

/* Memory Device - Type 17 of SMBIOS spec */
struct memdev_dmi_entry {
u8 type;
Expand Down Expand Up @@ -225,14 +227,12 @@ static void enumerate_dimms(const struct dmi_header *dh, void *arg)

static void ghes_scan_system(void)
{
static bool scanned;

if (scanned)
if (system_scanned)
return;

dmi_walk(enumerate_dimms, &ghes_hw);

scanned = true;
system_scanned = true;
}

void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err)
Expand Down Expand Up @@ -631,6 +631,8 @@ void ghes_edac_unregister(struct ghes *ghes)

mutex_lock(&ghes_reg_mutex);

system_scanned = false;

if (!refcount_dec_and_test(&ghes_refcount))
goto unlock;

Expand Down

0 comments on commit b972fdb

Please sign in to comment.