cros_config: Change cros_config_read_*sku_info* input array format

The cros_config_read_* have different arguments:
 - ARM (fdt) versions need a list of identifiers and one length arg.
 - X86 versions take a single comma separated list
Meanwhile, probe_frid and other functions take a string array with NULL
in last element.

To unify, we should always use NULL-terminated array and strlfind to
look up list.

BUG=chromium:982692
TEST=emerge-{kukui,octopus,eve} mosys; run 'mosys platform model' on device.

Change-Id: I4bb38062d9b9ce57750d3224656b5c9f88e0c878
Reviewed-on: https://chromium-review.googlesource.com/1697967
Tested-by: Hung-Te Lin <hungte@chromium.org>
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Hsin-Yi Wang <hsinyi@chromium.org>
diff --git a/include/lib/cros_config.h b/include/lib/cros_config.h
index 24884b4..534e438 100644
--- a/include/lib/cros_config.h
+++ b/include/lib/cros_config.h
@@ -41,13 +41,12 @@
  * Read information about the current model.
  *
  * @intf: Platform information, used to access SMBIOS name and SKU ID
- * @find_platform_names: Comma-separated list of platform names that are
- *    permitted
+ * @find_platform_names: Array of permitted platform names, end with NULL
  * @sku_info: Returns SKU information on success
  * @return: 0 if OK, other value on error
  */
 int cros_config_read_sku_info(struct platform_intf *intf,
-			      const char *find_platform_names,
+			      const char *find_platform_names[],
 			      struct sku_info *sku_info);
 
 /**
@@ -60,15 +59,12 @@
  * @compat_platform_names: Array of platform names that are permitted,
  *    use the platform id not including the leading 'google,'. Platform
  *    id 'google,gru' should pass in only 'gru'. Platform ids are currently
- *    limited to 256 chars.
- * @compat_platform_names_size: Number of elements in the
- *    compat_platform_names array
+ *    limited to 256 chars, and the array must end with NULL.
  * @sku_info: Returns SKU information on success
  * @return: 0 if OK, other value on error
  */
 int cros_config_read_sku_info_fdt(struct platform_intf *intf,
 			          const char *compat_platform_names[],
-				  int compat_platform_names_size,
 			      	  struct sku_info *sku_info);
 /**
  * cros_config_read_default_sku_info_fdt() - read SKU information for current
@@ -81,9 +77,7 @@
  * @compat_platform_names: Array of platform names that are permitted,
  *    use the platform id not including the leading 'google,'. Platform
  *    id 'google,gru' should pass in only 'gru'. Platform ids are currently
- *    limited to 256 chars.
- * @compat_platform_names_size: Number of elements in the
- *    compat_platform_names array
+ *    limited to 256 chars, and the array must end with NULL.
  * @default_sku_id: The fallback sku id if fdt_get_sku_id() returns
  *    invalid (<0) sku id. Pass negative value here if we don't want to
  *    fall back.
@@ -92,7 +86,6 @@
  */
 int cros_config_read_default_sku_info_fdt(struct platform_intf *intf,
 					  const char *compat_platform_names[],
-					  int compat_platform_names_size,
 					  const int default_sku_id,
 					  struct sku_info *sku_info);
 
@@ -103,14 +96,13 @@
  * Read information about the current model.
  *
  * @intf: Platform information, used to access SMBIOS name and SKU ID
- * @find_platform_names: Comma-separated list of platform names that are
- *    permitted
+ * @find_platform_names: Array of permitted platform names, end with NULL
  * @forced_sku_number: forced sku number
  * @sku_info: Returns SKU information on success
  * @return: 0 if OK, other value on error
  */
 int cros_config_read_forced_sku_info(struct platform_intf *intf,
-			             const char *find_platform_names,
+			             const char *find_platform_names[],
 			             const int forced_sku_number,
 			             struct sku_info *sku_info);
 
@@ -118,11 +110,10 @@
  * cros_config_smbios_platform_name_match() - shallow match on sbmios name
  *
  * @intf: Platform information, used to access SMBIOS name and SKU ID
- * @find_platform_names: Comma-separated list of platform names that are
- *    permitted
+ * @find_platform_names: Array of permitted platform names, end with NULL
  * @return: 0 if OK, other value on error
  */
 int cros_config_smbios_platform_name_match(struct platform_intf *intf,
-					const char *find_platform_names);
+					   const char *find_platform_names[]);
 
 #endif
diff --git a/lib/cros_config/cros_config.c b/lib/cros_config/cros_config.c
index 50a9aa2..d740738 100644
--- a/lib/cros_config/cros_config.c
+++ b/lib/cros_config/cros_config.c
@@ -50,41 +50,16 @@
 #include "lib/string.h"
 
 
