summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorAngel Pons <th3fanbus@gmail.com>2021-04-23 12:58:42 +0200
committerNico Huber <nico.h@gmx.de>2021-04-25 11:43:50 +0000
commit109a9ec339c6c3adc1a3714be46178db13cb8f18 (patch)
tree1f592c3d487bd6ba5699d5d43a71ef4f25edc2c8 /src/drivers
parent08f08c9fa4c127bda6ec1ac7f6f3d523d1983abe (diff)
drivers/pc80/rtc: Factor out CMOS entry lookup
The procedure is identical for reads and writes. Factor it out. Change-Id: I22b1d334270881734b34312f1fee01aa110a6db4 Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/52636 Reviewed-by: Patrick Rudolph <siro@das-labor.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/pc80/rtc/option.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/src/drivers/pc80/rtc/option.c b/src/drivers/pc80/rtc/option.c
index 409f0efb3b..5cc5ea558e 100644
--- a/src/drivers/pc80/rtc/option.c
+++ b/src/drivers/pc80/rtc/option.c
@@ -68,30 +68,33 @@ static struct cmos_option_table *get_cmos_layout(void)
return ct;
}
+static struct cmos_entries *find_cmos_entry(struct cmos_option_table *ct, const char *name)
+{
+ /* Figure out how long name is */
+ const size_t namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
+ struct cmos_entries *ce;
+
+ /* Find the requested entry record */
+ ce = (struct cmos_entries *)((unsigned char *)ct + ct->header_length);
+ for (; ce->tag == LB_TAG_OPTION;
+ ce = (struct cmos_entries *)((unsigned char *)ce + ce->size)) {
+ if (memcmp(ce->name, name, namelen) == 0)
+ return ce;
+ }
+ return NULL;
+}
+
enum cb_err cmos_get_option(void *dest, const char *name)
{
struct cmos_option_table *ct;
struct cmos_entries *ce;
- size_t namelen;
- int found = 0;
-
- /* Figure out how long name is */
- namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
ct = get_cmos_layout();
if (!ct)
return CB_CMOS_LAYOUT_NOT_FOUND;
- /* find the requested entry record */
- ce = (struct cmos_entries *)((unsigned char *)ct + ct->header_length);
- for (; ce->tag == LB_TAG_OPTION;
- ce = (struct cmos_entries *)((unsigned char *)ce + ce->size)) {
- if (memcmp(ce->name, name, namelen) == 0) {
- found = 1;
- break;
- }
- }
- if (!found) {
+ ce = find_cmos_entry(ct, name);
+ if (!ce) {
printk(BIOS_DEBUG, "No CMOS option '%s'.\n", name);
return CB_CMOS_OPTION_NOT_FOUND;
}
@@ -151,26 +154,13 @@ enum cb_err cmos_set_option(const char *name, void *value)
struct cmos_option_table *ct;
struct cmos_entries *ce;
unsigned long length;
- size_t namelen;
- int found = 0;
-
- /* Figure out how long name is */
- namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
ct = get_cmos_layout();
if (!ct)
return CB_CMOS_LAYOUT_NOT_FOUND;
- /* find the requested entry record */
- ce = (struct cmos_entries *)((unsigned char *)ct + ct->header_length);
- for (; ce->tag == LB_TAG_OPTION;
- ce = (struct cmos_entries *)((unsigned char *)ce + ce->size)) {
- if (memcmp(ce->name, name, namelen) == 0) {
- found = 1;
- break;
- }
- }
- if (!found) {
+ ce = find_cmos_entry(ct, name);
+ if (!ce) {
printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
return CB_CMOS_OPTION_NOT_FOUND;
}