public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Milton Miller <miltonm@bga.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH] sched domain sysctl: free kstrdup allocations
Date: Mon, 15 Oct 2007 18:40:43 -0500 (CDT)	[thread overview]
Message-ID: <mm-sched-2b@bga.com> (raw)
In-Reply-To: <20071015074700.GC32064@elte.hu>

The procnames for the cpu and domain were allocated via kstrdup and so
should also be freed.   The names for the files are static, but we
can differentiate them by the presence of the proc_handler.  If a
kstrdup (of < 32 characters) fails the sysctl code will not see the
procname or remaining table entries, but any child tables and names
will be reclaimed upon free.

Signed-off-by: Milton Miller <miltonm@bga.com>
--- 

Hi Ingo.

It occurred to me this morning that the procname field was dynamically
allocated and needed to be freed.  I started to put in break statements
when allocation failed but it was approaching 50% error handling code.

I came up with this alternative of looping while entry->mode is set and
checking proc_handler instead of ->table.  Alternatively, the string
version of the domain name and cpu number could be stored the structs.

I verified by compiling CONFIG_DEBUG_SLAB and checking the allocation
counts after taking a cpuset exclusive and back.

milton

Index: kernel/kernel/sched.c
===================================================================
--- kernel.orig/kernel/sched.c	2007-10-15 12:21:38.000000000 -0500
+++ kernel/kernel/sched.c	2007-10-15 12:22:12.000000000 -0500
@@ -5290,11 +5290,20 @@ static struct ctl_table *sd_alloc_ctl_en
 
 static void sd_free_ctl_entry(struct ctl_table **tablep)
 {
-	struct ctl_table *entry = *tablep;
+	struct ctl_table *entry;
 
-	for (entry = *tablep; entry->procname; entry++)
+	/*
+	 * In the intermediate directories, both the child directory and
+	 * procname are dynamically allocated and could fail but the mode
+	 * will always be set.  In the lowest directory the names are
+	 * static strings and all have proc handlers.
+	 */
+	for (entry = *tablep; entry->mode; entry++) {
 		if (entry->child)
 			sd_free_ctl_entry(&entry->child);
+		if (entry->proc_handler == NULL)
+			kfree(entry->procname);
+	}
 
 	kfree(*tablep);
 	*tablep = NULL;

  reply	other threads:[~2007-10-15 23:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-12  9:34 [PATCH] sched domain debug sysctl fixes Milton Miller
2007-10-12  9:35 ` [PATCH] sched.c: use kcalloc Milton Miller
2007-10-12  9:35 ` [PATCH] sched domain sysctl: register online cpus Milton Miller
2007-10-12  9:35 ` [PATCH] sched domain sysctl: free and rebuild when changing domains Milton Miller
2007-10-12  9:35 ` [PATCH] sched domain sysctl: don't bug on alloc failure Milton Miller
2007-10-12  9:35 ` [PATCH] sched domain sysctl: sysctl tables can have no holes Milton Miller
2007-10-12  9:54 ` [PATCH] sched domain debug sysctl fixes Milton Miller
2007-10-15  7:47 ` Ingo Molnar
2007-10-15 23:40   ` Milton Miller [this message]
2007-10-16  8:44     ` [PATCH] sched domain sysctl: free kstrdup allocations Ingo Molnar

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=mm-sched-2b@bga.com \
    --to=miltonm@bga.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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