On Fri, 18 Oct 2019 18:07:26 +0200
Jiri Pirko <[email protected]> wrote:
> +static bool devlink_param_valid_name(const char *name)
> +{
> + int len = strlen(name);
> + int i;
> +
> + /* Name can contain lowercase characters or digits.
> + * Underscores are also allowed, but not at the beginning
> + * or end of the name and not more than one in a row.
> + */
> +
> + for (i = 0; i < len; i++) {
> + if (islower(name[i]) || isdigit(name[i]))
> + continue;
> + if (name[i] != '_')
> + return false;
> + if (i == 0 || i + 1 == len)
> + return false;
> + if (name[i - 1] == '_')
> + return false;
> + }
> + return true;
> +}
You might want to also impose a maximum length on name,
and not allow slash in name (if you ever plan to use sysfs).