Skip to content

Commit 80f9d90

Browse files
committed
Merge tag 'dmi-for-v6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
Pull dmi updates from Jean Delvare: "Bug fixes: - KCFI violation in dmi-id - stop decoding on broken (short) DMI table entry New features: - print info about populated memory slots at boot" * tag 'dmi-for-v6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: firmware: dmi: Add info message for number of populated and total memory slots firmware: dmi: Stop decoding on broken entry firmware: dmi-id: add a release callback function
2 parents a913d94 + 4d1b28a commit 80f9d90

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

drivers/firmware/dmi-id.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,14 @@ static int dmi_dev_uevent(const struct device *dev, struct kobj_uevent_env *env)
169169
return 0;
170170
}
171171

172+
static void dmi_dev_release(struct device *dev)
173+
{
174+
kfree(dev);
175+
}
176+
172177
static struct class dmi_class = {
173178
.name = "dmi",
174-
.dev_release = (void(*)(struct device *)) kfree,
179+
.dev_release = dmi_dev_release,
175180
.dev_uevent = dmi_dev_uevent,
176181
};
177182

drivers/firmware/dmi_scan.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static struct dmi_memdev_info {
4242
u8 type; /* DDR2, DDR3, DDR4 etc */
4343
} *dmi_memdev;
4444
static int dmi_memdev_nr;
45+
static int dmi_memdev_populated_nr __initdata;
4546

4647
static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
4748
{
@@ -101,6 +102,17 @@ static void dmi_decode_table(u8 *buf,
101102
(data - buf + sizeof(struct dmi_header)) <= dmi_len) {
102103
const struct dmi_header *dm = (const struct dmi_header *)data;
103104

105+
/*
106+
* If a short entry is found (less than 4 bytes), not only it
107+
* is invalid, but we cannot reliably locate the next entry.
108+
*/
109+
if (dm->length < sizeof(struct dmi_header)) {
110+
pr_warn(FW_BUG
111+
"Corrupted DMI table, offset %zd (only %d entries processed)\n",
112+
data - buf, i);
113+
break;
114+
}
115+
104116
/*
105117
* We want to know the total length (formatted area and
106118
* strings) before decoding to make sure we won't run off the
@@ -448,6 +460,9 @@ static void __init save_mem_devices(const struct dmi_header *dm, void *v)
448460
else
449461
bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20;
450462

463+
if (bytes)
464+
dmi_memdev_populated_nr++;
465+
451466
dmi_memdev[nr].size = bytes;
452467
nr++;
453468
}
@@ -824,6 +839,8 @@ void __init dmi_setup(void)
824839
return;
825840

826841
dmi_memdev_walk();
842+
pr_info("DMI: Memory slots populated: %d/%d\n",
843+
dmi_memdev_populated_nr, dmi_memdev_nr);
827844
dump_stack_set_arch_desc("%s", dmi_ids_string);
828845
}
829846

0 commit comments

Comments
 (0)