Skip to content

Commit 85b8bac

Browse files
committed
Merge branch 'dmi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
Pull dmi subsystem updates/fixes from Jean Delvare. * 'dmi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: firmware: dmi: handle missing DMI data gracefully firmware: dmi_scan: Fix handling of empty DMI strings firmware: dmi_scan: Drop dmi_initialized firmware: dmi: Optimize dmi_matches
2 parents 1726aa7 + a81114d commit 85b8bac

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

drivers/firmware/dmi-sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ static int __init dmi_sysfs_init(void)
652652
int val;
653653

654654
if (!dmi_kobj) {
655-
pr_err("dmi-sysfs: dmi entry is absent.\n");
655+
pr_debug("dmi-sysfs: dmi entry is absent.\n");
656656
error = -ENODATA;
657657
goto err;
658658
}

drivers/firmware/dmi_scan.c

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@ EXPORT_SYMBOL_GPL(dmi_kobj);
1818
* of and an antecedent to, SMBIOS, which stands for System
1919
* Management BIOS. See further: http://www.dmtf.org/standards
2020
*/
21-
static const char dmi_empty_string[] = " ";
21+
static const char dmi_empty_string[] = "";
2222

2323
static u32 dmi_ver __initdata;
2424
static u32 dmi_len;
2525
static u16 dmi_num;
2626
static u8 smbios_entry_point[32];
2727
static int smbios_entry_point_size;
2828

29-
/*
30-
* Catch too early calls to dmi_check_system():
31-
*/
32-
static int dmi_initialized;
33-
3429
/* DMI system identification string used during boot */
3530
static char dmi_ids_string[128] __initdata;
3631

@@ -44,25 +39,21 @@ static int dmi_memdev_nr;
4439
static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
4540
{
4641
const u8 *bp = ((u8 *) dm) + dm->length;
42+
const u8 *nsp;
4743

4844
if (s) {
49-
s--;
50-
while (s > 0 && *bp) {
45+
while (--s > 0 && *bp)
5146
bp += strlen(bp) + 1;
52-
s--;
53-
}
5447

55-
if (*bp != 0) {
56-
size_t len = strlen(bp)+1;
57-
size_t cmp_len = len > 8 ? 8 : len;
58-
59-
if (!memcmp(bp, dmi_empty_string, cmp_len))
60-
return dmi_empty_string;
48+
/* Strings containing only spaces are considered empty */
49+
nsp = bp;
50+
while (*nsp == ' ')
51+
nsp++;
52+
if (*nsp != '\0')
6153
return bp;
62-
}
6354
}
6455

65-
return "";
56+
return dmi_empty_string;
6657
}
6758

6859
static const char * __init dmi_string(const struct dmi_header *dm, u8 s)
@@ -633,7 +624,7 @@ void __init dmi_scan_machine(void)
633624

634625
if (!dmi_smbios3_present(buf)) {
635626
dmi_available = 1;
636-
goto out;
627+
return;
637628
}
638629
}
639630
if (efi.smbios == EFI_INVALID_TABLE_ADDR)
@@ -651,7 +642,7 @@ void __init dmi_scan_machine(void)
651642

652643
if (!dmi_present(buf)) {
653644
dmi_available = 1;
654-
goto out;
645+
return;
655646
}
656647
} else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) {
657648
p = dmi_early_remap(0xF0000, 0x10000);
@@ -668,7 +659,7 @@ void __init dmi_scan_machine(void)
668659
if (!dmi_smbios3_present(buf)) {
669660
dmi_available = 1;
670661
dmi_early_unmap(p, 0x10000);
671-
goto out;
662+
return;
672663
}
673664
memcpy(buf, buf + 16, 16);
674665
}
@@ -686,16 +677,14 @@ void __init dmi_scan_machine(void)
686677
if (!dmi_present(buf)) {
687678
dmi_available = 1;
688679
dmi_early_unmap(p, 0x10000);
689-
goto out;
680+
return;
690681
}
691682
memcpy(buf, buf + 16, 16);
692683
}
693684
dmi_early_unmap(p, 0x10000);
694685
}
695686
error:
696687
pr_info("DMI not present or invalid.\n");
697-
out:
698-
dmi_initialized = 1;
699688
}
700689

701690
static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
@@ -715,10 +704,8 @@ static int __init dmi_init(void)
715704
u8 *dmi_table;
716705
int ret = -ENOMEM;
717706

718-
if (!dmi_available) {
719-
ret = -ENODATA;
720-
goto err;
721-
}
707+
if (!dmi_available)
708+
return 0;
722709

723710
/*
724711
* Set up dmi directory at /sys/firmware/dmi. This entry should stay
@@ -784,19 +771,20 @@ static bool dmi_matches(const struct dmi_system_id *dmi)
784771
{
785772
int i;
786773

787-
WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
788-
789774
for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
790775
int s = dmi->matches[i].slot;
791776
if (s == DMI_NONE)
792777
break;
793778
if (dmi_ident[s]) {
794-
if (!dmi->matches[i].exact_match &&
795-
strstr(dmi_ident[s], dmi->matches[i].substr))
796-
continue;
797-
else if (dmi->matches[i].exact_match &&
798-
!strcmp(dmi_ident[s], dmi->matches[i].substr))
799-
continue;
779+
if (dmi->matches[i].exact_match) {
780+
if (!strcmp(dmi_ident[s],
781+
dmi->matches[i].substr))
782+
continue;
783+
} else {
784+
if (strstr(dmi_ident[s],
785+
dmi->matches[i].substr))
786+
continue;
787+
}
800788
}
801789

802790
/* No match */
@@ -826,6 +814,8 @@ static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
826814
* Walk the blacklist table running matching functions until someone
827815
* returns non zero or we hit the end. Callback function is called for
828816
* each successful match. Returns the number of matches.
817+
*
818+
* dmi_scan_machine must be called before this function is called.
829819
*/
830820
int dmi_check_system(const struct dmi_system_id *list)
831821
{
@@ -854,6 +844,8 @@ EXPORT_SYMBOL(dmi_check_system);
854844
*
855845
* Walk the blacklist table until the first match is found. Return the
856846
* pointer to the matching entry or NULL if there's no match.
847+
*
848+
* dmi_scan_machine must be called before this function is called.
857849
*/
858850
const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
859851
{

0 commit comments

Comments
 (0)