aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAndré Goddard Rosa <andre.goddard@gmail.com>2009-12-14 21:01:06 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-15 11:53:32 -0500
commite7d2860b690d4f3bed6824757c540579638e3d1e (patch)
tree84268ee28893256fd6a6a7e1d4474f61dbee74e7 /drivers
parent84c95c9acf088c99d8793d78036b67faa5d0b851 (diff)
tree-wide: convert open calls to remove spaces to skip_spaces() lib function
Makes use of skip_spaces() defined in lib/string.c for removing leading spaces from strings all over the tree. It decreases lib.a code size by 47 bytes and reuses the function tree-wide: text data bss dec hex filename 64688 584 592 65864 10148 (TOTALS-BEFORE) 64641 584 592 65817 10119 (TOTALS-AFTER) Also, while at it, if we see (*str && isspace(*str)), we can be sure to remove the first condition (*str) as the second one (isspace(*str)) also evaluates to 0 whenever *str == 0, making it redundant. In other words, "a char equals zero is never a space". Julia Lawall tried the semantic patch (http://coccinelle.lip6.fr) below, and found occurrences of this pattern on 3 more files: drivers/leds/led-class.c drivers/leds/ledtrig-timer.c drivers/video/output.c @@ expression str; @@ ( // ignore skip_spaces cases while (*str && isspace(*str)) { \(str++;\|++str;\) } | - *str && isspace(*str) ) Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com> Cc: Julia Lawall <julia@diku.dk> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Jeff Dike <jdike@addtoit.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Richard Purdie <rpurdie@rpsys.net> Cc: Neil Brown <neilb@suse.de> Cc: Kyle McMartin <kyle@mcmartin.ca> Cc: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Cc: David Howells <dhowells@redhat.com> Cc: <linux-ext4@vger.kernel.org> Cc: Samuel Ortiz <samuel@sortiz.org> Cc: Patrick McHardy <kaber@trash.net> Cc: Takashi Iwai <tiwai@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/leds/led-class.c2
-rw-r--r--drivers/leds/ledtrig-timer.c4
-rw-r--r--drivers/md/dm-table.c6
-rw-r--r--drivers/md/md.c4
-rw-r--r--drivers/parisc/pdc_stable.c9
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c7
-rw-r--r--drivers/pnp/interface.c36
-rw-r--r--drivers/s390/block/dasd_proc.c5
-rw-r--r--drivers/video/backlight/lcd.c4
-rw-r--r--drivers/video/display/display-sysfs.c2
-rw-r--r--drivers/video/output.c2
11 files changed, 29 insertions, 52 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f2cc13d76810..782f95822eab 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -50,7 +50,7 @@ static ssize_t led_brightness_store(struct device *dev,
50 unsigned long state = simple_strtoul(buf, &after, 10); 50 unsigned long state = simple_strtoul(buf, &after, 10);
51 size_t count = after - buf; 51 size_t count = after - buf;
52 52
53 if (*after && isspace(*after)) 53 if (isspace(*after))
54 count++; 54 count++;
55 55
56 if (count == size) { 56 if (count == size) {
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index 3b83406de752..38b3378be442 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -83,7 +83,7 @@ static ssize_t led_delay_on_store(struct device *dev,
83 unsigned long state = simple_strtoul(buf, &after, 10); 83 unsigned long state = simple_strtoul(buf, &after, 10);
84 size_t count = after - buf; 84 size_t count = after - buf;
85 85
86 if (*after && isspace(*after)) 86 if (isspace(*after))
87 count++; 87 count++;
88 88
89 if (count == size) { 89 if (count == size) {
@@ -127,7 +127,7 @@ static ssize_t led_delay_off_store(struct device *dev,
127 unsigned long state = simple_strtoul(buf, &after, 10); 127 unsigned long state = simple_strtoul(buf, &after, 10);
128 size_t count = after - buf; 128 size_t count = after - buf;
129 129
130 if (*after && isspace(*after)) 130 if (isspace(*after))
131 count++; 131 count++;
132 132
133 if (count == size) { 133 if (count == size) {
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 1a6cb3c7822e..91976e8fae5f 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -12,6 +12,7 @@
12#include <linux/blkdev.h> 12#include <linux/blkdev.h>
13#include <linux/namei.h> 13#include <linux/namei.h>
14#include <linux/ctype.h> 14#include <linux/ctype.h>
15#include <linux/string.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/interrupt.h> 17#include <linux/interrupt.h>
17#include <linux/mutex.h> 18#include <linux/mutex.h>
@@ -600,11 +601,8 @@ int dm_split_args(int *argc, char ***argvp, char *input)
600 return -ENOMEM; 601 return -ENOMEM;
601 602
602 while (1) { 603 while (1) {
603 start = end;
604
605 /* Skip whitespace */ 604 /* Skip whitespace */
606 while (*start && isspace(*start)) 605 start = skip_spaces(end);
607 start++;
608 606
609 if (!*start) 607 if (!*start)
610 break; /* success, we hit the end */ 608 break; /* success, we hit the end */
diff --git a/drivers/md/md.c b/drivers/md/md.c
index e1f3c1715cca..6f9148623a4d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -39,6 +39,7 @@
39#include <linux/buffer_head.h> /* for invalidate_bdev */ 39#include <linux/buffer_head.h> /* for invalidate_bdev */
40#include <linux/poll.h> 40#include <linux/poll.h>
41#include <linux/ctype.h> 41#include <linux/ctype.h>
42#include <linux/string.h>
42#include <linux/hdreg.h> 43#include <linux/hdreg.h>
43#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
44#include <linux/random.h> 45#include <linux/random.h>
@@ -3439,8 +3440,7 @@ bitmap_store(mddev_t *mddev, const char *buf, size_t len)
3439 } 3440 }
3440 if (*end && !isspace(*end)) break; 3441 if (*end && !isspace(*end)) break;
3441 bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk); 3442 bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk);
3442 buf = end; 3443 buf = skip_spaces(end);
3443 while (isspace(*buf)) buf++;
3444 } 3444 }
3445 bitmap_unplug(mddev->bitmap); /* flush the bits to disk */ 3445 bitmap_unplug(mddev->bitmap); /* flush the bits to disk */
3446out: 3446out:
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 13a64bc081b6..0bc5d474b168 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -779,12 +779,9 @@ static ssize_t pdcs_auto_write(struct kobject *kobj,
779 read_unlock(&pathentry->rw_lock); 779 read_unlock(&pathentry->rw_lock);
780 780
781 DPRINTK("%s: flags before: 0x%X\n", __func__, flags); 781 DPRINTK("%s: flags before: 0x%X\n", __func__, flags);
782 782
783 temp = in; 783 temp = skip_spaces(in);
784 784
785 while (*temp && isspace(*temp))
786 temp++;
787
788 c = *temp++ - '0'; 785 c = *temp++ - '0';
789 if ((c != 0) && (c != 1)) 786 if ((c != 0) && (c != 1))
790 goto parse_error; 787 goto parse_error;
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 0ed84806f8ae..cf61d6a8ef6f 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -1006,11 +1006,8 @@ static int parse_strtoul(const char *buf,
1006{ 1006{
1007 char *endp; 1007 char *endp;
1008 1008
1009 while (*buf && isspace(*buf)) 1009 *value = simple_strtoul(skip_spaces(buf), &endp, 0);
1010 buf++; 1010 endp = skip_spaces(endp);
1011 *value = simple_strtoul(buf, &endp, 0);
1012 while (*endp && isspace(*endp))
1013 endp++;
1014 if (*endp || *value > max) 1011 if (*endp || *value > max)
1015 return -EINVAL; 1012 return -EINVAL;
1016 1013
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c
index c3f1c8e9d254..68b0c04987e4 100644
--- a/drivers/pnp/interface.c
+++ b/drivers/pnp/interface.c
@@ -310,8 +310,7 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
310 goto done; 310 goto done;
311 } 311 }
312 312
313 while (isspace(*buf)) 313 buf = skip_spaces(buf);
314 ++buf;
315 if (!strnicmp(buf, "disable", 7)) { 314 if (!strnicmp(buf, "disable", 7)) {
316 retval = pnp_disable_dev(dev); 315 retval = pnp_disable_dev(dev);
317 goto done; 316 goto done;
@@ -353,19 +352,13 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
353 pnp_init_resources(dev); 352 pnp_init_resources(dev);
354 mutex_lock(&pnp_res_mutex); 353 mutex_lock(&pnp_res_mutex);
355 while (1) { 354 while (1) {
356 while (isspace(*buf)) 355 buf = skip_spaces(buf);
357 ++buf;
358 if (!strnicmp(buf, "io", 2)) { 356 if (!strnicmp(buf, "io", 2)) {
359 buf += 2; 357 buf = skip_spaces(buf + 2);
360 while (isspace(*buf))
361 ++buf;
362 start = simple_strtoul(buf, &buf, 0); 358 start = simple_strtoul(buf, &buf, 0);
363 while (isspace(*buf)) 359 buf = skip_spaces(buf);
364 ++buf;
365 if (*buf == '-') { 360 if (*buf == '-') {
366 buf += 1; 361 buf = skip_spaces(buf + 1);
367 while (isspace(*buf))
368 ++buf;
369 end = simple_strtoul(buf, &buf, 0); 362 end = simple_strtoul(buf, &buf, 0);
370 } else 363 } else
371 end = start; 364 end = start;
@@ -373,16 +366,11 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
373 continue; 366 continue;
374 } 367 }
375 if (!strnicmp(buf, "mem", 3)) { 368 if (!strnicmp(buf, "mem", 3)) {
376 buf += 3; 369 buf = skip_spaces(buf + 3);
377 while (isspace(*buf))
378 ++buf;
379 start = simple_strtoul(buf, &buf, 0); 370 start = simple_strtoul(buf, &buf, 0);
380 while (isspace(*buf)) 371 buf = skip_spaces(buf);
381 ++buf;
382 if (*buf == '-') { 372 if (*buf == '-') {
383 buf += 1; 373 buf = skip_spaces(buf + 1);
384 while (isspace(*buf))
385 ++buf;
386 end = simple_strtoul(buf, &buf, 0); 374 end = simple_strtoul(buf, &buf, 0);
387 } else 375 } else
388 end = start; 376 end = start;
@@ -390,17 +378,13 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
390 continue; 378 continue;
391 } 379 }
392 if (!strnicmp(buf, "irq", 3)) { 380 if (!strnicmp(buf, "irq", 3)) {
393 buf += 3; 381 buf = skip_spaces(buf + 3);
394 while (isspace(*buf))
395 ++buf;
396 start = simple_strtoul(buf, &buf, 0); 382 start = simple_strtoul(buf, &buf, 0);
397 pnp_add_irq_resource(dev, start, 0); 383 pnp_add_irq_resource(dev, start, 0);
398 continue; 384 continue;
399 } 385 }
400 if (!strnicmp(buf, "dma", 3)) { 386 if (!strnicmp(buf, "dma", 3)) {
401 buf += 3; 387 buf = skip_spaces(buf + 3);
402 while (isspace(*buf))
403 ++buf;
404 start = simple_strtoul(buf, &buf, 0); 388 start = simple_strtoul(buf, &buf, 0);
405 pnp_add_dma_resource(dev, start, 0); 389 pnp_add_dma_resource(dev, start, 0);
406 continue; 390 continue;
diff --git a/drivers/s390/block/dasd_proc.c b/drivers/s390/block/dasd_proc.c
index 5f23eca82804..6315fbd8e68b 100644
--- a/drivers/s390/block/dasd_proc.c
+++ b/drivers/s390/block/dasd_proc.c
@@ -14,6 +14,7 @@
14#define KMSG_COMPONENT "dasd" 14#define KMSG_COMPONENT "dasd"
15 15
16#include <linux/ctype.h> 16#include <linux/ctype.h>
17#include <linux/string.h>
17#include <linux/seq_file.h> 18#include <linux/seq_file.h>
18#include <linux/vmalloc.h> 19#include <linux/vmalloc.h>
19#include <linux/proc_fs.h> 20#include <linux/proc_fs.h>
@@ -272,10 +273,10 @@ dasd_statistics_write(struct file *file, const char __user *user_buf,
272 DBF_EVENT(DBF_DEBUG, "/proc/dasd/statictics: '%s'\n", buffer); 273 DBF_EVENT(DBF_DEBUG, "/proc/dasd/statictics: '%s'\n", buffer);
273 274
274 /* check for valid verbs */ 275 /* check for valid verbs */
275 for (str = buffer; isspace(*str); str++); 276 str = skip_spaces(buffer);
276 if (strncmp(str, "set", 3) == 0 && isspace(str[3])) { 277 if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
277 /* 'set xxx' was given */ 278 /* 'set xxx' was given */
278 for (str = str + 4; isspace(*str); str++); 279 str = skip_spaces(str + 4);
279 if (strcmp(str, "on") == 0) { 280 if (strcmp(str, "on") == 0) {
280 /* switch on statistics profiling */ 281 /* switch on statistics profiling */
281 dasd_profile_level = DASD_PROFILE_ON; 282 dasd_profile_level = DASD_PROFILE_ON;
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index a482dd7b0311..9b3be74cee5a 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -101,7 +101,7 @@ static ssize_t lcd_store_power(struct device *dev,
101 int power = simple_strtoul(buf, &endp, 0); 101 int power = simple_strtoul(buf, &endp, 0);
102 size_t size = endp - buf; 102 size_t size = endp - buf;
103 103
104 if (*endp && isspace(*endp)) 104 if (isspace(*endp))
105 size++; 105 size++;
106 if (size != count) 106 if (size != count)
107 return -EINVAL; 107 return -EINVAL;
@@ -140,7 +140,7 @@ static ssize_t lcd_store_contrast(struct device *dev,
140 int contrast = simple_strtoul(buf, &endp, 0); 140 int contrast = simple_strtoul(buf, &endp, 0);
141 size_t size = endp - buf; 141 size_t size = endp - buf;
142 142
143 if (*endp && isspace(*endp)) 143 if (isspace(*endp))
144 size++; 144 size++;
145 if (size != count) 145 if (size != count)
146 return -EINVAL; 146 return -EINVAL;
diff --git a/drivers/video/display/display-sysfs.c b/drivers/video/display/display-sysfs.c
index 4830b1bf51e5..80abbf323b99 100644
--- a/drivers/video/display/display-sysfs.c
+++ b/drivers/video/display/display-sysfs.c
@@ -67,7 +67,7 @@ static ssize_t display_store_contrast(struct device *dev,
67 contrast = simple_strtoul(buf, &endp, 0); 67 contrast = simple_strtoul(buf, &endp, 0);
68 size = endp - buf; 68 size = endp - buf;
69 69
70 if (*endp && isspace(*endp)) 70 if (isspace(*endp))
71 size++; 71 size++;
72 72
73 if (size != count) 73 if (size != count)
diff --git a/drivers/video/output.c b/drivers/video/output.c
index 5e6439ae7394..5137aa016b83 100644
--- a/drivers/video/output.c
+++ b/drivers/video/output.c
@@ -50,7 +50,7 @@ static ssize_t video_output_store_state(struct device *dev,
50 int request_state = simple_strtoul(buf,&endp,0); 50 int request_state = simple_strtoul(buf,&endp,0);
51 size_t size = endp - buf; 51 size_t size = endp - buf;
52 52
53 if (*endp && isspace(*endp)) 53 if (isspace(*endp))
54 size++; 54 size++;
55 if (size != count) 55 if (size != count)
56 return -EINVAL; 56 return -EINVAL;