diff options
author | Jim Cromie <jim.cromie@gmail.com> | 2012-12-05 16:48:27 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-17 15:19:09 -0500 |
commit | 18c216c53b29f15b17c4c05a46395fc90ebb6f0c (patch) | |
tree | 0f01e8fd2346ec6c82eaace95e6831440bc39a03 /lib | |
parent | 7a555613eb77c69eb6e48b61bc5f72dd42fa1780 (diff) |
dynamic_debug: add pr_errs before -EINVALs
Ma noted that dynamic-debug is silent about many query errors, so add
pr_err()s to explain those errors, and tweak a few others. Also parse
flags 1st, so that match-spec errs are slightly clearer.
CC: Jianpeng Ma <majianpeng@gmail.com>
CC: Joe Perches <joe@perches.com>
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dynamic_debug.c | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index ac7d27737e42..5276b99ca650 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -223,8 +223,10 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords) | |||
223 | int quote = *buf++; | 223 | int quote = *buf++; |
224 | for (end = buf; *end && *end != quote; end++) | 224 | for (end = buf; *end && *end != quote; end++) |
225 | ; | 225 | ; |
226 | if (!*end) | 226 | if (!*end) { |
227 | pr_err("unclosed quote: %s\n", buf); | ||
227 | return -EINVAL; /* unclosed quote */ | 228 | return -EINVAL; /* unclosed quote */ |
229 | } | ||
228 | } else { | 230 | } else { |
229 | for (end = buf; *end && !isspace(*end); end++) | 231 | for (end = buf; *end && !isspace(*end); end++) |
230 | ; | 232 | ; |
@@ -232,8 +234,10 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords) | |||
232 | } | 234 | } |
233 | 235 | ||
234 | /* `buf' is start of word, `end' is one past its end */ | 236 | /* `buf' is start of word, `end' is one past its end */ |
235 | if (nwords == maxwords) | 237 | if (nwords == maxwords) { |
238 | pr_err("too many words, legal max <=%d\n", maxwords); | ||
236 | return -EINVAL; /* ran out of words[] before bytes */ | 239 | return -EINVAL; /* ran out of words[] before bytes */ |
240 | } | ||
237 | if (*end) | 241 | if (*end) |
238 | *end++ = '\0'; /* terminate the word */ | 242 | *end++ = '\0'; /* terminate the word */ |
239 | words[nwords++] = buf; | 243 | words[nwords++] = buf; |
@@ -265,7 +269,11 @@ static inline int parse_lineno(const char *str, unsigned int *val) | |||
265 | return 0; | 269 | return 0; |
266 | } | 270 | } |
267 | *val = simple_strtoul(str, &end, 10); | 271 | *val = simple_strtoul(str, &end, 10); |
268 | return end == NULL || end == str || *end != '\0' ? -EINVAL : 0; | 272 | if (end == NULL || end == str || *end != '\0') { |
273 | pr_err("bad line-number: %s\n", str); | ||
274 | return -EINVAL; | ||
275 | } | ||
276 | return 0; | ||
269 | } | 277 | } |
270 | 278 | ||
271 | /* | 279 | /* |
@@ -345,8 +353,10 @@ static int ddebug_parse_query(char *words[], int nwords, | |||
345 | int rc; | 353 | int rc; |
346 | 354 | ||
347 | /* check we have an even number of words */ | 355 | /* check we have an even number of words */ |
348 | if (nwords % 2 != 0) | 356 | if (nwords % 2 != 0) { |
357 | pr_err("expecting pairs of match-spec <value>\n"); | ||
349 | return -EINVAL; | 358 | return -EINVAL; |
359 | } | ||
350 | memset(query, 0, sizeof(*query)); | 360 | memset(query, 0, sizeof(*query)); |
351 | 361 | ||
352 | if (modname) | 362 | if (modname) |
@@ -367,18 +377,22 @@ static int ddebug_parse_query(char *words[], int nwords, | |||
367 | char *first = words[i+1]; | 377 | char *first = words[i+1]; |
368 | char *last = strchr(first, '-'); | 378 | char *last = strchr(first, '-'); |
369 | if (query->first_lineno || query->last_lineno) { | 379 | if (query->first_lineno || query->last_lineno) { |
370 | pr_err("match-spec:line given 2 times\n"); | 380 | pr_err("match-spec: line used 2x\n"); |
371 | return -EINVAL; | 381 | return -EINVAL; |
372 | } | 382 | } |
373 | if (last) | 383 | if (last) |
374 | *last++ = '\0'; | 384 | *last++ = '\0'; |
375 | if (parse_lineno(first, &query->first_lineno) < 0) | 385 | if (parse_lineno(first, &query->first_lineno) < 0) { |
386 | pr_err("line-number is <0\n"); | ||
376 | return -EINVAL; | 387 | return -EINVAL; |
388 | } | ||
377 | if (last) { | 389 | if (last) { |
378 | /* range <first>-<last> */ | 390 | /* range <first>-<last> */ |
379 | if (parse_lineno(last, &query->last_lineno) | 391 | if (parse_lineno(last, &query->last_lineno) |
380 | < query->first_lineno) { | 392 | < query->first_lineno) { |
381 | pr_err("last-line < 1st-line\n"); | 393 | pr_err("last-line:%d < 1st-line:%d\n", |
394 | query->last_lineno, | ||
395 | query->first_lineno); | ||
382 | return -EINVAL; | 396 | return -EINVAL; |
383 | } | 397 | } |
384 | } else { | 398 | } else { |
@@ -414,6 +428,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp, | |||
414 | op = *str++; | 428 | op = *str++; |
415 | break; | 429 | break; |
416 | default: | 430 | default: |
431 | pr_err("bad flag-op %c, at start of %s\n", *str, str); | ||
417 | return -EINVAL; | 432 | return -EINVAL; |
418 | } | 433 | } |
419 | vpr_info("op='%c'\n", op); | 434 | vpr_info("op='%c'\n", op); |
@@ -425,8 +440,10 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp, | |||
425 | break; | 440 | break; |
426 | } | 441 | } |
427 | } | 442 | } |
428 | if (i < 0) | 443 | if (i < 0) { |
444 | pr_err("unknown flag '%c' in \"%s\"\n", *str, str); | ||
429 | return -EINVAL; | 445 | return -EINVAL; |
446 | } | ||
430 | } | 447 | } |
431 | vpr_info("flags=0x%x\n", flags); | 448 | vpr_info("flags=0x%x\n", flags); |
432 | 449 | ||
@@ -458,13 +475,19 @@ static int ddebug_exec_query(char *query_string, const char *modname) | |||
458 | char *words[MAXWORDS]; | 475 | char *words[MAXWORDS]; |
459 | 476 | ||
460 | nwords = ddebug_tokenize(query_string, words, MAXWORDS); | 477 | nwords = ddebug_tokenize(query_string, words, MAXWORDS); |
461 | if (nwords <= 0) | 478 | if (nwords <= 0) { |
479 | pr_err("tokenize failed\n"); | ||
462 | return -EINVAL; | 480 | return -EINVAL; |
463 | if (ddebug_parse_query(words, nwords-1, &query, modname)) | 481 | } |
482 | /* check flags 1st (last arg) so query is pairs of spec,val */ | ||
483 | if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) { | ||
484 | pr_err("flags parse failed\n"); | ||
464 | return -EINVAL; | 485 | return -EINVAL; |
465 | if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) | 486 | } |
487 | if (ddebug_parse_query(words, nwords-1, &query, modname)) { | ||
488 | pr_err("query parse failed\n"); | ||
466 | return -EINVAL; | 489 | return -EINVAL; |
467 | 490 | } | |
468 | /* actually go and implement the change */ | 491 | /* actually go and implement the change */ |
469 | nfound = ddebug_change(&query, flags, mask); | 492 | nfound = ddebug_change(&query, flags, mask); |
470 | vpr_info_dq(&query, nfound ? "applied" : "no-match"); | 493 | vpr_info_dq(&query, nfound ? "applied" : "no-match"); |