public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] ipmi: strstrip conversion
@ 2006-04-25  9:11 Pekka Enberg
  2006-04-25 13:10 ` Corey Minyard
  0 siblings, 1 reply; 2+ messages in thread
From: Pekka Enberg @ 2006-04-25  9:11 UTC (permalink / raw)
  To: akpm; +Cc: minyard, linux-kernel

From: Pekka Enberg <penberg@cs.helsinki.fi>

This patch switches an open-coded strstrip to use the new API.

Cc: Corey Minyard <minyard@acm.org>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>

---

 drivers/char/ipmi/ipmi_watchdog.c |   25 +++++++++----------------
 1 files changed, 9 insertions(+), 16 deletions(-)

342eaae5800b0fd002f5101d66ccb02e786016d8
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 2d11ddd..8f88671 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -212,24 +212,16 @@ static int set_param_str(const char *val
 {
 	action_fn  fn = (action_fn) kp->arg;
 	int        rv = 0;
-	const char *end;
-	char       valcp[16];
-	int        len;
-
-	/* Truncate leading and trailing spaces. */
-	while (isspace(*val))
-		val++;
-	end = val + strlen(val) - 1;
-	while ((end >= val) && isspace(*end))
-		end--;
-	len = end - val + 1;
-	if (len > sizeof(valcp) - 1)
-		return -EINVAL;
-	memcpy(valcp, val, len);
-	valcp[len] = '\0';
+	char       *dup, *s;
+
+	dup = kstrdup(val, GFP_KERNEL);
+	if (!dup)
+		return -ENOMEM;
+
+	s = strstrip(dup);
 
 	down_read(&register_sem);
-	rv = fn(valcp, NULL);
+	rv = fn(s, NULL);
 	if (rv)
 		goto out_unlock;
 
@@ -239,6 +231,7 @@ static int set_param_str(const char *val
 
  out_unlock:
 	up_read(&register_sem);
+	kfree(dup);
 	return rv;
 }
 
-- 
1.3.0




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] ipmi: strstrip conversion
  2006-04-25  9:11 [PATCH 2/2] ipmi: strstrip conversion Pekka Enberg
@ 2006-04-25 13:10 ` Corey Minyard
  0 siblings, 0 replies; 2+ messages in thread
From: Corey Minyard @ 2006-04-25 13:10 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: akpm, linux-kernel

It's a little less efficient, but certainly a lot cleaner to do it this
way.  It's not critical code, so I'm happy with this change.

-Corey

Pekka Enberg wrote:

>From: Pekka Enberg <penberg@cs.helsinki.fi>
>
>This patch switches an open-coded strstrip to use the new API.
>
>Cc: Corey Minyard <minyard@acm.org>
>Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
>
>---
>
> drivers/char/ipmi/ipmi_watchdog.c |   25 +++++++++----------------
> 1 files changed, 9 insertions(+), 16 deletions(-)
>
>342eaae5800b0fd002f5101d66ccb02e786016d8
>diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
>index 2d11ddd..8f88671 100644
>--- a/drivers/char/ipmi/ipmi_watchdog.c
>+++ b/drivers/char/ipmi/ipmi_watchdog.c
>@@ -212,24 +212,16 @@ static int set_param_str(const char *val
> {
> 	action_fn  fn = (action_fn) kp->arg;
> 	int        rv = 0;
>-	const char *end;
>-	char       valcp[16];
>-	int        len;
>-
>-	/* Truncate leading and trailing spaces. */
>-	while (isspace(*val))
>-		val++;
>-	end = val + strlen(val) - 1;
>-	while ((end >= val) && isspace(*end))
>-		end--;
>-	len = end - val + 1;
>-	if (len > sizeof(valcp) - 1)
>-		return -EINVAL;
>-	memcpy(valcp, val, len);
>-	valcp[len] = '\0';
>+	char       *dup, *s;
>+
>+	dup = kstrdup(val, GFP_KERNEL);
>+	if (!dup)
>+		return -ENOMEM;
>+
>+	s = strstrip(dup);
> 
> 	down_read(&register_sem);
>-	rv = fn(valcp, NULL);
>+	rv = fn(s, NULL);
> 	if (rv)
> 		goto out_unlock;
> 
>@@ -239,6 +231,7 @@ static int set_param_str(const char *val
> 
>  out_unlock:
> 	up_read(&register_sem);
>+	kfree(dup);
> 	return rv;
> }
> 
>  
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-04-25 13:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-25  9:11 [PATCH 2/2] ipmi: strstrip conversion Pekka Enberg
2006-04-25 13:10 ` Corey Minyard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox