Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

efistub/smbios: Simplify SMBIOS enumeration API

Update the efi_get_smbios_string() macro to take a pointer to the entire
record struct rather than the header. This removes the need to pass the
type explicitly, as it can be inferred from the typed pointer. Also,
drop 'type' from the prototype of __efi_get_smbios_string(), as it is
never referenced.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

+7 -9
+1 -2
drivers/firmware/efi/libstub/arm64.c
··· 39 39 static char const emag[] = "eMAG"; 40 40 41 41 default: 42 - version = efi_get_smbios_string(&record->header, 4, 43 - processor_version); 42 + version = efi_get_smbios_string(record, processor_version); 44 43 if (!version || (strncmp(version, altra, sizeof(altra) - 1) && 45 44 strncmp(version, emag, sizeof(emag) - 1))) 46 45 break;
+4 -5
drivers/firmware/efi/libstub/efistub.h
··· 1204 1204 u16 thread_enabled; 1205 1205 }; 1206 1206 1207 - #define efi_get_smbios_string(__record, __type, __name) ({ \ 1208 - int off = offsetof(struct efi_smbios_type ## __type ## _record, \ 1209 - __name); \ 1210 - __efi_get_smbios_string((__record), __type, off); \ 1207 + #define efi_get_smbios_string(__record, __field) ({ \ 1208 + __typeof__(__record) __rec = __record; \ 1209 + __efi_get_smbios_string(&__rec->header, &__rec->__field); \ 1211 1210 }) 1212 1211 1213 1212 const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record, 1214 - u8 type, int offset); 1213 + const u8 *offset); 1215 1214 1216 1215 void efi_remap_image(unsigned long image_base, unsigned alloc_size, 1217 1216 unsigned long code_size);
+2 -2
drivers/firmware/efi/libstub/smbios.c
··· 38 38 } 39 39 40 40 const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record, 41 - u8 type, int offset) 41 + const u8 *offset) 42 42 { 43 43 const u8 *strtable; 44 44 ··· 46 46 return NULL; 47 47 48 48 strtable = (u8 *)record + record->length; 49 - for (int i = 1; i < ((u8 *)record)[offset]; i++) { 49 + for (int i = 1; i < *offset; i++) { 50 50 int len = strlen(strtable); 51 51 52 52 if (!len)