Skip to content

Commit 72d9b97

Browse files
praritrafaeljw
authored andcommitted
ACPI: extlog: fix NULL pointer dereference check
The gcc plugin -fanalyzer [1] tries to detect various patterns of incorrect behaviour. The tool reports: drivers/acpi/acpi_extlog.c: In function ‘extlog_exit’: drivers/acpi/acpi_extlog.c:307:12: warning: check of ‘extlog_l1_addr’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check] | | 306 | ((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN; | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ | | | | | (1) pointer ‘extlog_l1_addr’ is dereferenced here | 307 | if (extlog_l1_addr) | | ~ | | | | | (2) pointer ‘extlog_l1_addr’ is checked for NULL here but it was already dereferenced at (1) | Fix the NULL pointer dereference check in extlog_exit(). Link: https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html # [1] Signed-off-by: Prarit Bhargava <prarit@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 33cc938 commit 72d9b97

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/acpi/acpi_extlog.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,10 @@ static int __init extlog_init(void)
303303
static void __exit extlog_exit(void)
304304
{
305305
mce_unregister_decode_chain(&extlog_mce_dec);
306-
((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN;
307-
if (extlog_l1_addr)
306+
if (extlog_l1_addr) {
307+
((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN;
308308
acpi_os_unmap_iomem(extlog_l1_addr, l1_size);
309+
}
309310
if (elog_addr)
310311
acpi_os_unmap_iomem(elog_addr, elog_size);
311312
release_mem_region(elog_base, elog_size);

0 commit comments

Comments
 (0)