mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@redhat.com
Cc: bvanassche@acm.org, joe@perches.com, gregkh@suse.de,
	linux-kernel@vger.kernel.org, gnb@fmeh.org,
	Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH 21/25] dynamic_debug: shrink struct pending query to size actually needed
Date: Mon, 25 Jul 2011 15:42:46 -0600	[thread overview]
Message-ID: <1311630170-26057-22-git-send-email-jim.cromie@gmail.com> (raw)
In-Reply-To: <1311630170-26057-1-git-send-email-jim.cromie@gmail.com>

Remove struct pending_query's fixed sized char arrays; function,
filename, module, format, and replace them with a 0-sized charbuf.
Before the struct is allocd, determine the size needed to store
the 4 strings into the charbuf.  Then copy the strings off the stack,
and update the field ptrs in the embedded struct ddebug_query to point
into the charbuf.  This change uses strcpy instead of strlcpy, since
we know that the charbuf is big enough to hold the 4 strings.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 lib/dynamic_debug.c |   37 ++++++++++++++++++++++---------------
 1 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 8f56092..5ec8165 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -56,11 +56,8 @@ struct ddebug_query {
 struct pending_query {
 	struct list_head link;
 	struct ddebug_query query;
-	char filename[100];
-	char module[30];
-	char function[50];
-	char format[200];
 	unsigned int flags, mask;
+	char buf[0];
 };
 
 struct ddebug_iter {
@@ -507,7 +504,8 @@ static int ddebug_save_pending(struct ddebug_query *query,
 				unsigned int flags, unsigned int mask)
 {
 	struct pending_query *pq, *pqnext;
-	char *qstr;
+	char *qstr, *bp;
+	size_t buflen;
 
 	list_for_each_entry_safe(pq, pqnext, &pending_queries, link) {
 		if (queries_match(query, &pq->query)) {
@@ -537,26 +535,33 @@ static int ddebug_save_pending(struct ddebug_query *query,
 	pr_debug("add to pending: %s\n", qstr);
 	kfree(qstr);
 
-	pq = kzalloc(sizeof(struct pending_query), GFP_KERNEL);
+	buflen = (query->module ? strlen(query->module) : 0)
+		+ (query->function ? strlen(query->function) : 0)
+		+ (query->filename ? strlen(query->filename) : 0)
+		+ (query->format ? strlen(query->format) : 0)
+		+ 4; /* for \0's */
+
+	pq = kzalloc(sizeof(struct pending_query) + buflen, GFP_KERNEL);
 	if (pq == NULL)
 		return -ENOMEM;
 
 	/* copy non-null match-specs into allocd mem, update pointers */
+	bp = pq->buf;
 	if (query->module) {
-		strlcpy(pq->module, query->module, sizeof(pq->module));
-		pq->query.module = pq->module;
+		pq->query.module = strcpy(bp, query->module);
+		bp += strlen(bp) + 1;
 	}
 	if (query->function) {
-		strlcpy(pq->function, query->function, sizeof(pq->function));
-		pq->query.function = pq->function;
+		pq->query.function = strcpy(bp, query->function);
+		bp += strlen(bp) + 1;
 	}
 	if (query->filename) {
-		strlcpy(pq->filename, query->filename, sizeof(pq->filename));
-		pq->query.filename = pq->filename;
+		pq->query.filename = strcpy(bp, query->filename);
+		bp += strlen(bp) + 1;
 	}
 	if (query->format) {
-		strlcpy(pq->format, query->format, sizeof(pq->format));
-		pq->query.format = pq->format;
+		pq->query.format = strcpy(bp, query->format);
+		bp += strlen(bp) + 1;
 	}
 	pq->flags = flags;
 	pq->mask = mask;
@@ -564,7 +569,9 @@ static int ddebug_save_pending(struct ddebug_query *query,
 	list_add(&pq->link, &pending_queries);
 	pending_ct++;
 
-	pr_debug("query saved as pending %d\n", pending_ct);
+	pr_debug("query saved as pending %d, in %d+%d bytes\n",
+		pending_ct, sizeof(struct pending_query), buflen);
+
 	return 0;
 }
 
-- 
1.7.4.1


  parent reply	other threads:[~2011-07-25 21:45 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-25 21:42 [patch 00/25] dynamic_debug: multiple, pending queries in boot-arg Jim Cromie
2011-07-25 21:42 ` [PATCH 01/25] dynamic_debug: add pending flag 'a' to make pending queries explicit Jim Cromie
2011-07-25 21:42 ` [PATCH 02/25] dynamic_debug: change verbosity at runtime Jim Cromie
2011-07-25 21:42 ` [PATCH 03/25] dynamic_debug: use pr_debug instead of pr_info Jim Cromie
2011-07-26  7:08   ` Bart Van Assche
2011-07-27 21:34     ` Jim Cromie
2011-07-28  9:18       ` Bart Van Assche
2011-07-28 18:24         ` Jason Baron
2011-07-28 21:15           ` Jim Cromie
2011-08-03 18:27             ` Jason Baron
2011-08-03 19:52               ` Jim Cromie
2011-08-10 17:14                 ` Jason Baron
2011-08-10 19:28                   ` Jim Cromie
2011-07-25 21:42 ` [PATCH 04/25] dynamic_debug: replace strcpy with strlcpy, in ddebug_setup_query() Jim Cromie
2011-07-25 21:42 ` [PATCH 05/25] dynamic_debug: trim source-path prefix from dynamic_debug/control Jim Cromie
2011-07-25 21:42 ` [PATCH 06/25] dynamic_debug: process multiple commands on a line Jim Cromie
2011-07-25 21:42 ` [PATCH 07/25] dynamic_debug: enlarge command/query write buffer Jim Cromie
2011-07-25 21:42 ` [PATCH 08/25] dynamic_debug: warn when >1 of each type of match-spec is given Jim Cromie
2011-07-25 21:42 ` [PATCH 09/25] dynamic_debug: pr_err() call should not depend upon verbosity Jim Cromie
2011-07-25 21:42 ` [PATCH 10/25] dynamic_debug: dont kill entire facility on error parsing ddebug_query Jim Cromie
2011-07-25 21:42 ` [PATCH 11/25] dynamic_debug: factor show_ddebug_query out of ddebug_parse_query Jim Cromie
2011-07-26  7:13   ` Bart Van Assche
2011-07-26  7:15   ` Bart Van Assche
2011-07-26 16:21     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 12/25] dynamic_debug: save non-matching queries to pending-list for later application Jim Cromie
2011-07-25 21:42 ` [PATCH 13/25] dynamic_debug: apply_pending_queries() from ddebug_add_module() Jim Cromie
2011-07-25 21:42 ` [PATCH 14/25] dynamic_debug: refactor query_matches_callsite out of ddebug_change Jim Cromie
2011-07-25 21:42 ` [PATCH 15/25] dynamic_debug: remove explicit foo != NULL checks Jim Cromie
2011-07-25 21:42 ` [PATCH 16/25] dynamic_debug: require 'a' flag to explicitly mark pending queries Jim Cromie
2011-07-26  7:26   ` Bart Van Assche
2011-07-27 17:27     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 17/25] dynamic_debug: hoist locking in ddebug_change to callers Jim Cromie
2011-07-25 21:42 ` [PATCH 18/25] dynamic_debug: describe_flags with '=[pmflta_]*' Jim Cromie
2011-07-26  7:37   ` Bart Van Assche
2011-07-27 17:28     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 19/25] dynamic_debug: add flags filtering to flags spec Jim Cromie
2011-07-25 21:42 ` [PATCH 20/25] dynamic_debug: remove pending query when flags zeroed Jim Cromie
2011-07-25 21:42 ` Jim Cromie [this message]
2011-07-26  7:32   ` [PATCH 21/25] dynamic_debug: shrink struct pending query to size actually needed Bart Van Assche
2011-07-27 18:41     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 22/25] dynamic_debug: call ddebug_add_module() on dynamic_debug first Jim Cromie
2011-07-25 21:42 ` [PATCH 23/25] dynamic_debug: document pending queries, flags-filter, multiple queries Jim Cromie
2011-07-25 21:42 ` [PATCH 24/25] dynamic_debug: drop pr_fmt() from dynamic_pr_debug Jim Cromie
2011-07-26  2:23   ` Joe Perches
2011-07-26  3:45   ` Joe Perches
2011-07-26  5:54     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 25/25] dynamic_debug: add $DBGFS/dynamic_debug/pending Jim Cromie

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=1311630170-26057-22-git-send-email-jim.cromie@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=bvanassche@acm.org \
    --cc=gnb@fmeh.org \
    --cc=gregkh@suse.de \
    --cc=jbaron@redhat.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

all inboxes | Powered by JetHome®