]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/firmware/dmi_scan.c
DMI: Introduce dmi_first_match to make the interface more flexible
[linux-2.6-omap-h63xx.git] / drivers / firmware / dmi_scan.c
index d76adfea5df7c78bb6421a327f417ae3ed210fd6..8f0f7c44930540aa6829fdbe92b085d7c4009a46 100644 (file)
@@ -414,6 +414,29 @@ void __init dmi_scan_machine(void)
        dmi_initialized = 1;
 }
 
+/**
+ *     dmi_matches - check if dmi_system_id structure matches system DMI data
+ *     @dmi: pointer to the dmi_system_id structure to check
+ */
+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)
+                       continue;
+               if (dmi_ident[s]
+                   && strstr(dmi_ident[s], dmi->matches[i].substr))
+                       continue;
+               /* No match */
+               return false;
+       }
+       return true;
+}
+
 /**
  *     dmi_check_system - check system DMI data
  *     @list: array of dmi_system_id structures to match against
@@ -429,31 +452,44 @@ void __init dmi_scan_machine(void)
  */
 int dmi_check_system(const struct dmi_system_id *list)
 {
-       int i, count = 0;
-       const struct dmi_system_id *d = list;
-
-       WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
-
-       while (d->ident) {
-               for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
-                       int s = d->matches[i].slot;
-                       if (s == DMI_NONE)
-                               continue;
-                       if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr))
-                               continue;
-                       /* No match */
-                       goto fail;
+       int count = 0;
+       const struct dmi_system_id *d;
+
+       for (d = list; d->ident; d++)
+               if (dmi_matches(d)) {
+                       count++;
+                       if (d->callback && d->callback(d))
+                               break;
                }
-               count++;
-               if (d->callback && d->callback(d))
-                       break;
-fail:          d++;
-       }
 
        return count;
 }
 EXPORT_SYMBOL(dmi_check_system);
 
+/**
+ *     dmi_first_match - find dmi_system_id structure matching system DMI data
+ *     @list: array of dmi_system_id structures to match against
+ *             All non-null elements of the list must match
+ *             their slot's (field index's) data (i.e., each
+ *             list string must be a substring of the specified
+ *             DMI slot's string data) to be considered a
+ *             successful match.
+ *
+ *     Walk the blacklist table until the first match is found.  Return the
+ *     pointer to the matching entry or NULL if there's no match.
+ */
+const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
+{
+       const struct dmi_system_id *d;
+
+       for (d = list; d->ident; d++)
+               if (dmi_matches(d))
+                       return d;
+
+       return NULL;
+}
+EXPORT_SYMBOL(dmi_first_match);
+
 /**
  *     dmi_get_system_info - return DMI data value
  *     @field: data index (see enum dmi_field)