linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Baron <jbaron@redhat.com>
To: greg@kroah.com
Cc: jim.cromie@gmail.com, joe@perches.com, bart.vanassche@gmail.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH 09/16] dynamic_debug: tighten up error checking on debug queries
Date: Mon, 19 Dec 2011 17:12:49 -0500	[thread overview]
Message-ID: <01b746c156837251ab3977029d2252844c39d306.1324318997.git.jbaron@redhat.com> (raw)
In-Reply-To: <cover.1324318997.git.jbaron@redhat.com>

From: Jim Cromie <jim.cromie@gmail.com>

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>
---
 lib/dynamic_debug.c |   39 +++++++++++++++++++++++++++++++++------
 1 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index cde4dfe..5a7bacc 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -276,6 +276,19 @@ static char *unescape(char *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
  * of (keyword, value) pairs chosen from these possibilities:
@@ -287,11 +300,15 @@ static char *unescape(char *str)
  * format <escaped-string-to-find-in-format>
  * line <lineno>
  * 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,
 			       struct ddebug_query *query)
 {
 	unsigned int i;
+	int rc;
 
 	/* check we have an even number of words */
 	if (nwords % 2 != 0)
@@ -300,24 +317,32 @@ static int ddebug_parse_query(char *words[], int nwords,
 
 	for (i = 0 ; i < nwords ; i += 2) {
 		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"))
-			query->filename = words[i+1];
+			rc = check_set(&query->filename, words[i+1], "file");
 		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"))
-			query->format = unescape(words[i+1]);
+			rc = check_set(&query->format, unescape(words[i+1]),
+				"format");
 		else if (!strcmp(words[i], "line")) {
 			char *first = words[i+1];
 			char *last = strchr(first, '-');
+			if (query->first_lineno || query->last_lineno) {
+				pr_err("match-spec:line given 2 times\n");
+				return -EINVAL;
+			}
 			if (last)
 				*last++ = '\0';
 			if (parse_lineno(first, &query->first_lineno) < 0)
 				return -EINVAL;
-			if (last != NULL) {
+			if (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;
+				}
 			} else {
 				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]);
 			return -EINVAL;
 		}
+		if (rc)
+			return rc;
 	}
 
 	if (verbose)
-- 
1.7.7.3


  parent reply	other threads:[~2011-12-19 22:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-19 22:11 [PATCH 00/16] dynamic debug: ehancements and cleanups Jason Baron
2011-12-19 22:11 ` [PATCH 01/16] dynamic_debug: fix whitespace complaints from scripts/cleanfile Jason Baron
2011-12-19 22:11 ` [PATCH 02/16] dynamic_debug: drop enabled field from struct _ddebug, use _DPRINTK_FLAGS_PRINT Jason Baron
2011-12-19 22:11 ` [PATCH 03/16] dynamic_debug: make dynamic-debug supersede DEBUG ccflag Jason Baron
2011-12-19 22:12 ` [PATCH 04/16] dynamic_debug: change verbosity at runtime Jason Baron
2011-12-19 22:12 ` [PATCH 05/16] dynamic_debug: replace strcpy with strlcpy, in ddebug_setup_query() Jason Baron
2011-12-20  8:08   ` Bart Van Assche
2011-12-21 21:30     ` Jason Baron
2011-12-19 22:12 ` [PATCH 06/16] dynamic_debug: pr_err() call should not depend upon verbosity Jason Baron
2011-12-19 22:12 ` [PATCH 07/16] dynamic_debug: drop explicit !=NULL checks Jason Baron
2011-12-19 22:12 ` [PATCH 08/16] dynamic_debug: describe_flags with '=[pmflt_]*' Jason Baron
2011-12-19 22:12 ` Jason Baron [this message]
2011-12-19 22:12 ` [PATCH 10/16] dynamic_debug: early return if _ddebug table is empty Jason Baron
2011-12-19 22:12 ` [PATCH 11/16] dynamic_debug: reduce lineno field to a saner 18 bits Jason Baron
2011-12-19 22:13 ` [PATCH 12/16] dynamic_debug: chop off comments in ddebug_tokenize Jason Baron
2011-12-19 22:13 ` [PATCH 13/16] dynamic_debug: enlarge command/query write buffer Jason Baron
2011-12-19 22:13 ` [PATCH 14/16] dynamic_debug: add trim_prefix() to provide source-root relative paths Jason Baron
2011-12-20  8:15   ` Bart Van Assche
2011-12-21 21:32     ` Jason Baron
2011-12-19 22:13 ` [PATCH 15/16] dynamic_debug: factor vpr_info_dq out of ddebug_parse_query Jason Baron
2011-12-20  8:17   ` Bart Van Assche
2011-12-20 15:47     ` Jim Cromie
2011-12-20 15:49       ` Bart Van Assche
2011-12-21 21:33         ` Jason Baron
2012-01-24 20:50           ` Greg KH
2011-12-19 22:13 ` [PATCH 16/16] dynamic_debug: process multiple debug-queries on a line Jason Baron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01b746c156837251ab3977029d2252844c39d306.1324318997.git.jbaron@redhat.com \
    --to=jbaron@redhat.com \
    --cc=bart.vanassche@gmail.com \
    --cc=greg@kroah.com \
    --cc=jim.cromie@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).