Skip to content

Commit

Permalink
Merge branch 'dmi-for-linus' of git://git.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/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
  • Loading branch information
Linus Torvalds committed Feb 3, 2018
2 parents 1726aa7 + a81114d commit 85b8bac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
2 changes: 1 addition & 1 deletion drivers/firmware/dmi-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ static int __init dmi_sysfs_init(void)
int val;

if (!dmi_kobj) {
pr_err("dmi-sysfs: dmi entry is absent.\n");
pr_debug("dmi-sysfs: dmi entry is absent.\n");
error = -ENODATA;
goto err;
}
Expand Down
64 changes: 28 additions & 36 deletions drivers/firmware/dmi_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,14 @@ EXPORT_SYMBOL_GPL(dmi_kobj);
* of and an antecedent to, SMBIOS, which stands for System
* Management BIOS. See further: http://www.dmtf.org/standards
*/
static const char dmi_empty_string[] = " ";
static const char dmi_empty_string[] = "";

static u32 dmi_ver __initdata;
static u32 dmi_len;
static u16 dmi_num;
static u8 smbios_entry_point[32];
static int smbios_entry_point_size;

/*
* Catch too early calls to dmi_check_system():
*/
static int dmi_initialized;

/* DMI system identification string used during boot */
static char dmi_ids_string[128] __initdata;

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

if (s) {
s--;
while (s > 0 && *bp) {
while (--s > 0 && *bp)
bp += strlen(bp) + 1;
s--;
}

if (*bp != 0) {
size_t len = strlen(bp)+1;
size_t cmp_len = len > 8 ? 8 : len;

if (!memcmp(bp, dmi_empty_string, cmp_len))
return dmi_empty_string;
/* Strings containing only spaces are considered empty */
nsp = bp;
while (*nsp == ' ')
nsp++;
if (*nsp != '\0')
return bp;
}
}

return "";
return dmi_empty_string;
}

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

if (!dmi_smbios3_present(buf)) {
dmi_available = 1;
goto out;
return;
}
}
if (efi.smbios == EFI_INVALID_TABLE_ADDR)
Expand All @@ -651,7 +642,7 @@ void __init dmi_scan_machine(void)

if (!dmi_present(buf)) {
dmi_available = 1;
goto out;
return;
}
} else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) {
p = dmi_early_remap(0xF0000, 0x10000);
Expand All @@ -668,7 +659,7 @@ void __init dmi_scan_machine(void)
if (!dmi_smbios3_present(buf)) {
dmi_available = 1;
dmi_early_unmap(p, 0x10000);
goto out;
return;
}
memcpy(buf, buf + 16, 16);
}
Expand All @@ -686,16 +677,14 @@ void __init dmi_scan_machine(void)
if (!dmi_present(buf)) {
dmi_available = 1;
dmi_early_unmap(p, 0x10000);
goto out;
return;
}
memcpy(buf, buf + 16, 16);
}
dmi_early_unmap(p, 0x10000);
}
error:
pr_info("DMI not present or invalid.\n");
out:
dmi_initialized = 1;
}

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

if (!dmi_available) {
ret = -ENODATA;
goto err;
}
if (!dmi_available)
return 0;

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

WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");

for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
int s = dmi->matches[i].slot;
if (s == DMI_NONE)
break;
if (dmi_ident[s]) {
if (!dmi->matches[i].exact_match &&
strstr(dmi_ident[s], dmi->matches[i].substr))
continue;
else if (dmi->matches[i].exact_match &&
!strcmp(dmi_ident[s], dmi->matches[i].substr))
continue;
if (dmi->matches[i].exact_match) {
if (!strcmp(dmi_ident[s],
dmi->matches[i].substr))
continue;
} else {
if (strstr(dmi_ident[s],
dmi->matches[i].substr))
continue;
}
}

/* No match */
Expand Down Expand Up @@ -826,6 +814,8 @@ static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
* Walk the blacklist table running matching functions until someone
* returns non zero or we hit the end. Callback function is called for
* each successful match. Returns the number of matches.
*
* dmi_scan_machine must be called before this function is called.
*/
int dmi_check_system(const struct dmi_system_id *list)
{
Expand Down Expand Up @@ -854,6 +844,8 @@ EXPORT_SYMBOL(dmi_check_system);
*
* Walk the blacklist table until the first match is found. Return the
* pointer to the matching entry or NULL if there's no match.
*
* dmi_scan_machine must be called before this function is called.
*/
const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
{
Expand Down

0 comments on commit 85b8bac

Please sign in to comment.