Commit 5017b2851373ee15c7035151853bb1448800cae2

Authored by Jani Nikula
Committed by Linus Torvalds
1 parent 45c64940c8

dmi: add support for exact DMI matches in addition to substring matching

dmi_match() considers a substring match to be a successful match.  This is
not always sufficient to distinguish between DMI data for different
systems.  Add support for exact string matching using strcmp() in addition
to the substring matching using strstr().

The specific use case in the i915 driver is to allow us to use an exact
match for D510MO, without also incorrectly matching D510MOV:

  {
	.ident = "Intel D510MO",
	.matches = {
		DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
		DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
	},
  }

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Cc: <annndddrr@gmail.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Cornel Panceac <cpanceac@gmail.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 13 additions and 5 deletions Side-by-side Diff

drivers/firmware/dmi_scan.c
... ... @@ -551,9 +551,15 @@
551 551 int s = dmi->matches[i].slot;
552 552 if (s == DMI_NONE)
553 553 break;
554   - if (dmi_ident[s]
555   - && strstr(dmi_ident[s], dmi->matches[i].substr))
556   - continue;
  554 + if (dmi_ident[s]) {
  555 + if (!dmi->matches[i].exact_match &&
  556 + strstr(dmi_ident[s], dmi->matches[i].substr))
  557 + continue;
  558 + else if (dmi->matches[i].exact_match &&
  559 + !strcmp(dmi_ident[s], dmi->matches[i].substr))
  560 + continue;
  561 + }
  562 +
557 563 /* No match */
558 564 return false;
559 565 }
include/linux/mod_devicetable.h
... ... @@ -456,7 +456,8 @@
456 456 };
457 457  
458 458 struct dmi_strmatch {
459   - unsigned char slot;
  459 + unsigned char slot:7;
  460 + unsigned char exact_match:1;
460 461 char substr[79];
461 462 };
462 463  
... ... @@ -474,7 +475,8 @@
474 475 */
475 476 #define dmi_device_id dmi_system_id
476 477  
477   -#define DMI_MATCH(a, b) { a, b }
  478 +#define DMI_MATCH(a, b) { .slot = a, .substr = b }
  479 +#define DMI_EXACT_MATCH(a, b) { .slot = a, .substr = b, .exact_match = 1 }
478 480  
479 481 #define PLATFORM_NAME_SIZE 20
480 482 #define PLATFORM_MODULE_PREFIX "platform:"