libpayload: fix compiler warning for first_cmos_entry()
[coreboot.git] / payloads / libpayload / drivers / options.c
index 33c06596ca7749179cb00eb4473f5bd84061fd9e..73316c1de6db86f425b69cd5d37f4aa8d36530a7 100644 (file)
@@ -57,7 +57,7 @@ struct cb_cmos_option_table *get_system_option_table(void)
        return phys_to_virt(lib_sysinfo.option_table);
 }
 
-static int options_checksum_valid(const struct nvram_accessor *nvram)
+int options_checksum_valid(const struct nvram_accessor *nvram)
 {
        int i;
        int range_start = lib_sysinfo.cmos_range_start / 8;
@@ -155,7 +155,7 @@ static int set_cmos_value(const struct nvram_accessor *nvram, u32 bitnum, u32 le
 static struct cb_cmos_entries *lookup_cmos_entry(struct cb_cmos_option_table *option_table, char *name)
 {
        struct cb_cmos_entries *cmos_entry;
-       int len = strnlen(name, CMOS_MAX_NAME_LENGTH);
+       int len = name ? strnlen(name, CMOS_MAX_NAME_LENGTH) : 0;
 
        /* cmos entries are located right after the option table */
 
@@ -171,6 +171,20 @@ static struct cb_cmos_entries *lookup_cmos_entry(struct cb_cmos_option_table *op
        return NULL;
 }
 
+struct cb_cmos_entries *first_cmos_entry(struct cb_cmos_option_table *option_table)
+{
+       return lookup_cmos_entry(option_table, NULL);
+}
+
+struct cb_cmos_entries *next_cmos_entry(struct cb_cmos_entries *cmos_entry)
+{
+       struct cb_cmos_entries *next = (struct cb_cmos_entries*)((unsigned char *)cmos_entry + cmos_entry->size);
+       if (next->tag == CB_TAG_OPTION)
+               return next;
+       else
+               return NULL;
+}
+
 /* Either value or text must be NULL. Returns the field that matches "the other" for a given config_id */
 static struct cb_cmos_enums *lookup_cmos_enum_core(struct cb_cmos_option_table *option_table, int config_id, u8 *value, char *text)
 {
@@ -278,7 +292,7 @@ int get_option_as_string(const struct nvram_accessor *nvram, struct cb_cmos_opti
                        *dest = strdup((const char*)cmos_enum->text);
                        break;
                default: /* fail */
-                       return 1;
+                       ret = 1;
        }
        free(raw);
        return ret;
@@ -295,7 +309,7 @@ int set_option_from_string(const struct nvram_accessor *nvram, struct cb_cmos_op
        switch (cmos_entry->config) {
                case 'h':
                        /* only works on little endian */
-                       raw = malloc(8);
+                       raw = malloc(sizeof(u64));
                        *(u64*)raw = strtoull(value, NULL, 0);
                        break;
                case 's':