Skip to content

Commit 8cf4e6a

Browse files
committed
firmware: dmi: Optimize dmi_matches
Function dmi_matches can me made a bit faster: * The documented purpose of dmi_initialized is to catch too early calls to dmi_check_system(). I'm not fully convinced it justifies slowing down the initialization of all systems out there, but at least the check should not have been moved from dmi_check_system() to dmi_matches(). dmi_matches() is being called for every entry of the table passed to dmi_check_system(), causing the same redundant check to be performed again and again. So move it back to dmi_check_system(), reverting this specific portion of commit d7b1956 ("DMI: Introduce dmi_first_match to make the interface more flexible"). * Don't check for the exact_match flag again when we already know its value. Signed-off-by: Jean Delvare <[email protected]> Fixes: d7b1956 ("DMI: Introduce dmi_first_match to make the interface more flexible") Cc: Jani Nikula <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: Jeff Garzik <[email protected]>
1 parent d8a5b80 commit 8cf4e6a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/firmware/dmi_scan.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,19 +784,20 @@ static bool dmi_matches(const struct dmi_system_id *dmi)
784784
{
785785
int i;
786786

787-
WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
788-
789787
for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
790788
int s = dmi->matches[i].slot;
791789
if (s == DMI_NONE)
792790
break;
793791
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;
792+
if (dmi->matches[i].exact_match) {
793+
if (!strcmp(dmi_ident[s],
794+
dmi->matches[i].substr))
795+
continue;
796+
} else {
797+
if (strstr(dmi_ident[s],
798+
dmi->matches[i].substr))
799+
continue;
800+
}
800801
}
801802

802803
/* No match */
@@ -832,6 +833,8 @@ int dmi_check_system(const struct dmi_system_id *list)
832833
int count = 0;
833834
const struct dmi_system_id *d;
834835

836+
WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
837+
835838
for (d = list; !dmi_is_end_of_table(d); d++)
836839
if (dmi_matches(d)) {
837840
count++;

0 commit comments

Comments
 (0)