]> git.baikalelectronics.ru Git - kernel.git/commitdiff
efi: libstub: fix type confusion for load_options_size
authorArd Biesheuvel <ardb@kernel.org>
Wed, 14 Sep 2022 14:14:18 +0000 (16:14 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 20 Sep 2022 12:12:45 +0000 (14:12 +0200)
Even though it is unlikely to ever make a difference, let's use u32
consistently for the size of the load_options provided by the firmware
(aka the command line)

While at it, do some general cleanup too: use efi_char16_t, avoid using
options_chars in places where it really means options_size, etc.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/efi-stub-helper.c
drivers/firmware/efi/libstub/efistub.h
drivers/firmware/efi/libstub/file.c

index 3d972061c1b0d30b9d07b450daf51a4a4f32fb01..829f732c5f37e3862e63ccd89842916685d99201 100644 (file)
@@ -310,7 +310,7 @@ bool efi_load_option_unpack(efi_load_option_unpacked_t *dest,
  *
  * Detect this case and extract OptionalData.
  */
-void efi_apply_loadoptions_quirk(const void **load_options, int *load_options_size)
+void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_options_size)
 {
        const efi_load_option_t *load_option = *load_options;
        efi_load_option_unpacked_t load_option_unpacked;
@@ -341,21 +341,22 @@ void efi_apply_loadoptions_quirk(const void **load_options, int *load_options_si
  */
 char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len)
 {
-       const u16 *s2;
-       unsigned long cmdline_addr = 0;
-       int options_chars = efi_table_attr(image, load_options_size);
-       const u16 *options = efi_table_attr(image, load_options);
+       const efi_char16_t *options = efi_table_attr(image, load_options);
+       u32 options_size = efi_table_attr(image, load_options_size);
        int options_bytes = 0, safe_options_bytes = 0;  /* UTF-8 bytes */
+       unsigned long cmdline_addr = 0;
+       const efi_char16_t *s2;
        bool in_quote = false;
        efi_status_t status;
+       u32 options_chars;
 
-       efi_apply_loadoptions_quirk((const void **)&options, &options_chars);
-       options_chars /= sizeof(*options);
+       efi_apply_loadoptions_quirk((const void **)&options, &options_size);
+       options_chars = options_size / sizeof(efi_char16_t);
 
        if (options) {
                s2 = options;
                while (options_bytes < COMMAND_LINE_SIZE && options_chars--) {
-                       u16 c = *s2++;
+                       efi_char16_t c = *s2++;
 
                        if (c < 0x80) {
                                if (c == L'\0' || c == L'\n')
index 54f37e886be79280b63f03eda56fe4493bdb6937..02fb5f7c8effec0ee165d6f797ba57f8b2f36183 100644 (file)
@@ -861,7 +861,7 @@ typedef struct {
        u16 file_path_list_length;
        const efi_char16_t *description;
        const efi_device_path_protocol_t *file_path_list;
-       size_t optional_data_size;
+       u32 optional_data_size;
        const void *optional_data;
 } efi_load_option_unpacked_t;
 
@@ -906,7 +906,7 @@ __printf(1, 2) int efi_printk(char const *fmt, ...);
 
 void efi_free(unsigned long size, unsigned long addr);
 
-void efi_apply_loadoptions_quirk(const void **load_options, int *load_options_size);
+void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_options_size);
 
 char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len);
 
index f089ffa93ee35b156e277e406fcb70ebef61522c..bf133d39a543ce5130dca0e01432a2dda6f0ecb3 100644 (file)
@@ -154,7 +154,7 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
                                  unsigned long *load_size)
 {
        const efi_char16_t *cmdline = image->load_options;
-       int cmdline_len = image->load_options_size;
+       u32 cmdline_len = image->load_options_size;
        unsigned long efi_chunk_size = ULONG_MAX;
        efi_file_protocol_t *volume = NULL;
        efi_file_protocol_t *file;