efi/runtime-wrapper: Move workqueue manipulation out of line
authorArd Biesheuvel <ardb@kernel.org>
Sun, 2 Jul 2023 13:57:13 +0000 (15:57 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Mon, 21 Aug 2023 15:59:54 +0000 (17:59 +0200)
efi_queue_work() is a macro that implements the non-trivial manipulation
of the EFI runtime workqueue and completion data structure, most of
which is generic, and could be shared between all the users of the
macro. So move it out of the macro and into a new helper function.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/runtime-wrappers.c

index 66066e058757c1b515b18f9095ac163d788be723..ee5c9a3e506043982292d8ae6dea16b5802f577f 100644 (file)
@@ -125,34 +125,8 @@ struct efi_runtime_work efi_rts_work;
  * thread waits for completion.
  */
 #define efi_queue_work(_rts, _args...)                                 \
-({                                                                     \
-       efi_rts_work.efi_rts_id = EFI_ ## _rts;                         \
-       efi_rts_work.args = &(union efi_rts_args){ ._rts = { _args }};  \
-       efi_rts_work.status = EFI_ABORTED;                              \
-                                                                       \
-       if (!efi_enabled(EFI_RUNTIME_SERVICES)) {                       \
-               pr_warn_once("EFI Runtime Services are disabled!\n");   \
-               efi_rts_work.status = EFI_DEVICE_ERROR;                 \
-               goto exit;                                              \
-       }                                                               \
-                                                                       \
-       init_completion(&efi_rts_work.efi_rts_comp);                    \
-       INIT_WORK(&efi_rts_work.work, efi_call_rts);                    \
-                                                                       \
-       /*                                                              \
-        * queue_work() returns 0 if work was already on queue,         \
-        * _ideally_ this should never happen.                          \
-        */                                                             \
-       if (queue_work(efi_rts_wq, &efi_rts_work.work))                 \
-               wait_for_completion(&efi_rts_work.efi_rts_comp);        \
-       else                                                            \
-               pr_err("Failed to queue work to efi_rts_wq.\n");        \
-                                                                       \
-       WARN_ON_ONCE(efi_rts_work.status == EFI_ABORTED);               \
-exit:                                                                  \
-       efi_rts_work.efi_rts_id = EFI_NONE;                             \
-       efi_rts_work.status;                                            \
-})
+       __efi_queue_work(EFI_ ## _rts,                                  \
+                        &(union efi_rts_args){ ._rts = { _args }})
 
 #ifndef arch_efi_save_flags
 #define arch_efi_save_flags(state_flags)       local_save_flags(state_flags)
@@ -319,6 +293,37 @@ static void efi_call_rts(struct work_struct *work)
        complete(&efi_rts_work.efi_rts_comp);
 }
 
+static efi_status_t __efi_queue_work(enum efi_rts_ids id,
+                                    union efi_rts_args *args)
+{
+       efi_rts_work.efi_rts_id = id;
+       efi_rts_work.args = args;
+       efi_rts_work.status = EFI_ABORTED;
+
+       if (!efi_enabled(EFI_RUNTIME_SERVICES)) {
+               pr_warn_once("EFI Runtime Services are disabled!\n");
+               efi_rts_work.status = EFI_DEVICE_ERROR;
+               goto exit;
+       }
+
+       init_completion(&efi_rts_work.efi_rts_comp);
+       INIT_WORK(&efi_rts_work.work, efi_call_rts);
+
+       /*
+        * queue_work() returns 0 if work was already on queue,
+        * _ideally_ this should never happen.
+        */
+       if (queue_work(efi_rts_wq, &efi_rts_work.work))
+               wait_for_completion(&efi_rts_work.efi_rts_comp);
+       else
+               pr_err("Failed to queue work to efi_rts_wq.\n");
+
+       WARN_ON_ONCE(efi_rts_work.status == EFI_ABORTED);
+exit:
+       efi_rts_work.efi_rts_id = EFI_NONE;
+       return efi_rts_work.status;
+}
+
 static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
 {
        efi_status_t status;