Skip to content

Commit 4cf3cbe

Browse files
Roman ZippelLinus Torvalds
authored andcommitted
[PATCH] kconfig: allow variable argumnts for range
This allows variable arguments in the range option for int and hex config symbols. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Cc: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 9038916 commit 4cf3cbe

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

‎scripts/kconfig/menu.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
151151
menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
152152
}
153153

154+
static int menu_range_valid_sym(struct symbol *sym, struct symbol *sym2)
155+
{
156+
return sym2->type == S_INT || sym2->type == S_HEX ||
157+
(sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name));
158+
}
159+
154160
void sym_check_prop(struct symbol *sym)
155161
{
156162
struct property *prop;
@@ -185,8 +191,8 @@ void sym_check_prop(struct symbol *sym)
185191
if (sym->type != S_INT && sym->type != S_HEX)
186192
prop_warn(prop, "range is only allowed "
187193
"for int or hex symbols");
188-
if (!sym_string_valid(sym, prop->expr->left.sym->name) ||
189-
!sym_string_valid(sym, prop->expr->right.sym->name))
194+
if (!menu_range_valid_sym(sym, prop->expr->left.sym) ||
195+
!menu_range_valid_sym(sym, prop->expr->right.sym))
190196
prop_warn(prop, "range is invalid");
191197
break;
192198
default:

‎scripts/kconfig/symbol.c‎

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,55 @@ struct property *sym_get_range_prop(struct symbol *sym)
141141
return NULL;
142142
}
143143

144+
static int sym_get_range_val(struct symbol *sym, int base)
145+
{
146+
sym_calc_value(sym);
147+
switch (sym->type) {
148+
case S_INT:
149+
base = 10;
150+
break;
151+
case S_HEX:
152+
base = 16;
153+
break;
154+
default:
155+
break;
156+
}
157+
return strtol(sym->curr.val, NULL, base);
158+
}
159+
160+
static void sym_validate_range(struct symbol *sym)
161+
{
162+
struct property *prop;
163+
int base, val, val2;
164+
char str[64];
165+
166+
switch (sym->type) {
167+
case S_INT:
168+
base = 10;
169+
break;
170+
case S_HEX:
171+
base = 16;
172+
break;
173+
default:
174+
return;
175+
}
176+
prop = sym_get_range_prop(sym);
177+
if (!prop)
178+
return;
179+
val = strtol(sym->curr.val, NULL, base);
180+
val2 = sym_get_range_val(prop->expr->left.sym, base);
181+
if (val >= val2) {
182+
val2 = sym_get_range_val(prop->expr->right.sym, base);
183+
if (val <= val2)
184+
return;
185+
}
186+
if (sym->type == S_INT)
187+
sprintf(str, "%d", val2);
188+
else
189+
sprintf(str, "0x%x", val2);
190+
sym->curr.val = strdup(str);
191+
}
192+
144193
static void sym_calc_visibility(struct symbol *sym)
145194
{
146195
struct property *prop;
@@ -301,6 +350,7 @@ void sym_calc_value(struct symbol *sym)
301350
sym->curr = newval;
302351
if (sym_is_choice(sym) && newval.tri == yes)
303352
sym->curr.val = sym_calc_choice(sym);
353+
sym_validate_range(sym);
304354

305355
if (memcmp(&oldval, &sym->curr, sizeof(oldval)))
306356
sym_set_changed(sym);
@@ -489,17 +539,17 @@ bool sym_string_within_range(struct symbol *sym, const char *str)
489539
if (!prop)
490540
return true;
491541
val = strtol(str, NULL, 10);
492-
return val >= strtol(prop->expr->left.sym->name, NULL, 10) &&
493-
val <= strtol(prop->expr->right.sym->name, NULL, 10);
542+
return val >= sym_get_range_val(prop->expr->left.sym, 10) &&
543+
val <= sym_get_range_val(prop->expr->right.sym, 10);
494544
case S_HEX:
495545
if (!sym_string_valid(sym, str))
496546
return false;
497547
prop = sym_get_range_prop(sym);
498548
if (!prop)
499549
return true;
500550
val = strtol(str, NULL, 16);
501-
return val >= strtol(prop->expr->left.sym->name, NULL, 16) &&
502-
val <= strtol(prop->expr->right.sym->name, NULL, 16);
551+
return val >= sym_get_range_val(prop->expr->left.sym, 16) &&
552+
val <= sym_get_range_val(prop->expr->right.sym, 16);
503553
case S_BOOLEAN:
504554
case S_TRISTATE:
505555
switch (str[0]) {

0 commit comments

Comments
 (0)