]> git.baikalelectronics.ru Git - kernel.git/commitdiff
efi: fix NULL-deref in init error path
authorJohan Hovold <johan+linaro@kernel.org>
Mon, 19 Dec 2022 09:10:04 +0000 (10:10 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:42:06 +0000 (11:42 +0100)
[ Upstream commit 703c13fe3c9af557d312f5895ed6a5fda2711104 ]

In cases where runtime services are not supported or have been disabled,
the runtime services workqueue will never have been allocated.

Do not try to destroy the workqueue unconditionally in the unlikely
event that EFI initialisation fails to avoid dereferencing a NULL
pointer.

Fixes: 65d87c07ba85 ("efi: add missed destroy_workqueue when efisubsys_init fails")
Cc: stable@vger.kernel.org
Cc: Li Heng <liheng40@huawei.com>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/firmware/efi/efi.c

index ac9fb336c80ffab6b9b0b91d803f4bf24f3482b6..eb98018ab420e3a0683d5ff5dfd7ca5ff5929487 100644 (file)
@@ -345,8 +345,8 @@ static int __init efisubsys_init(void)
        efi_kobj = kobject_create_and_add("efi", firmware_kobj);
        if (!efi_kobj) {
                pr_err("efi: Firmware registration failed.\n");
-               destroy_workqueue(efi_rts_wq);
-               return -ENOMEM;
+               error = -ENOMEM;
+               goto err_destroy_wq;
        }
 
        error = generic_ops_register();
@@ -382,7 +382,10 @@ err_unregister:
        generic_ops_unregister();
 err_put:
        kobject_put(efi_kobj);
-       destroy_workqueue(efi_rts_wq);
+err_destroy_wq:
+       if (efi_rts_wq)
+               destroy_workqueue(efi_rts_wq);
+
        return error;
 }