0030-efi-Return-grub_efi_status_t-from-grub_efi_get_varia.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. From 04ae030d0eea8668d4417702d88bf2cf04713d80 Mon Sep 17 00:00:00 2001
  2. From: Daniel Kiper <daniel.kiper@oracle.com>
  3. Date: Thu, 3 Dec 2020 16:01:46 +0100
  4. Subject: [PATCH] efi: Return grub_efi_status_t from grub_efi_get_variable()
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This is needed to properly detect and report UEFI Secure Boot status
  9. to the x86 Linux kernel. The functionality will be added by subsequent
  10. patches.
  11. Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
  12. Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
  13. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
  14. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  15. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  16. ---
  17. grub-core/commands/efi/efifwsetup.c | 8 ++++----
  18. grub-core/kern/efi/efi.c | 16 +++++++++-------
  19. grub-core/video/efi_gop.c | 2 +-
  20. include/grub/efi/efi.h | 7 ++++---
  21. 4 files changed, 18 insertions(+), 15 deletions(-)
  22. diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c
  23. index 7a137a72a..eaca03283 100644
  24. --- a/grub-core/commands/efi/efifwsetup.c
  25. +++ b/grub-core/commands/efi/efifwsetup.c
  26. @@ -38,8 +38,8 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
  27. grub_size_t oi_size;
  28. grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
  29. - old_os_indications = grub_efi_get_variable ("OsIndications", &global,
  30. - &oi_size);
  31. + grub_efi_get_variable ("OsIndications", &global, &oi_size,
  32. + (void **) &old_os_indications);
  33. if (old_os_indications != NULL && oi_size == sizeof (os_indications))
  34. os_indications |= *old_os_indications;
  35. @@ -63,8 +63,8 @@ efifwsetup_is_supported (void)
  36. grub_size_t oi_size = 0;
  37. grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
  38. - os_indications_supported = grub_efi_get_variable ("OsIndicationsSupported",
  39. - &global, &oi_size);
  40. + grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size,
  41. + (void **) &os_indications_supported);
  42. if (!os_indications_supported)
  43. return 0;
  44. diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
  45. index e0165e74c..9403b12cd 100644
  46. --- a/grub-core/kern/efi/efi.c
  47. +++ b/grub-core/kern/efi/efi.c
  48. @@ -223,9 +223,9 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
  49. return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var);
  50. }
  51. -void *
  52. +grub_efi_status_t
  53. grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
  54. - grub_size_t *datasize_out)
  55. + grub_size_t *datasize_out, void **data_out)
  56. {
  57. grub_efi_status_t status;
  58. grub_efi_uintn_t datasize = 0;
  59. @@ -234,13 +234,14 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
  60. void *data;
  61. grub_size_t len, len16;
  62. + *data_out = NULL;
  63. *datasize_out = 0;
  64. len = grub_strlen (var);
  65. len16 = len * GRUB_MAX_UTF16_PER_UTF8;
  66. var16 = grub_calloc (len16 + 1, sizeof (var16[0]));
  67. if (!var16)
  68. - return NULL;
  69. + return GRUB_EFI_OUT_OF_RESOURCES;
  70. len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);
  71. var16[len16] = 0;
  72. @@ -251,14 +252,14 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
  73. if (status != GRUB_EFI_BUFFER_TOO_SMALL || !datasize)
  74. {
  75. grub_free (var16);
  76. - return NULL;
  77. + return status;
  78. }
  79. data = grub_malloc (datasize);
  80. if (!data)
  81. {
  82. grub_free (var16);
  83. - return NULL;
  84. + return GRUB_EFI_OUT_OF_RESOURCES;
  85. }
  86. status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, data);
  87. @@ -266,12 +267,13 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
  88. if (status == GRUB_EFI_SUCCESS)
  89. {
  90. + *data_out = data;
  91. *datasize_out = datasize;
  92. - return data;
  93. + return status;
  94. }
  95. grub_free (data);
  96. - return NULL;
  97. + return status;
  98. }
  99. #pragma GCC diagnostic ignored "-Wcast-align"
  100. diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c
  101. index be446f8d2..7fe0cdabf 100644
  102. --- a/grub-core/video/efi_gop.c
  103. +++ b/grub-core/video/efi_gop.c
  104. @@ -316,7 +316,7 @@ grub_video_gop_get_edid (struct grub_video_edid_info *edid_info)
  105. char edidname[] = "agp-internal-edid";
  106. grub_size_t datasize;
  107. grub_uint8_t *data;
  108. - data = grub_efi_get_variable (edidname, &efi_var_guid, &datasize);
  109. + grub_efi_get_variable (edidname, &efi_var_guid, &datasize, (void **) &data);
  110. if (data && datasize > 16)
  111. {
  112. copy_size = datasize - 16;
  113. diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
  114. index e90e00dc4..8b2a0f1f5 100644
  115. --- a/include/grub/efi/efi.h
  116. +++ b/include/grub/efi/efi.h
  117. @@ -74,9 +74,10 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memo
  118. grub_efi_uintn_t descriptor_size,
  119. grub_efi_uint32_t descriptor_version,
  120. grub_efi_memory_descriptor_t *virtual_map);
  121. -void *EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
  122. - const grub_efi_guid_t *guid,
  123. - grub_size_t *datasize_out);
  124. +grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
  125. + const grub_efi_guid_t *guid,
  126. + grub_size_t *datasize_out,
  127. + void **data_out);
  128. grub_err_t
  129. EXPORT_FUNC (grub_efi_set_variable) (const char *var,
  130. const grub_efi_guid_t *guid,
  131. --
  132. 2.29.2