git: 07b84d1f3f14 - stable/14 - smbios: Unmap memory on error on identify
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 08 Apr 2025 13:40:51 UTC
The branch stable/14 has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=07b84d1f3f14782edf0817bb2a0793e4e08c2007
commit 07b84d1f3f14782edf0817bb2a0793e4e08c2007
Author: Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-02-28 17:19:37 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-04-08 13:38:23 +0000
smbios: Unmap memory on error on identify
While here, de-indent most of the code by simply bailing out if 'addr'
is still 0 after the various detection methods have been tried.
Reviewed by: emaste, imp
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49180
(cherry picked from commit 67d510f0c07afd89e51e337e5abec47f4483ecd9)
---
sys/dev/smbios/smbios.c | 82 ++++++++++++++++++++++++-------------------------
1 file changed, 41 insertions(+), 41 deletions(-)
diff --git a/sys/dev/smbios/smbios.c b/sys/dev/smbios/smbios.c
index e10ffa192e2b..cd9a0eefb9f9 100644
--- a/sys/dev/smbios/smbios.c
+++ b/sys/dev/smbios/smbios.c
@@ -114,53 +114,53 @@ smbios_identify (driver_t *driver, device_t parent)
}
#endif
- if (addr != 0) {
- ptr = pmap_mapbios(addr, map_size);
- if (ptr == NULL)
- return;
- if (map_size == sizeof(*eps3)) {
- eps3 = ptr;
- length = eps3->length;
- if (memcmp(eps3->anchor_string,
- SMBIOS3_SIG, SMBIOS3_LEN) != 0) {
- printf("smbios3: corrupt sig %s found\n",
- eps3->anchor_string);
- return;
- }
- } else {
- eps = ptr;
- length = eps->length;
- if (memcmp(eps->anchor_string,
- SMBIOS_SIG, SMBIOS_LEN) != 0) {
- printf("smbios: corrupt sig %s found\n",
- eps->anchor_string);
- return;
- }
+ if (addr == 0)
+ return;
+
+ ptr = pmap_mapbios(addr, map_size);
+ if (ptr == NULL)
+ return;
+ if (map_size == sizeof(*eps3)) {
+ eps3 = ptr;
+ length = eps3->length;
+ if (memcmp(eps3->anchor_string,
+ SMBIOS3_SIG, SMBIOS3_LEN) != 0) {
+ printf("smbios3: corrupt sig %s found\n",
+ eps3->anchor_string);
+ goto unmap_return;
}
- if (length != map_size) {
- u_int8_t major, minor;
-
- major = eps->major_version;
- minor = eps->minor_version;
-
- /* SMBIOS v2.1 implementation might use 0x1e. */
- if (length == 0x1e && major == 2 && minor == 1) {
- length = 0x1f;
- } else {
- pmap_unmapbios(eps, map_size);
- return;
- }
+ } else {
+ eps = ptr;
+ length = eps->length;
+ if (memcmp(eps->anchor_string,
+ SMBIOS_SIG, SMBIOS_LEN) != 0) {
+ printf("smbios: corrupt sig %s found\n",
+ eps->anchor_string);
+ goto unmap_return;
}
+ }
+ if (length != map_size) {
+ u_int8_t major, minor;
- child = BUS_ADD_CHILD(parent, 5, "smbios", -1);
- device_set_driver(child, driver);
+ major = eps->major_version;
+ minor = eps->minor_version;
- /* smuggle the phys addr into probe and attach */
- bus_set_resource(child, SYS_RES_MEMORY, 0, addr, length);
- device_set_desc(child, "System Management BIOS");
- pmap_unmapbios(ptr, map_size);
+ /* SMBIOS v2.1 implementation might use 0x1e. */
+ if (length == 0x1e && major == 2 && minor == 1)
+ length = 0x1f;
+ else
+ goto unmap_return;
}
+ child = BUS_ADD_CHILD(parent, 5, "smbios", -1);
+ device_set_driver(child, driver);
+
+ /* smuggle the phys addr into probe and attach */
+ bus_set_resource(child, SYS_RES_MEMORY, 0, addr, length);
+ device_set_desc(child, "System Management BIOS");
+
+unmap_return:
+ pmap_unmapbios(ptr, map_size);
return;
}