
From: Simon Glass <sjg@chromium.org> At present smbios_next_table() does not support SMBIOS v2 tables. Pass in the info struct so that it can check for the end of the tables. Signed-off-by: Simon Glass <sjg@chromium.org> --- cmd/smbios.c | 2 +- include/smbios.h | 4 +++- lib/smbios-parser.c | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/smbios.c b/cmd/smbios.c index 830cd513ad7..5d1d9eadb11 100644 --- a/cmd/smbios.c +++ b/cmd/smbios.c @@ -401,7 +401,7 @@ static int do_smbios(struct cmd_tbl *cmdtp, int flag, int argc, (unsigned long long)map_to_sysmem(info.table)); for (struct smbios_header *pos = info.table; pos; - pos = smbios_next_table(pos)) { + pos = smbios_next_table(&info, pos)) { printf("\nHandle 0x%04x, DMI type %d, %d bytes at 0x%llx\n", pos->handle, pos->type, pos->length, (unsigned long long)map_to_sysmem(pos)); diff --git a/include/smbios.h b/include/smbios.h index 98426a8b1d8..1e9f7ddceb9 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -413,10 +413,12 @@ const char *smbios_get_string(void *table, int index); /** * smbios_next_table() - Find the next table * + * @info: SMBIOS info * @table: Table to start from * Return: Pointer to the next table, or NULL if @table is the last */ -struct smbios_header *smbios_next_table(struct smbios_header *table); +struct smbios_header *smbios_next_table(const struct smbios_info *info, + struct smbios_header *table); /** * smbios_locate() - Locate the SMBIOS tables diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c index 24000ef0e1b..b05fc28d95f 100644 --- a/lib/smbios-parser.c +++ b/lib/smbios-parser.c @@ -32,10 +32,13 @@ const char *smbios_get_string(void *table, int index) return str; } -struct smbios_header *smbios_next_table(struct smbios_header *table) +struct smbios_header *smbios_next_table(const struct smbios_info *info, + struct smbios_header *table) { const char *str; + if ((ulong)table - (ulong)info->table >= info->max_size) + return NULL; if (table->type == SMBIOS_END_OF_TABLE) return NULL; @@ -317,7 +320,7 @@ int smbios_locate(ulong addr, struct smbios_info *info) info->count = 0; for (struct smbios_header *pos = info->table; pos; - pos = smbios_next_table(pos)) + pos = smbios_next_table(info, pos)) info->count++; return 0; -- 2.43.0