DMI: fix dmi_get_year year parsing
Subsystems (2)
PATCH 1/1 DMI: fix dmi_get_year year parsing
Don't guess a year number base. Use 10 instead, since year may be 2-digit starting with 0, so that we would end up in base equal to 8.
--- drivers/firmware/dmi_scan.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/firmware/dmi_scan.c +1 -1
@@ -611,7 +611,7 @@ int dmi_get_year(int field)return 0 ; s +=1 ; - year =simple_strtoul (s,NULL ,0 ); + year =simple_strtoul (s,NULL ,10 );if (year && year <100 ) {/* 2-digit year */ year +=1900 ;if (year <1996 )/* no dates < spec 1.0 */
Signature · 1 line
1.6.3.2
Quoted 15 lines · Jiri Slaby
Don't guess a year number base. Use 10 instead, since year may be 2-digit starting with 0, so that we would end up in base equal to 8.
Signed-off-by Jiri Slaby <[email protected]>Reported-by Matthias Pfaller <[email protected]>--- drivers/firmware/dmi_scan.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/firmware/dmi_scan.c +0
-0
drivers/firmware/dmi_scan.c int dmi_get_year(int field) · line 617
Quoted 8 lines
drivers/firmware/dmi_scan.c +1
-1@@ -611,7 +611,7 @@ int dmi_get_year(int field)return 0 ; s +=1 ; - year =simple_strtoul (s,NULL ,0 ); + year =simple_strtoul (s,NULL ,10 );if (year && year <100 ) {/* 2-digit year */ year +=1900 ;if (year <1996 )/* no dates < spec 1.0 */
I just noticed, that this is not enough, because this will still fail for xxx/xx/00. I suggest the following patch:
firmware/dmi_scan.c Wed Jul 8 02:42:17 2009 renamed from firmware/dmi_scan.c.bak Wed Jul 8 02:42:04 2009 +9 -6
@@ -360,12 +360,15 @@ return 0; s += 1; - year = simple_strtoul(s, NULL, 0); - if (year && year < 100) { /* 2-digit year */ - year += 1900; - if (year < 1996) /* no dates < spec 1.0 */ - year += 100; + if (s[0] == '0' && s[1] == '0' && s[2] == '\0') { + year = 2000; + } else { + year = simple_strtoul(s, NULL, 10); + if (year && year < 100) { /* 2-digit year */ + year += 1900; + if (year < 1996) /* no dates < spec 1.0 */ + year += 100; + } } - return year; }
Signature · 5 lines
Matthias Pfaller Software Entwicklung marco Systemanalyse und Entwicklung GmbH Tel +49 8131 5161 41 Hans-Böckler-Str. 2, D 85221 Dachau Fax +49 8131 5161 66 http://www.marco.de/ Email [email protected] Geschäftsführer Martin Reuter HRB 171775 Amtsgericht München
Quoted 18 lines · Matthias Pfaller
Quoted 17 lines · Jiri Slaby
Don't guess a year number base. Use 10 instead, since year may be 2-digit starting with 0, so that we would end up in base equal to 8.
Signed-off-by Jiri Slaby <[email protected]>Reported-by Matthias Pfaller <[email protected]>--- drivers/firmware/dmi_scan.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/firmware/dmi_scan.c +0
-0@@ -611,7 +611,7 @@ int dmi_get_year(int field)return 0 ;
Quoted 9 lines
drivers/firmware/dmi_scan.c int dmi_get_year(int field) · line 617
Quoted 6 lines
drivers/firmware/dmi_scan.c +1
-1s +=1 ; - year =simple_strtoul (s,NULL ,0 ); + year =simple_strtoul (s,NULL ,10 );if (year && year <100 ) {/* 2-digit year */ year +=1900 ;if (year <1996 )/* no dates < spec 1.0 */ I just noticed, that this is not enough, because this will still fail for xxx/xx/00. I suggest the following patch:
Actually the patch below is not correct. Standard says consider xx/xx/yy as 19yy, not 20yy.
BTW. the patch above is not useful, reporting 1908 and 1909 as a year is almost the same as 1900.
Do you have such a broken BIOS?
Quoted 25 lines
firmware/dmi_scan.c Wed Jul 8 02:42:17 2009 renamed from firmware/dmi_scan.c.bak Wed Jul 8 02:42:04 2009 +9
-6@@ -360,12 +360,15 @@ return 0; s += 1; - year = simple_strtoul(s, NULL, 0); - if (year && year < 100) { /* 2-digit year */ - year += 1900; - if (year < 1996) /* no dates < spec 1.0 */ - year += 100; + if (s[0] == '0' && s[1] == '0' && s[2] == '\0') { + year = 2000; + } else { + year = simple_strtoul(s, NULL, 10); + if (year && year < 100) { /* 2-digit year */ + year += 1900; + if (year < 1996) /* no dates < spec 1.0 */ + year += 100; + } } - return year; }
Quoted 28 lines · Jiri Slaby
Quoted 18 lines · Matthias Pfaller
Quoted 17 lines · Jiri Slaby
Don't guess a year number base. Use 10 instead, since year may be 2-digit starting with 0, so that we would end up in base equal to 8.
Signed-off-by Jiri Slaby <[email protected]>Reported-by Matthias Pfaller <[email protected]>--- drivers/firmware/dmi_scan.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/firmware/dmi_scan.c +0
-0@@ -611,7 +611,7 @@ int dmi_get_year(int field)return 0 ;Quoted 8 lines
drivers/firmware/dmi_scan.c int dmi_get_year(int field) · line 617
Quoted 6 lines
drivers/firmware/dmi_scan.c +1
-1s +=1 ; - year =simple_strtoul (s,NULL ,0 ); + year =simple_strtoul (s,NULL ,10 );if (year && year <100 ) {/* 2-digit year */ year +=1900 ;if (year <1996 )/* no dates < spec 1.0 */ I just noticed, that this is not enough, because this will still fail for xxx/xx/00. I suggest the following patch:
Quoted 5 lines
Actually the patch below is not correct. Standard says consider xx/xx/yy as 19yy, not 20yy.
BTW. the patch above is not useful, reporting 1908 and 1909 as a year is almost the same as 1900.
Sorry, I don't understand. simple_strtoul will return 8 for my bios. So
1900 will get added resulting in 1908 (as you said). But because 1908 is still less than 1996 now 100 will get added which results in 2008 which is what I need.
Quoted 1 line
Do you have such a broken BIOS?
Yes. Its on an etx-cd, an embedded board from kontron. dmidecode output:
Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
Vendor: Phoenix Technologies LTD
Version: MCALR116
Release Date: 08/13/08
Address: 0xE3F90
Runtime Size: 114800 bytes
ROM Size: 1024 kB
Characteristics:
ISA is supported
PCI is supported
PC Card (PCMCIA) is supported PNP is supported
BIOS is upgradeable
BIOS shadowing is allowed ESCD support is available Boot from CD is supported ACPI is supported
USB legacy is supported
BIOS boot specification is supported
Our systems started to fail after we got boards with a newer bios from our supplier...
Quoted 27 lines
Quoted 26 lines
firmware/dmi_scan.c Wed Jul 8 02:42:17 2009 renamed from firmware/dmi_scan.c.bak Wed Jul 8 02:42:04 2009 +9
-6@@ -360,12 +360,15 @@ return 0; s += 1; - year = simple_strtoul(s, NULL, 0); - if (year && year < 100) { /* 2-digit year */ - year += 1900; - if (year < 1996) /* no dates < spec 1.0 */ - year += 100; + if (s[0] == '0' && s[1] == '0' && s[2] == '\0') { + year = 2000; + } else { + year = simple_strtoul(s, NULL, 10); + if (year && year < 100) { /* 2-digit year */ + year += 1900; + if (year < 1996) /* no dates < spec 1.0 */ + year += 100; + } } - return year; }
Signature · 5 lines
Matthias Pfaller Software Entwicklung marco Systemanalyse und Entwicklung GmbH Tel +49 8131 5161 41 Hans-Böckler-Str. 2, D 85221 Dachau Fax +49 8131 5161 66 http://www.marco.de/ Email [email protected] Geschäftsführer Martin Reuter HRB 171775 Amtsgericht München
DMI year "00" + ACPI [was: DMI: fix dmi_get_year year parsing]
Quoted 29 lines · Matthias Pfaller
Quoted 28 lines · Jiri Slaby
Quoted 26 lines · Matthias Pfaller
Quoted 15 lines · Jiri Slaby
Don't guess a year number base. Use 10 instead, since year may be 2-digit starting with 0, so that we would end up in base equal to 8.
Signed-off-by Jiri Slaby <[email protected]>Reported-by Matthias Pfaller <[email protected]>--- drivers/firmware/dmi_scan.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/firmware/dmi_scan.c +0
-0drivers/firmware/dmi_scan.c int dmi_get_year(int field) · line 617
Quoted 8 lines
drivers/firmware/dmi_scan.c +1
-1@@ -611,7 +611,7 @@ int dmi_get_year(int field)return 0 ; s +=1 ; - year =simple_strtoul (s,NULL ,0 ); + year =simple_strtoul (s,NULL ,10 );if (year && year <100 ) {/* 2-digit year */ year +=1900 ;if (year <1996 )/* no dates < spec 1.0 */ I just noticed, that this is not enough, because this will still fail for xxx/xx/00. I suggest the following patch:
Quoted 7 lines
Quoted 5 lines
Actually the patch below is not correct. Standard says consider xx/xx/yy as 19yy, not 20yy.
BTW. the patch above is not useful, reporting 1908 and 1909 as a year is almost the same as 1900.
Sorry, I don't understand.
Nevermind, you're right. Both patches are OK, however we might hit a regression with 00/00/00 entries so that acpi gets unintentionally armed now for them (ACPI checks year == 0). I don't know if it's worth it. Any ideas?
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
firmware/dmi_scan.c Wed Jul 8 02:42:17 2009 renamed from firmware/dmi_scan.c.bak Wed Jul 8 02:42:04 2009 +7
-5@@ -360,12 +360,15 @@ return 0; s += 1; - year = simple_strtoul(s, NULL, 0); - if (year && year < 100) { /* 2-digit year */ - year += 1900; - if (year < 1996) /* no dates < spec 1.0 */ - year += 100; + if (s[0] == '0' && s[1] == '0' && s[2] == '\0') { + year = 2000; + } else { + year = simple_strtoul(s, NULL, 10); + if (year && year < 100) { /* 2-digit year */ + year += 1900; + if (year < 1996) /* no dates < spec1.0 */
firmware/dmi_scan.c Wed Jul 8 02:42:17 2009 renamed from firmware/dmi_scan.c.bak Wed Jul 8 02:42:04 2009 +2
-1+ year += 100; + } } - return year; }
Re: DMI year "00" + ACPI [was: DMI: fix dmi_get_year year parsing]
Quoted 32 lines · Jiri Slaby
Quoted 31 lines · Matthias Pfaller
Quoted 30 lines · Jiri Slaby
Quoted 18 lines · Matthias Pfaller
Quoted 17 lines · Jiri Slaby
Don't guess a year number base. Use 10 instead, since year may be 2-digit starting with 0, so that we would end up in base equal to 8.
Signed-off-by Jiri Slaby <[email protected]>Reported-by Matthias Pfaller <[email protected]>--- drivers/firmware/dmi_scan.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/firmware/dmi_scan.c +0
-0@@ -611,7 +611,7 @@ int dmi_get_year(int field)return 0 ;Quoted 8 lines
drivers/firmware/dmi_scan.c int dmi_get_year(int field) · line 617
Quoted 6 lines
drivers/firmware/dmi_scan.c +1
-1s +=1 ; - year =simple_strtoul (s,NULL ,0 ); + year =simple_strtoul (s,NULL ,10 );if (year && year <100 ) {/* 2-digit year */ year +=1900 ;if (year <1996 )/* no dates < spec 1.0 */ I just noticed, that this is not enough, because this will still fail for xxx/xx/00. I suggest the following patch:
Actually the patch below is not correct. Standard says consider xx/xx/yy as 19yy, not 20yy.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
BTW. the patch above is not useful, reporting 1908 and 1909 as a year is almost the same as 1900.
Sorry, I don't understand.
Nevermind, you're right. Both patches are OK, however we might hit a regression with 00/00/00 entries so that acpi gets unintentionally armed now for them (ACPI checks year == 0). I don't know if it's worth it. Any ideas?
There are bioses with 00/00/00? How about that:
dmi_scan.c Thu Jul 9 03:38:19 2009 renamed from dmi_scan.c.orig Thu Jul 9 03:34:48 2009 +25 -7
@@ -352,17 +352,36 @@ return -1; if (*s == '\0') return 0; + + /* Month must not be zero */ + if (simple_strtoul(s, NULL, 10) == 0) + return 0; + + /* Look for day of month */ + s = strchr(s, '/'); + if (!s) + return 0; + + /* Day of month must not be zero */ + s += 1; + if (simple_strtoul(s, NULL, 10) == 0) + return 0; + + /* Look for year */ s = strrchr(s, '/'); if (!s) return 0; s += 1; - year = simple_strtoul(s, NULL, 0); - if (year && year < 100) { /* 2-digit year */ - year += 1900; - if (year < 1996) /* no dates < spec 1.0 */ - year += 100; + if (s[0] == '0' && s[1] == '0' && s[2] == '\0') { + year = 2000; + } else { + year = simple_strtoul(s, NULL, 10); + if (year && year < 100) { /* 2-digit year */ + year += 1900; + if (year < 1996) /* no dates < spec 1.0 */ + year += 100; + } } - return year; } --
Matthias Pfaller Software Entwicklung
marco Systemanalyse und Entwicklung GmbH Tel +49 8131 5161 41
Hans-Böckler-Str. 2, D 85221 Dachau Fax +49 8131 5161 66
http://www.marco.de/ Email [email protected]
Geschäftsführer Martin Reuter HRB 171775 Amtsgericht München
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html