EDAC/ghes: Fix NULL pointer dereference in ghes_edac_register()
authorShiju Jose <shiju.jose@huawei.com>
Thu, 27 Aug 2020 14:04:50 +0000 (15:04 +0100)
committerBorislav Petkov <bp@suse.de>
Thu, 27 Aug 2020 16:04:07 +0000 (18:04 +0200)
commitb972fdba8665d75109ade0357739f46af6415d2a
treead189170d20c38c531ffbaa84f8a7c94b5fe2f70
parentd012a7190fc1fd72ed48911e77ca97ba4521bccd
EDAC/ghes: Fix NULL pointer dereference in ghes_edac_register()

After

  b9cae27728d1 ("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: b9cae27728d1 ("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
drivers/edac/ghes_edac.c