summaryrefslogtreecommitdiff
path: root/src/drivers/pc80
diff options
context:
space:
mode:
authorAngel Pons <th3fanbus@gmail.com>2021-04-23 14:34:49 +0200
committerFelix Held <felix-coreboot@felixheld.de>2021-05-06 14:49:10 +0000
commitca5d3e3b2b81c6fd970e7dc7884d633b49648f18 (patch)
tree7e0b046397d892a2a1703fbf3eabf787b8f3e95c /src/drivers/pc80
parent88dcb3179b4b78a2376609577ae4dd4327fb59c7 (diff)
drivers/pc80/rtc/option.c: Constrain API to integer values
None of the options accessed within coreboot is a string, and there are no guarantees that the code works as intended with them. Given that the current option API only supports integers for now, do not try to access options whose type is 's' (string). Change-Id: Ib67b126d972c6d55b77ea5ecfb862b4e9c766fe5 Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/52637 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Patrick Rudolph <siro@das-labor.org>
Diffstat (limited to 'src/drivers/pc80')
-rw-r--r--src/drivers/pc80/rtc/option.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/drivers/pc80/rtc/option.c b/src/drivers/pc80/rtc/option.c
index 5cc5ea558e..cc4138bfd7 100644
--- a/src/drivers/pc80/rtc/option.c
+++ b/src/drivers/pc80/rtc/option.c
@@ -84,7 +84,7 @@ static struct cmos_entries *find_cmos_entry(struct cmos_option_table *ct, const
return NULL;
}
-enum cb_err cmos_get_option(void *dest, const char *name)
+enum cb_err cmos_get_uint_option(unsigned int *dest, const char *name)
{
struct cmos_option_table *ct;
struct cmos_entries *ce;
@@ -99,6 +99,11 @@ enum cb_err cmos_get_option(void *dest, const char *name)
return CB_CMOS_OPTION_NOT_FOUND;
}
+ if (ce->config != 'e' && ce->config != 'h') {
+ printk(BIOS_ERR, "ERROR: CMOS option '%s' is not of integer type.\n", name);
+ return CB_ERR_ARG;
+ }
+
if (!cmos_checksum_valid(LB_CKS_RANGE_START, LB_CKS_RANGE_END, LB_CKS_LOC))
return CB_CMOS_CHECKSUM_INVALID;
@@ -149,11 +154,10 @@ static enum cb_err set_cmos_value(unsigned long bit, unsigned long length,
return CB_SUCCESS;
}
-enum cb_err cmos_set_option(const char *name, void *value)
+enum cb_err cmos_set_uint_option(const char *name, unsigned int *value)
{
struct cmos_option_table *ct;
struct cmos_entries *ce;
- unsigned long length;
ct = get_cmos_layout();
if (!ct)
@@ -165,16 +169,12 @@ enum cb_err cmos_set_option(const char *name, void *value)
return CB_CMOS_OPTION_NOT_FOUND;
}
- length = ce->length;
- if (ce->config == 's') {
- length = MAX(strlen((const char *)value) * 8, ce->length - 8);
- /* make sure the string is null terminated */
- if (set_cmos_value(ce->bit + ce->length - 8, 8, &(u8[]){0})
- != CB_SUCCESS)
- return CB_CMOS_ACCESS_ERROR;
+ if (ce->config != 'e' && ce->config != 'h') {
+ printk(BIOS_ERR, "ERROR: CMOS option '%s' is not of integer type.\n", name);
+ return CB_ERR_ARG;
}
- if (set_cmos_value(ce->bit, length, value) != CB_SUCCESS)
+ if (set_cmos_value(ce->bit, ce->length, value) != CB_SUCCESS)
return CB_CMOS_ACCESS_ERROR;
return CB_SUCCESS;