Skip to contentSkip to conversation

Mark strstrip() as must_check

PATCH In review KOSAKI Motohiro 2 participants 6 messages Oct 2, 2009 – Oct 3, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Mark strstrip() as must_check

In few weeks ago discussion, Andrew Morton pointed out strstrip() should be must_check, because it was often abused.

This patch does that.

---
 include/linux/string.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/string.h +1 -1
index 489019e..b850886 100644
@@ -62,7 +62,7 @@ extern char * strnchr(const char *, size_t, int);
 #ifndef __HAVE_ARCH_STRRCHR
 extern char * strrchr(const char *,int);
 #endif
-extern char * strstrip(char *);
+extern char * __must_check strstrip(char *);
 #ifndef __HAVE_ARCH_STRSTR
 extern char * strstr(const char *,const char *);
 #endif
Signature · 9 lines
1.6.0.GIT



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 2/3 Fix strstrip() abuse in elv_iosched_store()

elv_iosched_store() ignore the return value of strstrip(). it makes small inconsistent behavior.

This patch fixes it.

<before>
====================================

 # cd /sys/block/{blockdev}/queue

case1:

 # echo "anticipatory" > scheduler
 # cat scheduler
 noop [anticipatory] deadline cfq

case2:

 # echo "anticipatory " > scheduler
 # cat scheduler
 noop [anticipatory] deadline cfq

case3:

 # echo " anticipatory" > scheduler
 bash: echo: write error: Invalid argument

<after>
====================================

 # cd /sys/block/{blockdev}/queue

case1:

 # echo "anticipatory" > scheduler
 # cat scheduler
 noop [anticipatory] deadline cfq

case2:

 # echo "anticipatory " > scheduler
 # cat scheduler
 noop [anticipatory] deadline cfq

case3:

 # echo " anticipatory" > scheduler
 noop [anticipatory] deadline cfq
---
 block/elevator.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
block/elevator.c +1 -3
Index: b/block/elevator.c
===================================================================
@@ -1059,9 +1059,7 @@ ssize_t elv_iosched_store(struct request
 		return count;
 
 	strlcpy(elevator_name, name, sizeof(elevator_name));
-	strstrip(elevator_name);
-
-	e = elevator_get(elevator_name);
+	e = elevator_get(strstrip(elevator_name));
 	if (!e) {
 		printk(KERN_ERR "elevator: type %s not found\n", elevator_name);
 		return -EINVAL;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

PATCH 3/3 cgroup: fix strstrip() abuse

In reply to KOSAKI Motohiro

cgroup_write_X64() and cgroup_write_string() ignore the return value of strstrip().
it makes small inconsistent behavior.

example:
=========================

 # cd /mnt/cgroup/hoge
 # cat memory.swappiness
 60
 # echo "59 " > memory.swappiness
 # cat memory.swappiness
 59
 # echo " 58" > memory.swappiness
 bash: echo: write error: Invalid argument

This patch fixes it.

---
 kernel/cgroup.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
kernel/cgroup.c +3 -5
Index: b/kernel/cgroup.c
===================================================================
@@ -1710,14 +1710,13 @@ static ssize_t cgroup_write_X64(struct c
 		return -EFAULT;
 
 	buffer[nbytes] = 0;     /* nul-terminate */
-	strstrip(buffer);
 	if (cft->write_u64) {
-		u64 val = simple_strtoull(buffer, &end, 0);
+		u64 val = simple_strtoull(strstrip(buffer), &end, 0);
 		if (*end)
 			return -EINVAL;
 		retval = cft->write_u64(cgrp, cft, val);
 	} else {
-		s64 val = simple_strtoll(buffer, &end, 0);
+		s64 val = simple_strtoll(strstrip(buffer), &end, 0);
 		if (*end)
 			return -EINVAL;
 		retval = cft->write_s64(cgrp, cft, val);
@@ -1753,8 +1752,7 @@ static ssize_t cgroup_write_string(struc
 	}
 
 	buffer[nbytes] = 0;     /* nul-terminate */
-	strstrip(buffer);
-	retval = cft->write_string(cgrp, cft, buffer);
+	retval = cft->write_string(cgrp, cft, strstrip(buffer));
 	if (!retval)
 		retval = nbytes;
 out:

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v1 3/3
#3 lore raw

Re: [PATCH 3/3] cgroup: fix strstrip() abuse

Quoted 16 lines · KOSAKI Motohiro

cgroup_write_X64() and cgroup_write_string() ignore the return value of strstrip().
it makes small inconsistent behavior.

example:
=========================

 # cd /mnt/cgroup/hoge
 # cat memory.swappiness
 60
 # echo "59 " > memory.swappiness
 # cat memory.swappiness
 59
 # echo " 58" > memory.swappiness
 bash: echo: write error: Invalid argument
Quoted 5 lines

This patch fixes it.

Thanks - although I think I'd s/abuse/misuse/ in the description.

Quoted 38 lines

---
 kernel/cgroup.c |    8 +++-----

 1 file changed, 3 insertions(+), 5 deletions(-)

Index: b/kernel/cgroup.c
===================================================================

kernel/cgroup.c +0 -0
@@ -1710,14 +1710,13 @@ static ssize_t cgroup_write_X64(struct c
                return -EFAULT;
 

       buffer[nbytes] = 0;     /* nul-terminate */
-       strstrip(buffer);
       if (cft->write_u64) {
-               u64 val = simple_strtoull(buffer, &end, 0);
+               u64 val = simple_strtoull(strstrip(buffer), &end, 0); if (*end)
                       return -EINVAL;
               retval = cft->write_u64(cgrp, cft, val);
       } else {
-               s64 val = simple_strtoll(buffer, &end, 0);
+               s64 val = simple_strtoll(strstrip(buffer), &end, 0); if (*end)
                       return -EINVAL;
               retval = cft->write_s64(cgrp, cft, val);

kernel/cgroup.c +0 -0
@@ -1753,8 +1752,7 @@ static ssize_t cgroup_write_string(struc
        }
 

       buffer[nbytes] = 0;     /* nul-terminate */
-       strstrip(buffer);
-       retval = cft->write_string(cgrp, cft, buffer);
+       retval = cft->write_string(cgrp, cft, strstrip(buffer)); if (!retval)
               retval = nbytes;
 out:

#4 lore raw

Re: [PATCH 3/3] cgroup: fix strstrip() abuse

Quoted 18 lines
Quoted 18 lines

cgroup_write_X64() and cgroup_write_string() ignore the return value of strstrip().
it makes small inconsistent behavior.

example:
=========================

 # cd /mnt/cgroup/hoge
 # cat memory.swappiness
 60
 # echo "59 " > memory.swappiness
 # cat memory.swappiness
 59
 # echo " 58" > memory.swappiness
 bash: echo: write error: Invalid argument

This patch fixes it.

Quoted 7 lines
Quoted 3 lines

Thanks - although I think I'd s/abuse/misuse/ in the description.

I don't know what's different between them. My dictionary is slightly quiet ;) Is this X-rated word? if so, I'll resend it soon.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Re: [PATCH 3/3] cgroup: fix strstrip() abuse

Quoted 4 lines · KOSAKI Motohiro
Quoted 1 line

Thanks - although I think I'd s/abuse/misuse/ in the description.

I don't know what's different between them. My dictionary is slightly quiet ;) Is this X-rated word? if so, I'll resend it soon.

Certainly not X-rated :-)

Generally "abuse" carries a connotation of intent (or perhaps deliberate hackiness) whereas "misuse" simply indicates that the previous code was wrong.

Paul

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>