[PATCH] param, charp: Cache val length
From: Borislav Petkov
Date: Mon Feb 18 2013 - 04:12:38 EST
From: Borislav Petkov <bp@xxxxxxx>
... instead of doing strlen twice.
Signed-off-by: Borislav Petkov <bp@xxxxxxx>
Cc: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
kernel/params.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/params.c b/kernel/params.c
index ed35345be536..d9401d66f5be 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -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);
--
1.8.1.3.535.ga923c31
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/