config/powerpc-nvram: Don't require petitboot, prefix on all params
authorJeremy Kerr <jk@ozlabs.org>
Tue, 2 Jul 2013 02:36:47 +0000 (10:36 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 2 Jul 2013 03:44:20 +0000 (11:44 +0800)
Currently, we only store nvram params with a "petitboot," prefix, so
that we don't grow the config list to an unbound size. However,
the "auto-boot?" param has no prefix.

Instead, remove the requirement for the "petitboot," prefix, and use an
array of known parameters instead.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/pb-config/storage-powerpc-nvram.c

index 4e4d29ae8effccff7f2a44f0140adc676d545457..96d279c4041dc65d7a950e883d3342575de16bb2 100644 (file)
@@ -12,7 +12,6 @@
 #include "storage.h"
 
 static const char *partition = "common";
-static const char *prefix = "petitboot,";
 
 struct param {
        char                    *name;
@@ -26,12 +25,33 @@ struct powerpc_nvram_storage {
        struct list             params;
 };
 
+static const char *known_params[] = {
+       "auto-boot?",
+       "petitboot,network",
+       NULL,
+};
+
 #define to_powerpc_nvram_storage(s) \
        container_of(s, struct powerpc_nvram_storage, storage)
 
 /* a partition max a max size of 64k * 16bytes = 1M */
 static const int max_partition_size = 64 * 1024 * 16;
 
+static bool param_is_known(const char *param, unsigned int len)
+{
+       const char *known_param;
+       unsigned int i;
+
+       for (i = 0; known_params[i]; i++) {
+               known_param = known_params[i];
+               if (len == strlen(known_param) &&
+                               !strncmp(param, known_param, len))
+                       return true;
+       }
+
+       return false;
+}
+
 static int parse_nvram_params(struct powerpc_nvram_storage *nv,
                char *buf, int len)
 {
@@ -70,13 +90,10 @@ static int parse_nvram_params(struct powerpc_nvram_storage *nv,
                        continue;
 
                namelen = name - value;
-               if (namelen <= strlen(prefix))
-                       continue;
 
-               if (strncmp(name, prefix, strlen(prefix)))
+               if (!param_is_known(name, namelen))
                        continue;
 
-               name += strlen(prefix);
                value++;
 
                param = talloc(nv, struct param);
@@ -249,7 +266,7 @@ static void populate_network_config(struct powerpc_nvram_storage *nv,
        char *val;
        int i;
 
-       cval = get_param(nv, "network");
+       cval = get_param(nv, "petitboot,network");
        if (!cval || !strlen(cval))
                return;