linuxkpi/dmi: don't match exactly on DMI_MATCH

Linux has two defines to check dmi data. DMI_MATCH checks if the dmi
string includes substr. DMI_EXACT_MATCH checks if the dmi string exactly
matches substr. Compat layer should have the same behaviour.

The new definition of dmi_strmatch shouldn't break any driver. A driver
would break if it uses the highest bit of the slot field. Nevertheless,
linux uses the same definition and FreeBSD uses dmi_field values as slot
which are lower than 128.

Sponsored by:		Beckhoff Automation GmbH & Co. KG
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D35395
This commit is contained in:
Corvin Köhne 2022-06-03 16:20:45 +02:00 committed by Emmanuel Vadot
parent 9d28e15e7b
commit 99902b1c52
2 changed files with 10 additions and 5 deletions

View File

@ -55,7 +55,8 @@ enum dmi_field {
};
struct dmi_strmatch {
unsigned char slot;
unsigned char slot : 7;
unsigned char exact_match : 1;
char substr[79];
};
@ -67,6 +68,6 @@ struct dmi_system_id {
};
#define DMI_MATCH(a, b) { .slot = a, .substr = b }
#define DMI_EXACT_MATCH(a, b) { .slot = a, .substr = b, }
#define DMI_EXACT_MATCH(a, b) { .slot = a, .substr = b, .exact_match = 1 }
#endif /* __LINUXKPI_LINUX_MOD_DEVICETABLE_H__ */

View File

@ -82,9 +82,13 @@ linux_dmi_matches(const struct dmi_system_id *dsi)
for (i = 0; i < nitems(dsi->matches); i++) {
if (dsi->matches[i].slot == DMI_NONE)
break;
if (dmi_match(dsi->matches[i].slot,
dsi->matches[i].substr) == false)
return (false);
if (dsi->matches[i].exact_match) {
return (dmi_match(dsi->matches[i].slot,
dsi->matches[i].substr));
} else {
return (strstr(dmi_data[dsi->matches[i].slot],
dsi->matches[i].substr) != NULL);
}
}
return (true);