Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 0dad9ee

Browse files
committed
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>
1 parent 37aee82 commit 0dad9ee

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

drivers/firmware/efi/libstub/arm64.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ static bool system_needs_vamap(void)
3939
static char const emag[] = "eMAG";
4040

4141
default:
42-
version = efi_get_smbios_string(&record->header, 4,
43-
processor_version);
42+
version = efi_get_smbios_string(record, processor_version);
4443
if (!version || (strncmp(version, altra, sizeof(altra) - 1) &&
4544
strncmp(version, emag, sizeof(emag) - 1)))
4645
break;

drivers/firmware/efi/libstub/efistub.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,14 +1204,13 @@ struct efi_smbios_type4_record {
12041204
u16 thread_enabled;
12051205
};
12061206

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); \
12111210
})
12121211

12131212
const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,
1214-
u8 type, int offset);
1213+
const u8 *offset);
12151214

12161215
void efi_remap_image(unsigned long image_base, unsigned alloc_size,
12171216
unsigned long code_size);

drivers/firmware/efi/libstub/smbios.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ const struct efi_smbios_record *efi_get_smbios_record(u8 type)
3838
}
3939

4040
const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,
41-
u8 type, int offset)
41+
const u8 *offset)
4242
{
4343
const u8 *strtable;
4444

4545
if (!record)
4646
return NULL;
4747

4848
strtable = (u8 *)record + record->length;
49-
for (int i = 1; i < ((u8 *)record)[offset]; i++) {
49+
for (int i = 1; i < *offset; i++) {
5050
int len = strlen(strtable);
5151

5252
if (!len)

0 commit comments

Comments
 (0)