-#ifdef CONFIG_PLATFORM_ARCH_X86
-/**
- * string_in_list() - Check if a name is in a comma-separated list
- *
- * @name: Name to search for
- * @list: List of names to search in, separated by a comma
- * @return true if found, false if not found
- */
-static bool string_in_list(const char *name, const char *list)
-{
-	const char *p, *end;
-
-	for (p = list; *p; p = end + (*end == ',')) {
-		end = strchrnul(p, ',');
-		if (!strncmp(name, p, end - p))
-			return true;
-	}
-
-	return false;
-}
-#endif // CONFIG_PLATFORM_ARCH_X86
-
 int cros_config_read_sku_info_fdt(struct platform_intf *intf,
 				  const char *compat_platform_names[],
-				  int compat_platform_names_size,
 				  struct sku_info *sku_info)
 {
-	return cros_config_read_default_sku_info_fdt(intf,
-		compat_platform_names, compat_platform_names_size,
-		-1, sku_info);
+	return cros_config_read_default_sku_info_fdt(
+			intf, compat_platform_names, -1, sku_info);
 }
 
 int cros_config_read_default_sku_info_fdt(struct platform_intf *intf,
 					  const char *compat_platform_names[],
-					  int compat_platform_names_size,
 					  const int default_sku_id,
 					  struct sku_info *sku_info)
 {
@@ -107,7 +82,7 @@
 	// probe_fdt_compatible() returns an index of the matching name
 	// found in the find_platform_names list. Success is an index
 	// that is greater than or equal zero.
-	for (int i = 0; i < compat_platform_names_size; ++i) {
+	for (int i = 0; compat_platform_names[i]; ++i) {
 		char platform_name[MAX_NAME_LEN + 1];
 		platform_name[MAX_NAME_LEN] = '\0';
 		int ret = snprintf(platform_name, MAX_NAME_LEN, "google,%s",
@@ -138,7 +113,7 @@
 }
 
 int cros_config_read_sku_info(struct platform_intf *intf,
-			      const char *find_platform_names,
+			      const char *find_platform_names[],
 			      struct sku_info *sku_info)
 {
 #ifdef CONFIG_PLATFORM_ARCH_X86
@@ -152,11 +127,8 @@
 	if (sku_id == -1)
 		lprintf(LOG_DEBUG, "%s: Unknown SKU ID\n", __func__);
 
-	if (smbios_name && !string_in_list(smbios_name, find_platform_names)) {
-		lprintf(LOG_DEBUG, "%s: Could not locate name '%s' in '%s'\n",
-			__func__, smbios_name, find_platform_names);
+	if (smbios_name && !strlfind(smbios_name, find_platform_names, 1))
 		return -ENOENT;
-	}
 	return cros_config_read_sku_info_struct(intf, sku_id, sku_info);
 #else // CONFIG_PLATFORM_ARCH_X86
 	lprintf(LOG_ERR, "Only X86 platforms should call %s\n", __func__);
@@ -166,7 +138,7 @@
 
 // TODO(gmeinke): combine read forced sku with existing read function.
 int cros_config_read_forced_sku_info(struct platform_intf *intf,
-				     const char *find_platform_names,
+				     const char *find_platform_names[],
 				     const int forced_sku_number,
 				     struct sku_info *sku_info)
 {
@@ -177,11 +149,8 @@
 	if (!smbios_name)
 		lprintf(LOG_DEBUG, "%s: Unknown SMBIOS name\n", __func__);
 
-	if (smbios_name && !string_in_list(smbios_name, find_platform_names)) {
-		lprintf(LOG_DEBUG, "%s: Could not locate name '%s' in '%s'\n",
-			__func__, smbios_name, find_platform_names);
+	if (smbios_name && !strlfind(smbios_name, find_platform_names, 1))
 		return -ENOENT;
-	}
 	return cros_config_read_sku_info_struct(intf, forced_sku_number,
 						  sku_info);
 #else // CONFIG_PLATFORM_ARCH_X86
@@ -191,7 +160,7 @@
 }
 
 int cros_config_smbios_platform_name_match(struct platform_intf *intf,
-					   const char *find_platform_names)
+					   const char *find_platform_names[])
 {
 #ifdef CONFIG_PLATFORM_ARCH_X86
 	const char *smbios_name;
@@ -202,11 +171,8 @@
 		return -ENOENT;
 	}
 
-	if (!string_in_list(smbios_name, find_platform_names)) {
-		lprintf(LOG_DEBUG, "%s: Could not locate name '%s' in '%s'\n",
-			__func__, smbios_name, find_platform_names);
+	if (!strlfind(smbios_name, find_platform_names, 1))
 		return -ENOENT;
-	}
 
 	return 0;
 #else // CONFIG_PLATFORM_ARCH_X86
diff --git a/platform/cheza/cheza.c b/platform/cheza/cheza.c
index 2ca2eb2..cb2f158 100644
--- a/platform/cheza/cheza.c
+++ b/platform/cheza/cheza.c
@@ -64,11 +64,10 @@
 
 static int cheza_probe(struct platform_intf *intf)
 {
-	static const char* platform_arr[] = {"cheza"};
+	static const char* platform_arr[] = {"cheza", NULL};
 	static struct sku_info sku_info;
 
-	int ret = cros_config_read_sku_info_fdt(intf, platform_arr, 1,
-						&sku_info);
+	int ret = cros_config_read_sku_info_fdt(intf, platform_arr, &sku_info);
 	/* If there was no error, indicate that we found a match */
 	if (!ret) {
 		intf->sku_info = &sku_info;
diff --git a/platform/fizz/fizz.c b/platform/fizz/fizz.c
index df883d4..5439030 100644
--- a/platform/fizz/fizz.c
+++ b/platform/fizz/fizz.c
@@ -66,12 +66,17 @@
 	NULL
 };
 
+static const char *platform_names[] = {
+	"Fizz", "Karma",
+	NULL
+};
+
 int fizz_probe(struct platform_intf *intf)
 {
 	static struct sku_info sku_info;
 	int ret;
 
-	ret = cros_config_read_sku_info(intf, "Fizz,Karma", &sku_info);
+	ret = cros_config_read_sku_info(intf, platform_names, &sku_info);
 
 	/* If there was no error, indicate that we found a match */
 	if (!ret) {
diff --git a/platform/glados/glados.c b/platform/glados/glados.c
index cbf3b4c..59e9b45 100644
--- a/platform/glados/glados.c
+++ b/platform/glados/glados.c
@@ -108,10 +108,13 @@
 	static struct sku_info sku_info;
 	int ret = 0;
 
-	if (!cros_config_smbios_platform_name_match(intf, "Soraka,Rammus")) {
+	const char *platform1[] = {
+		"Soraka", "Rammus",
+		NULL
+	};
+	if (!cros_config_smbios_platform_name_match(intf, platform1)) {
 		/** Soraka,Rammus will always work correctly, no hacks needed */
-		ret = cros_config_read_sku_info(intf, "Soraka,Rammus",
-					        &sku_info);
+		ret = cros_config_read_sku_info(intf, platform1, &sku_info);
 		if (!ret) {
 			intf->sku_info = &sku_info;
 			return 1;
@@ -119,9 +122,13 @@
 		return 0;
 	}
 
-	if (!cros_config_smbios_platform_name_match(intf, "Nautilus")) {
+	const char *platform2[] = {
+		"Nautilus",
+		NULL
+	};
+	if (!cros_config_smbios_platform_name_match(intf, platform2)) {
 		/** Nautilus uni-build will work correctly, no hacks needed. */
-		ret = cros_config_read_sku_info(intf, "Nautilus", &sku_info);
+		ret = cros_config_read_sku_info(intf, platform2, &sku_info);
 		if (!ret) {
 			intf->sku_info = &sku_info;
 			return 1;
@@ -132,7 +139,7 @@
 		lprintf(LOG_DEBUG,
 			"%s: read_sku_info failed for Nautilus, force sku=0\n",
 			__func__);
-		ret = cros_config_read_forced_sku_info(intf, "Nautilus", 0,
+		ret = cros_config_read_forced_sku_info(intf, platform2, 0,
 						       &sku_info);
 		if (!ret) {
 			intf->sku_info = &sku_info;
diff --git a/platform/gru/gru.c b/platform/gru/gru.c
index 3817160..b16876c 100644
--- a/platform/gru/gru.c
+++ b/platform/gru/gru.c
@@ -87,10 +87,10 @@
 static int gru_probe(struct platform_intf *intf)
 {
 #ifdef CONFIG_CROS_CONFIG
-	static const char* platform_arr[] = {"gru"};
+	static const char* platform_arr[] = {"gru", NULL};
 	static struct sku_info sku_info;
 
-	int ret = cros_config_read_default_sku_info_fdt(intf, platform_arr, 1,
+	int ret = cros_config_read_default_sku_info_fdt(intf, platform_arr,
 						        SCARLET_DEFAULT_SKU_ID,
 						        &sku_info);
 	/* If there was no error, indicate that we found a match */
diff --git a/platform/hatch/hatch.c b/platform/hatch/hatch.c
index 07ba198..685d81d 100644
--- a/platform/hatch/hatch.c
+++ b/platform/hatch/hatch.c
@@ -59,7 +59,10 @@
 	NULL
 };
 
-static const char *platform_names = "Hatch,Kohaku,Helios,Kindred";
+static const char *platform_names[] = {
+	"Hatch", "Kohaku", "Helios", "Kindred",
+	NULL
+};
 
 int hatch_probe(struct platform_intf *intf)
 {
diff --git a/platform/kahlee/kahlee.c b/platform/kahlee/kahlee.c
index a1fb420..0b06e38 100644
--- a/platform/kahlee/kahlee.c
+++ b/platform/kahlee/kahlee.c
@@ -61,12 +61,17 @@
 	NULL
 };
 
+static const char *platform_names[] = {
+	"Kahlee", "Grunt",
+	NULL
+};
+
 int kahlee_probe(struct platform_intf *intf)
 {
         static struct sku_info sku_info;
         int ret;
 
-        ret = cros_config_read_sku_info(intf, "Kahlee,Grunt", &sku_info);
+        ret = cros_config_read_sku_info(intf, platform_names, &sku_info);
 
         /* If there was no error, indicate that we found a match */
         if (!ret) {
diff --git a/platform/nami/nami.c b/platform/nami/nami.c
index b15d949..e91cdda 100644
--- a/platform/nami/nami.c
+++ b/platform/nami/nami.c
@@ -63,12 +63,18 @@
 	NULL
 };
 
+static const char *platform_names[] = {
+	"Nami",
+	NULL
+};
+
 int nami_probe(struct platform_intf *intf)
 {
 	static struct sku_info sku_info;
 	int ret;
 
-	ret = cros_config_read_sku_info(intf, "Nami", &sku_info);
+
+	ret = cros_config_read_sku_info(intf, platform_names, &sku_info);
 
 	/* If there was no error, indicate that we found a match */
 	if (!ret) {
diff --git a/platform/oak/oak.c b/platform/oak/oak.c
index 5d33a7c..cae702b 100644
--- a/platform/oak/oak.c
+++ b/platform/oak/oak.c
@@ -108,11 +108,13 @@
 static int kukui_probe(struct platform_intf *intf)
 {
 #ifdef CONFIG_CROS_CONFIG
-	static const char* platform_arr[] = {"flapjack", "krane", "kukui"};
+	static const char* platform_arr[] = {
+		"krane", "kukui", "flapjack",
+		NULL,
+	};
 	static struct sku_info sku_info;
 
-	int ret = cros_config_read_sku_info_fdt(intf, platform_arr,
-					ARRAY_SIZE(platform_arr), &sku_info);
+	int ret = cros_config_read_sku_info_fdt(intf, platform_arr, &sku_info);
 	/* If there was no error, indicate that we found a match */
 	if (!ret) {
 		intf->sku_info = &sku_info;
diff --git a/platform/octopus/octopus.c b/platform/octopus/octopus.c
index 5fd5968..b9308a6 100644
--- a/platform/octopus/octopus.c
+++ b/platform/octopus/octopus.c
@@ -60,8 +60,11 @@
 	NULL
 };
 
-static const char *platform_names = "Ampton,Bip,Bloog,Bobba,Casta,Fleex,Garg,"
-				    "Meep,Phaser,Yorp";
+static const char *platform_names[] = {
+	"Ampton", "Bip", "Bloog", "Bobba", "Casta", "Fleex", "Garg", "Meep",
+	"Phaser", "Yorp",
+	NULL
+};
 
 int octopus_probe(struct platform_intf *intf)
 {
diff --git a/platform/reef/reef.c b/platform/reef/reef.c
index ecc6ab2..58e78b8 100644
--- a/platform/reef/reef.c
+++ b/platform/reef/reef.c
@@ -120,8 +120,12 @@
 	static struct sku_info sku_info;
 	int ret;
 
-	ret = cros_config_read_sku_info(intf, "Reef,Pyro,Sand,Snappy",
-					&sku_info);
+	const char *platform_names[] = {
+		"Reef", "Pyro", "Sand", "Snappy",
+		NULL
+	};
+
+	ret = cros_config_read_sku_info(intf, platform_names, &sku_info);
 
 	/* If there was no error, indicate that we found a match */
 	if (!ret) {
@@ -171,8 +175,12 @@
 #ifdef CONFIG_CROS_CONFIG
 	static struct sku_info sku_info;
 	int ret;
+	const char *platform_names[] = {
+		"Coral",
+		NULL
+	};
 
-	ret = cros_config_read_sku_info(intf, "Coral", &sku_info);
+	ret = cros_config_read_sku_info(intf, platform_names, &sku_info);
 
 	/* If there was no error, indicate that we found a match */
 	if (!ret) {
diff --git a/platform/sarien/sarien.c b/platform/sarien/sarien.c
index e577bdb..b666d7b 100644
--- a/platform/sarien/sarien.c
+++ b/platform/sarien/sarien.c
@@ -63,7 +63,10 @@
 	NULL
 };
 
-static const char *platform_names = "Sarien,Arcada";
+static const char *platform_names[] = {
+	"Sarien", "Arcada",
+	NULL
+};
 
 int sarien_probe(struct platform_intf *intf)
 {