From 311449a4e3321ee5e58bea6d1beb200b32d6b188 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Fri, 30 Jan 2015 19:19:03 +0000 Subject: [PATCH 1/7] msun: use previously ignored value. This fixes evaluation of exceptional values in scalblnl(). While here, simplify the code as suggested by Bruce Evans. Reported by: clang static analyzer MFC after: 1 week --- lib/msun/src/s_scalbln.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/lib/msun/src/s_scalbln.c b/lib/msun/src/s_scalbln.c index d609d4e8b3d4..2aa69003bed4 100644 --- a/lib/msun/src/s_scalbln.c +++ b/lib/msun/src/s_scalbln.c @@ -35,13 +35,7 @@ scalbln (double x, long n) { int in; - in = (int)n; - if (in != n) { - if (n > 0) - in = INT_MAX; - else - in = INT_MIN; - } + in = (n > INT_MAX) ? INT_MAX : (n < INT_MIN) ? INT_MIN : n; return (scalbn(x, in)); } @@ -50,13 +44,7 @@ scalblnf (float x, long n) { int in; - in = (int)n; - if (in != n) { - if (n > 0) - in = INT_MAX; - else - in = INT_MIN; - } + in = (n > INT_MAX) ? INT_MAX : (n < INT_MIN) ? INT_MIN : n; return (scalbnf(x, in)); } @@ -65,12 +53,6 @@ scalblnl (long double x, long n) { int in; - in = (int)n; - if (in != n) { - if (n > 0) - in = INT_MAX; - else - in = INT_MIN; - } - return (scalbnl(x, (int)n)); + in = (n > INT_MAX) ? INT_MAX : (n < INT_MIN) ? INT_MIN : n; + return (scalbnl(x, in)); } From 26066a530faea63c452b624cc448682b720f9055 Mon Sep 17 00:00:00 2001 From: Michael Gmelin Date: Fri, 30 Jan 2015 19:47:25 +0000 Subject: [PATCH 2/7] New function smbios_match to detect BIOS versions during boot Motivation is to introduce BIOS specific quirks early in the boot process. smbios_match can be called before malloc is avaible, that's why parts of smbios_detect have been moved into a separate function smbios_probe that will be called by smbios_detect as well as smbios_match. Reviewed by: jhb Approved by: jhb Differential Revision: https://reviews.freebsd.org/D1679 --- sys/boot/i386/libi386/libi386.h | 2 + sys/boot/i386/libi386/smbios.c | 185 +++++++++++++++++++++++--------- 2 files changed, 139 insertions(+), 48 deletions(-) diff --git a/sys/boot/i386/libi386/libi386.h b/sys/boot/i386/libi386/libi386.h index c68c1b6754f6..2322c2b303c1 100644 --- a/sys/boot/i386/libi386/libi386.h +++ b/sys/boot/i386/libi386/libi386.h @@ -114,6 +114,8 @@ uint32_t biospci_locator(int8_t bus, uint8_t device, uint8_t function); void biosacpi_detect(void); void smbios_detect(void); +int smbios_match(const char* bios_vendor, const char* maker, + const char* product); int i386_autoload(void); diff --git a/sys/boot/i386/libi386/smbios.c b/sys/boot/i386/libi386/smbios.c index 08abe1a8239f..0d5eb7b04ec0 100644 --- a/sys/boot/i386/libi386/smbios.c +++ b/sys/boot/i386/libi386/smbios.c @@ -64,10 +64,24 @@ __FBSDID("$FreeBSD$"); #define SMBIOS_GETLEN(base) SMBIOS_GET8(base, 0x01) #define SMBIOS_GETSTR(base) ((base) + SMBIOS_GETLEN(base)) -static uint32_t smbios_enabled_memory = 0; -static uint32_t smbios_old_enabled_memory = 0; -static uint8_t smbios_enabled_sockets = 0; -static uint8_t smbios_populated_sockets = 0; +struct smbios_attr { + int probed; + caddr_t addr; + size_t length; + size_t count; + int major; + int minor; + int ver; + const char* bios_vendor; + const char* maker; + const char* product; + uint32_t enabled_memory; + uint32_t old_enabled_memory; + uint8_t enabled_sockets; + uint8_t populated_sockets; +}; + +static struct smbios_attr smbios; static uint8_t smbios_checksum(const caddr_t addr, const uint8_t len) @@ -95,8 +109,8 @@ smbios_sigsearch(const caddr_t addr, const uint32_t len) return (NULL); } -static void -smbios_setenv(const char *name, caddr_t addr, const int offset) +static const char* +smbios_getstring(caddr_t addr, const int offset) { caddr_t cp; int i, idx; @@ -106,8 +120,19 @@ smbios_setenv(const char *name, caddr_t addr, const int offset) cp = SMBIOS_GETSTR(addr); for (i = 1; i < idx; i++) cp += strlen(cp) + 1; - setenv(name, cp, 1); + return cp; } + return (NULL); +} + +static void +smbios_setenv(const char *name, caddr_t addr, const int offset) +{ + const char* val; + + val = smbios_getstring(addr, offset); + if (val != NULL) + setenv(name, val, 1); } #ifdef SMBIOS_SERIAL_NUMBERS @@ -187,7 +212,7 @@ smbios_setuuid(const char *name, const caddr_t addr, const int ver) #endif static caddr_t -smbios_parse_table(const caddr_t addr, const int ver) +smbios_parse_table(const caddr_t addr) { caddr_t cp; int proc, size, osize, type; @@ -206,7 +231,7 @@ smbios_parse_table(const caddr_t addr, const int ver) smbios_setenv("smbios.system.version", addr, 0x06); #ifdef SMBIOS_SERIAL_NUMBERS smbios_setenv("smbios.system.serial", addr, 0x07); - smbios_setuuid("smbios.system.uuid", addr + 0x08, ver); + smbios_setuuid("smbios.system.uuid", addr + 0x08, smbios.ver); #endif break; @@ -248,9 +273,9 @@ smbios_parse_table(const caddr_t addr, const int ver) */ proc = SMBIOS_GET8(addr, 0x18); if ((proc & 0x07) == 1) - smbios_enabled_sockets++; + smbios.enabled_sockets++; if ((proc & 0x40) != 0) - smbios_populated_sockets++; + smbios.populated_sockets++; break; case 6: /* 3.3.7 Memory Module Information (Type 6, Obsolete) */ @@ -268,7 +293,7 @@ smbios_parse_table(const caddr_t addr, const int ver) */ osize = SMBIOS_GET8(addr, 0x0a) & 0x7f; if (osize > 0 && osize < 22) - smbios_old_enabled_memory += 1 << (osize + 10); + smbios.old_enabled_memory += 1 << (osize + 10); break; case 17: /* 3.3.18 Memory Device (Type 17) */ @@ -282,7 +307,7 @@ smbios_parse_table(const caddr_t addr, const int ver) */ size = SMBIOS_GET16(addr, 0x0c); if (size != 0 && size != 0xffff) - smbios_enabled_memory += (size & 0x8000) != 0 ? + smbios.enabled_memory += (size & 0x8000) != 0 ? (size & 0x7fff) : (size << 10); break; @@ -298,54 +323,118 @@ smbios_parse_table(const caddr_t addr, const int ver) return (cp + 2); } +static void +smbios_probe(void) +{ + caddr_t saddr, info; + u_int32_t paddr; + + if (smbios.probed) + return; + smbios.probed = 1; + + /* Search signatures and validate checksums. */ + saddr = smbios_sigsearch(PTOV(SMBIOS_START), SMBIOS_LENGTH); + if (saddr == NULL) + return; + + smbios.length = SMBIOS_GET16(saddr, 0x16); /* Structure Table Length */ + paddr = SMBIOS_GET32(saddr, 0x18); /* Structure Table Address */ + smbios.count = SMBIOS_GET16(saddr, 0x1c); /* No of SMBIOS Structures */ + smbios.ver = SMBIOS_GET8(saddr, 0x1e); /* SMBIOS BCD Revision */ + + if (smbios.ver != 0) { + smbios.major = smbios.ver >> 4; + smbios.minor = smbios.ver & 0x0f; + if (smbios.major > 9 || smbios.minor > 9) + smbios.ver = 0; + } + if (smbios.ver == 0) { + smbios.major = SMBIOS_GET8(saddr, 0x06);/* SMBIOS Major Version */ + smbios.minor = SMBIOS_GET8(saddr, 0x07);/* SMBIOS Minor Version */ + } + smbios.ver = (smbios.major << 8) | smbios.minor; + smbios.addr = PTOV(paddr); + + /* Get system information from SMBIOS */ + info = smbios_find_struct(0x00); + if (info != NULL) { + smbios.bios_vendor = smbios_getstring(info, 0x04); + } + info = smbios_find_struct(0x01); + if (info != NULL) { + smbios.maker = smbios_getstring(info, 0x04); + smbios.product = smbios_getstring(info, 0x05); + } +} + +static caddr_t +smbios_find_struct(int type) +{ + caddr_t dmi; + int i; + + if (smbios.addr == NULL) + return (NULL); + + for (dmi = smbios.addr, i = 0; + dmi < smbios.addr + smbios.length && i < smbios.count; i++) { + if (SMBIOS_GET8(dmi, 0) == type) + return dmi; + /* Find structure terminator. */ + dmi = SMBIOS_GETSTR(dmi); + while (SMBIOS_GET16(dmi, 0) != 0) + dmi++; + dmi += 2; + } + + return (NULL); +} + void smbios_detect(void) { char buf[16]; - caddr_t addr, dmi, smbios; - size_t count, length; - uint32_t paddr; - int i, major, minor, ver; + caddr_t dmi; + int i; - /* Search signatures and validate checksums. */ - smbios = smbios_sigsearch(PTOV(SMBIOS_START), SMBIOS_LENGTH); - if (smbios == NULL) + smbios_probe(); + if (smbios.addr == NULL) return; - length = SMBIOS_GET16(smbios, 0x16); /* Structure Table Length */ - paddr = SMBIOS_GET32(smbios, 0x18); /* Structure Table Address */ - count = SMBIOS_GET16(smbios, 0x1c); /* No of SMBIOS Structures */ - ver = SMBIOS_GET8(smbios, 0x1e); /* SMBIOS BCD Revision */ + for (dmi = smbios.addr, i = 0; + dmi < smbios.addr + smbios.length && i < smbios.count; i++) + dmi = smbios_parse_table(dmi); - if (ver != 0) { - major = ver >> 4; - minor = ver & 0x0f; - if (major > 9 || minor > 9) - ver = 0; - } - if (ver == 0) { - major = SMBIOS_GET8(smbios, 0x06); /* SMBIOS Major Version */ - minor = SMBIOS_GET8(smbios, 0x07); /* SMBIOS Minor Version */ - } - ver = (major << 8) | minor; - - addr = PTOV(paddr); - for (dmi = addr, i = 0; dmi < addr + length && i < count; i++) - dmi = smbios_parse_table(dmi, ver); - - sprintf(buf, "%d.%d", major, minor); + sprintf(buf, "%d.%d", smbios.major, smbios.minor); setenv("smbios.version", buf, 1); - if (smbios_enabled_memory > 0 || smbios_old_enabled_memory > 0) { - sprintf(buf, "%u", smbios_enabled_memory > 0 ? - smbios_enabled_memory : smbios_old_enabled_memory); + if (smbios.enabled_memory > 0 || smbios.old_enabled_memory > 0) { + sprintf(buf, "%u", smbios.enabled_memory > 0 ? + smbios.enabled_memory : smbios.old_enabled_memory); setenv("smbios.memory.enabled", buf, 1); } - if (smbios_enabled_sockets > 0) { - sprintf(buf, "%u", smbios_enabled_sockets); + if (smbios.enabled_sockets > 0) { + sprintf(buf, "%u", smbios.enabled_sockets); setenv("smbios.socket.enabled", buf, 1); } - if (smbios_populated_sockets > 0) { - sprintf(buf, "%u", smbios_populated_sockets); + if (smbios.populated_sockets > 0) { + sprintf(buf, "%u", smbios.populated_sockets); setenv("smbios.socket.populated", buf, 1); } } + +static int +smbios_match_str(const char* s1, const char* s2) +{ + return (s1 == NULL || (s2 != NULL && !strcmp(s1, s2))); +} + +int +smbios_match(const char* bios_vendor, const char* maker, + const char* product) +{ + smbios_probe(); + return (smbios_match_str(bios_vendor, smbios.bios_vendor) && + smbios_match_str(maker, smbios.maker) && + smbios_match_str(product, smbios.product)); +} From 04e98a37244601eb3a81e14ac10757eedba7f238 Mon Sep 17 00:00:00 2001 From: Nathan Whitehorn Date: Fri, 30 Jan 2015 21:22:18 +0000 Subject: [PATCH 3/7] Use MBR by default on BIOS systems. An increasing number of motherboards assume that GPT means UEFI boot, resulting in the installation of uninstallable systems. This needs a little more work before MFC, in particular based on disk size (> 2 TB + BIOS + MBR is not workable). That will come soon. --- usr.sbin/bsdinstall/partedit/partedit_x86.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bsdinstall/partedit/partedit_x86.c b/usr.sbin/bsdinstall/partedit/partedit_x86.c index cc6a5713f945..6a606784ae20 100644 --- a/usr.sbin/bsdinstall/partedit/partedit_x86.c +++ b/usr.sbin/bsdinstall/partedit/partedit_x86.c @@ -51,7 +51,10 @@ x86_bootmethod(void) const char * default_scheme(void) { - return ("GPT"); + if (strcmp(x86_bootmethod(), "UEFI") == 0) + return ("GPT"); + else + return ("MBR"); } int From 1bb25a82ab860aa71821b3f3e78661525637eec0 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 30 Jan 2015 21:59:53 +0000 Subject: [PATCH 4/7] Fix a bunch of -Wcast-qual warnings in netgraph's ng_parse.c, by using __DECONST. No functional change. MFC after: 3 days --- sys/netgraph/ng_parse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c index 10398bcda428..b08cecd102e9 100644 --- a/sys/netgraph/ng_parse.c +++ b/sys/netgraph/ng_parse.c @@ -1122,7 +1122,7 @@ ng_bytearray_parse(const struct ng_parse_type *type, struct ng_parse_type subtype; subtype = ng_parse_bytearray_subtype; - *(const void **)&subtype.private = type->info; + subtype.private = __DECONST(void *, type->info); return ng_array_parse(&subtype, s, off, start, buf, buflen); } } @@ -1134,7 +1134,7 @@ ng_bytearray_unparse(const struct ng_parse_type *type, struct ng_parse_type subtype; subtype = ng_parse_bytearray_subtype; - *(const void **)&subtype.private = type->info; + subtype.private = __DECONST(void *, type->info); return ng_array_unparse(&subtype, data, off, cbuf, cbuflen); } @@ -1145,7 +1145,7 @@ ng_bytearray_getDefault(const struct ng_parse_type *type, struct ng_parse_type subtype; subtype = ng_parse_bytearray_subtype; - *(const void **)&subtype.private = type->info; + subtype.private = __DECONST(void *, type->info); return ng_array_getDefault(&subtype, start, buf, buflen); } From 38fc0aa4840b8bf7ef883ade274cd4d9daf9dd22 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 30 Jan 2015 22:01:45 +0000 Subject: [PATCH 5/7] Fix a -Wcast-qual warning in udf_vnops.c, by using __DECONST. No functional change. MFC after: 3 days --- sys/fs/udf/udf_vnops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/fs/udf/udf_vnops.c b/sys/fs/udf/udf_vnops.c index abe073e8e36a..8e0d25e18adb 100644 --- a/sys/fs/udf/udf_vnops.c +++ b/sys/fs/udf/udf_vnops.c @@ -526,8 +526,9 @@ udf_transname(char *cs0string, char *destname, int len, struct udf_mnt *udfmp) } while (unilen > 0 && destleft > 0) { - udf_iconv->conv(udfmp->im_d2l, (const char **)&unibuf, - (size_t *)&unilen, (char **)&destname, &destleft); + udf_iconv->conv(udfmp->im_d2l, __DECONST(const char **, + &unibuf), (size_t *)&unilen, (char **)&destname, + &destleft); /* Unconverted character found */ if (unilen > 0 && destleft > 0) { *destname++ = '?'; From 7f4daa88f1b4be5a06ec08b1380ec1742f3555f9 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 30 Jan 2015 22:02:32 +0000 Subject: [PATCH 6/7] Fix a -Wcast-qual warning in smbfs_subr.c, by using __DECONST. No functional change. MFC after: 3 days --- sys/fs/smbfs/smbfs_subr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/fs/smbfs/smbfs_subr.c b/sys/fs/smbfs/smbfs_subr.c index aa03101f905e..4e9f77da4497 100644 --- a/sys/fs/smbfs/smbfs_subr.c +++ b/sys/fs/smbfs/smbfs_subr.c @@ -170,8 +170,8 @@ smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int *nmlen, int caseopt) if (error) return error; */ - error = iconv_conv_case - (vcp->vc_tolocal, (const char **)&ibuf, &ilen, &obuf, &olen, copt); + error = iconv_conv_case(vcp->vc_tolocal, + __DECONST(const char **, &ibuf), &ilen, &obuf, &olen, copt); if (error && SMB_UNICODE_STRINGS(vcp)) { /* * If using unicode, leaving a file name as it was when From 803deb9a21c4e31165e444950444bf13d9111208 Mon Sep 17 00:00:00 2001 From: Colin Percival Date: Fri, 30 Jan 2015 23:26:03 +0000 Subject: [PATCH 7/7] Fix 7-year-old typo: The default directory searched for fortunes is /usr/share/games/fortune, not /usr/games/fortune (which is the path to the fortune binary itself). --- games/fortune/fortune/fortune.6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/games/fortune/fortune/fortune.6 b/games/fortune/fortune/fortune.6 index 7272fd0d87d1..d8f6bad177d0 100644 --- a/games/fortune/fortune/fortune.6 +++ b/games/fortune/fortune/fortune.6 @@ -168,7 +168,7 @@ It is a colon-separated list of directories in which .Nm looks for data files. If not set it will default to -.Pa /usr/games/fortune . +.Pa /usr/share/games/fortune . If none of the directories specified exist, it will print a warning and exit. .It Ev FORTUNE_SAVESTATE If set, fortune will save some state about what fortune