MCPcopy Create free account
hub / github.com/coreboot/coreboot / prepare_cmos_write

Function prepare_cmos_write

util/nvramtool/cmos_ops.c:64–137  ·  view source on GitHub ↗

* prepare_cmos_write * * The caller wishes to set a CMOS parameter represented by 'e' to a value * whose string representation is stored in 'value_str'. Perform sanity * checking on 'value_str'. On error, return an error code. Else store the * numeric equivalent of 'value_str' in '*value' and return OK. ****************************************************************************/

Source from the content-addressed store, hash-verified

62 * numeric equivalent of 'value_str' in '*value' and return OK.
63 ****************************************************************************/
64int prepare_cmos_write(const cmos_entry_t * e, const char value_str[],
65 unsigned long long *value)
66{
67 const cmos_enum_t *q;
68 unsigned long long out;
69 const char *p;
70 char *memory = NULL;
71 int negative, result, found_one;
72
73 if ((result = prepare_cmos_op_common(e)) != OK)
74 return result;
75
76 switch (e->config) {
77 case CMOS_ENTRY_ENUM:
78 /* Make sure the user's input corresponds to a valid option. */
79 for (q = first_cmos_enum_id(e->config_id), found_one = 0;
80 q != NULL; q = next_cmos_enum_id(q)) {
81 found_one = 1;
82
83 if (!strncmp(q->text, value_str, CMOS_MAX_TEXT_LENGTH))
84 break;
85 }
86
87 if (!found_one)
88 return CMOS_OP_NO_MATCHING_ENUM;
89
90 if (q == NULL)
91 return CMOS_OP_BAD_ENUM_VALUE;
92
93 out = q->value;
94 break;
95
96 case CMOS_ENTRY_HEX:
97 /* See if the first character of 'value_str' (excluding
98 * any initial whitespace) is a minus sign.
99 */
100 for (p = value_str; isspace((int)(unsigned char)*p); p++) ;
101 negative = (*p == '-');
102
103 out = strtoull(value_str, (char **)&p, 0);
104
105 if (*p)
106 return CMOS_OP_INVALID_INT;
107
108 /* If we get this far, the user specified a valid integer.
109 * However we do not currently support the use of negative
110 * numbers as CMOS parameter values.
111 */
112 if (negative)
113 return CMOS_OP_NEGATIVE_INT;
114
115 break;
116
117 case CMOS_ENTRY_STRING:
118 if (e->length < (8 * strlen(value_str)))
119 return CMOS_OP_VALUE_TOO_WIDE;
120 memory = malloc(e->length / 8);
121 memset(memory, 0, e->length / 8);

Callers 2

try_prepare_cmos_writeFunction · 0.85
set_one_paramFunction · 0.85

Calls 11

prepare_cmos_op_commonFunction · 0.85
first_cmos_enum_idFunction · 0.85
next_cmos_enum_idFunction · 0.85
strlenFunction · 0.85
strncmpFunction · 0.50
isspaceFunction · 0.50
strtoullFunction · 0.50
mallocFunction · 0.50
memsetFunction · 0.50
strcpyFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected