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

dmi_scan: add comments on dmi_present() and the loop in dmi_scan_machine()

My previous refactoring in commit 79bae42d51a5 ("dmi_scan: refactor
dmi_scan_machine(), {smbios,dmi}_present()") resulted in slightly tricky
code (though I think it's more elegant). Explain what it's doing.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Cc: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ben Hutchings and committed by
Linus Torvalds
d39de28c 62c61046

+14
+14
drivers/firmware/dmi_scan.c
··· 419 419 dmi_get_system_info(DMI_BIOS_DATE)); 420 420 } 421 421 422 + /* 423 + * Check for DMI/SMBIOS headers in the system firmware image. Any 424 + * SMBIOS header must start 16 bytes before the DMI header, so take a 425 + * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset 426 + * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS 427 + * takes precedence) and return 0. Otherwise return 1. 428 + */ 422 429 static int __init dmi_present(const u8 *buf) 423 430 { 424 431 int smbios_ver; ··· 513 506 if (p == NULL) 514 507 goto error; 515 508 509 + /* 510 + * Iterate over all possible DMI header addresses q. 511 + * Maintain the 32 bytes around q in buf. On the 512 + * first iteration, substitute zero for the 513 + * out-of-range bytes so there is no chance of falsely 514 + * detecting an SMBIOS header. 515 + */ 516 516 memset(buf, 0, 16); 517 517 for (q = p; q < p + 0x10000; q += 16) { 518 518 memcpy_fromio(buf + 16, q, 16);