Skip to contentSkip to conversation

param, charp: Cache val length

PATCH In review Borislav Petkov 2 participants 3 messages Feb 18, 2013 – Feb 19, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 param, charp: Cache val length

From: Borislav Petkov <[email protected]>

... instead of doing strlen twice.

Cc Rusty Russell <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 kernel/params.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/params.c +5 -2
index ed35345be536..d9401d66f5be 100644
@@ -262,7 +262,10 @@ STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul);
 
 int param_set_charp(const char *val, const struct kernel_param *kp)
 {
-	if (strlen(val) > 1024) {
+	unsigned len;
+
+	len = strlen(val);
+	if (len > 1024) {
 		pr_err("%s: string parameter too long\n", kp->name);
 		return -ENOSPC;
 	}
@@ -272,7 +275,7 @@ int param_set_charp(const char *val, const struct kernel_param *kp)
 	/* This is a hack.  We can't kmalloc in early boot, and we
 	 * don't need to; this mangled commandline is preserved. */
 	if (slab_is_available()) {
-		*(char **)kp->arg = kmalloc_parameter(strlen(val)+1);
+		*(char **)kp->arg = kmalloc_parameter(len + 1);
 		if (!*(char **)kp->arg)
 			return -ENOMEM;
 		strcpy(*(char **)kp->arg, val);
Signature · 1 line
1.8.1.3.535.ga923c31
#1 lore raw
Quoted 3 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

... instead of doing strlen twice.

I'm delighted with your enthusiasm for making trivial changes, but I have trouble sharing in it.

In this case, it's so marginal that I'll leave the status quo.

Thanks,
Rusty.

#2 lore raw
Quoted 1 line · Rusty Russell

I'm delighted with your enthusiasm for making trivial changes,

Who says I'm enthusiastic about it?

Quoted 1 line

but I have trouble sharing in it.

I just assumed that noodling for a second time over a string of possible length of 1024 chars (I know, I know, we will never have params of that length, yadda yadda...) should be avoided.

Nevermind.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--