mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 18:52:02 +00:00
dynamic_debug: tighten up error checking on debug queries
Issue error when a match-spec is given multiple times in a rule. Previous code kept last one, but was silent about it. Docs imply only one is allowed by saying match-specs are ANDed together, given that module M cannot match both A and B. Also error when last_line < 1st_line. Signed-off-by: Jim Cromie <jim.cromie@gmail.com> Signed-off-by: Jason Baron <jbaron@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
5ca7d2a6c5
commit
820874c75e
@ -276,6 +276,19 @@ static char *unescape(char *str)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int check_set(const char **dest, char *src, char *name)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (*dest) {
|
||||||
|
rc = -EINVAL;
|
||||||
|
pr_err("match-spec:%s val:%s overridden by %s",
|
||||||
|
name, *dest, src);
|
||||||
|
}
|
||||||
|
*dest = src;
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse words[] as a ddebug query specification, which is a series
|
* Parse words[] as a ddebug query specification, which is a series
|
||||||
* of (keyword, value) pairs chosen from these possibilities:
|
* of (keyword, value) pairs chosen from these possibilities:
|
||||||
@ -287,11 +300,15 @@ static char *unescape(char *str)
|
|||||||
* format <escaped-string-to-find-in-format>
|
* format <escaped-string-to-find-in-format>
|
||||||
* line <lineno>
|
* line <lineno>
|
||||||
* line <first-lineno>-<last-lineno> // where either may be empty
|
* line <first-lineno>-<last-lineno> // where either may be empty
|
||||||
|
*
|
||||||
|
* Only 1 of each type is allowed.
|
||||||
|
* Returns 0 on success, <0 on error.
|
||||||
*/
|
*/
|
||||||
static int ddebug_parse_query(char *words[], int nwords,
|
static int ddebug_parse_query(char *words[], int nwords,
|
||||||
struct ddebug_query *query)
|
struct ddebug_query *query)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* check we have an even number of words */
|
/* check we have an even number of words */
|
||||||
if (nwords % 2 != 0)
|
if (nwords % 2 != 0)
|
||||||
@ -300,24 +317,32 @@ static int ddebug_parse_query(char *words[], int nwords,
|
|||||||
|
|
||||||
for (i = 0 ; i < nwords ; i += 2) {
|
for (i = 0 ; i < nwords ; i += 2) {
|
||||||
if (!strcmp(words[i], "func"))
|
if (!strcmp(words[i], "func"))
|
||||||
query->function = words[i+1];
|
rc = check_set(&query->function, words[i+1], "func");
|
||||||
else if (!strcmp(words[i], "file"))
|
else if (!strcmp(words[i], "file"))
|
||||||
query->filename = words[i+1];
|
rc = check_set(&query->filename, words[i+1], "file");
|
||||||
else if (!strcmp(words[i], "module"))
|
else if (!strcmp(words[i], "module"))
|
||||||
query->module = words[i+1];
|
rc = check_set(&query->module, words[i+1], "module");
|
||||||
else if (!strcmp(words[i], "format"))
|
else if (!strcmp(words[i], "format"))
|
||||||
query->format = unescape(words[i+1]);
|
rc = check_set(&query->format, unescape(words[i+1]),
|
||||||
|
"format");
|
||||||
else if (!strcmp(words[i], "line")) {
|
else if (!strcmp(words[i], "line")) {
|
||||||
char *first = words[i+1];
|
char *first = words[i+1];
|
||||||
char *last = strchr(first, '-');
|
char *last = strchr(first, '-');
|
||||||
|
if (query->first_lineno || query->last_lineno) {
|
||||||
|
pr_err("match-spec:line given 2 times\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
if (last)
|
if (last)
|
||||||
*last++ = '\0';
|
*last++ = '\0';
|
||||||
if (parse_lineno(first, &query->first_lineno) < 0)
|
if (parse_lineno(first, &query->first_lineno) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (last != NULL) {
|
if (last) {
|
||||||
/* range <first>-<last> */
|
/* range <first>-<last> */
|
||||||
if (parse_lineno(last, &query->last_lineno) < 0)
|
if (parse_lineno(last, &query->last_lineno)
|
||||||
|
< query->first_lineno) {
|
||||||
|
pr_err("last-line < 1st-line\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
query->last_lineno = query->first_lineno;
|
query->last_lineno = query->first_lineno;
|
||||||
}
|
}
|
||||||
@ -325,6 +350,8 @@ static int ddebug_parse_query(char *words[], int nwords,
|
|||||||
pr_err("unknown keyword \"%s\"\n", words[i]);
|
pr_err("unknown keyword \"%s\"\n", words[i]);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
|
Loading…
Reference in New Issue
Block a user