return -ENOENT;
}
-static int strtobool(const char *str, bool *p_val)
-{
- bool val;
-
- if (!strcmp(str, "true") || !strcmp(str, "1") ||
- !strcmp(str, "enable"))
- val = true;
- else if (!strcmp(str, "false") || !strcmp(str, "0") ||
- !strcmp(str, "disable"))
- val = false;
- else
- return -EINVAL;
- *p_val = val;
- return 0;
-}
-
static int ident_str_validate(char *str, unsigned int expected)
{
if (!str)
return -EINVAL;
}
- err = strtobool(str, p_val);
+ err = str_to_bool(str, p_val);
if (err) {
pr_err("\"%s\" is not a valid boolean value\n", str);
return err;
mnl_attr_put_u64(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, val_u64);
break;
case MNL_TYPE_FLAG:
- err = strtobool(dl->opts.param_value, &val_bool);
+ err = str_to_bool(dl->opts.param_value, &val_bool);
if (err)
goto err_param_value_parse;
if (val_bool == ctx.value.vbool)
mnl_attr_put_u64(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, val_u64);
break;
case MNL_TYPE_FLAG:
- err = strtobool(dl->opts.param_value, &val_bool);
+ err = str_to_bool(dl->opts.param_value, &val_bool);
if (err)
goto err_param_value_parse;
if (val_bool == ctx.value.vbool)
const char * const *list,
size_t len, int *p_err);
bool parse_on_off(const char *msg, const char *realval, int *p_err);
+int str_to_bool(const char *str, bool *p_val);
int parse_mapping_num_all(__u32 *keyp, const char *key);
int parse_mapping_gen(int *argcp, char ***argvp,
ARRAY_SIZE(values_on_off), p_err, strcmp);
}
+int str_to_bool(const char *str, bool *p_val)
+{
+ static const char * const values[] = {
+ "false", "true",
+ "0", "1",
+ "disable", "enable"
+ };
+ int err, index;
+
+ index = parse_one_of(NULL, str, values, ARRAY_SIZE(values), &err);
+ if (err)
+ return err;
+
+ *p_val = index & 1;
+ return 0;
+}
+
int parse_mapping_gen(int *argcp, char ***argvp,
int (*key_cb)(__u32 *keyp, const char *key),
int (*mapping_cb)(__u32 key, char *value, void *data),