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>
This commit is contained in:
parent
88dcb3179b
commit
ca5d3e3b2b
|
@ -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;
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
|
||||
void sanitize_cmos(void);
|
||||
|
||||
enum cb_err cmos_set_option(const char *name, void *val);
|
||||
enum cb_err cmos_get_option(void *dest, const char *name);
|
||||
enum cb_err cmos_set_uint_option(const char *name, unsigned int *value);
|
||||
enum cb_err cmos_get_uint_option(unsigned int *dest, const char *name);
|
||||
|
||||
static inline enum cb_err set_uint_option(const char *name, unsigned int value)
|
||||
{
|
||||
if (CONFIG(USE_OPTION_TABLE))
|
||||
return cmos_set_option(name, &value);
|
||||
return cmos_set_uint_option(name, &value);
|
||||
|
||||
return CB_CMOS_OTABLE_DISABLED;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ static inline int get_uint_option(const char *name, const unsigned int fallback)
|
|||
{
|
||||
if (CONFIG(USE_OPTION_TABLE)) {
|
||||
unsigned int value = 0;
|
||||
if (cmos_get_option(&value, name) == CB_SUCCESS)
|
||||
if (cmos_get_uint_option(&value, name) == CB_SUCCESS)
|
||||
return value;
|
||||
}
|
||||
return fallback;
|
||||
|
|
Loading…
Reference in New Issue