[06/12] x86: efi: Replace GFP_ATOMIC with GFP_KERNEL in efi_query_variable_store

Message ID 20180308080020.22828-7-ard.biesheuvel@linaro.org
State New
Headers show
Series
  • first batch of EFI changes for v4.17
Related show

Commit Message

Ard Biesheuvel March 8, 2018, 8 a.m.
From: Jia-Ju Bai <baijiaju1990@gmail.com>


The function kzalloc here is not called in atomic context.
If nonblocking in efi_query_variable_store is true,
namely it is in atomic context, efi_query_variable_store will return before
this kzalloc is called.
Thus GFP_ATOMIC is not necessary, and it can be replaced with GFP_KERNEL.

This is found by a static analysis tool named DCNS written by myself.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Reviewed-by: Ingo Molnar <mingo@kernel.org>

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 arch/x86/platform/efi/quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe linux-efi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Ingo Molnar March 9, 2018, 7:54 a.m. | #1
* Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:

> From: Jia-Ju Bai <baijiaju1990@gmail.com>

> 

> The function kzalloc here is not called in atomic context.

> If nonblocking in efi_query_variable_store is true,

> namely it is in atomic context, efi_query_variable_store will return before

> this kzalloc is called.

> Thus GFP_ATOMIC is not necessary, and it can be replaced with GFP_KERNEL.

> 

> This is found by a static analysis tool named DCNS written by myself.


Please fix typos/spelling in changelogs when applying patches.

I improved the above to:

  efi_query_variable_store() does an atomic kzalloc() unnecessarily,
  because we can never get this far when called in an atomic context,
  namely when nonblocking == 1.

  Replace it with GFP_KERNEL.

  This was found by the DCNS static analysis tool written by myself.

Thanks,

	Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-efi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 5b513ccffde4..1ef11c26f79b 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -177,7 +177,7 @@  efi_status_t efi_query_variable_store(u32 attributes, unsigned long size,
 		 * that by attempting to use more space than is available.
 		 */
 		unsigned long dummy_size = remaining_size + 1024;
-		void *dummy = kzalloc(dummy_size, GFP_ATOMIC);
+		void *dummy = kzalloc(dummy_size, GFP_KERNEL);
 
 		if (!dummy)
 			return EFI_OUT_OF_RESOURCES;