Skip to content

Commit e7d2860

Browse files
andre-rosatorvalds
authored andcommitted
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 <[email protected]> Cc: Julia Lawall <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Jeff Dike <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Richard Purdie <[email protected]> Cc: Neil Brown <[email protected]> Cc: Kyle McMartin <[email protected]> Cc: Henrique de Moraes Holschuh <[email protected]> Cc: David Howells <[email protected]> Cc: <[email protected]> Cc: Samuel Ortiz <[email protected]> Cc: Patrick McHardy <[email protected]> Cc: Takashi Iwai <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 84c95c9 commit e7d2860

File tree

24 files changed

+66
-115
lines changed

24 files changed

+66
-115
lines changed

arch/s390/kernel/debug.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/errno.h>
1919
#include <linux/slab.h>
2020
#include <linux/ctype.h>
21+
#include <linux/string.h>
2122
#include <linux/sysctl.h>
2223
#include <asm/uaccess.h>
2324
#include <linux/module.h>
@@ -1178,7 +1179,7 @@ debug_get_uint(char *buf)
11781179
{
11791180
int rc;
11801181

1181-
for(; isspace(*buf); buf++);
1182+
buf = skip_spaces(buf);
11821183
rc = simple_strtoul(buf, &buf, 10);
11831184
if(*buf){
11841185
rc = -EINVAL;

arch/um/drivers/mconsole_kern.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <linux/console.h>
88
#include <linux/ctype.h>
9+
#include <linux/string.h>
910
#include <linux/interrupt.h>
1011
#include <linux/list.h>
1112
#include <linux/mm.h>
@@ -131,7 +132,7 @@ void mconsole_proc(struct mc_request *req)
131132
char *ptr = req->request.data, *buf;
132133

133134
ptr += strlen("proc");
134-
while (isspace(*ptr)) ptr++;
135+
ptr = skip_spaces(ptr);
135136

136137
proc = get_fs_type("proc");
137138
if (proc == NULL) {
@@ -212,8 +213,7 @@ void mconsole_proc(struct mc_request *req)
212213
char *ptr = req->request.data;
213214

214215
ptr += strlen("proc");
215-
while (isspace(*ptr))
216-
ptr++;
216+
ptr = skip_spaces(ptr);
217217
snprintf(path, sizeof(path), "/proc/%s", ptr);
218218

219219
fd = sys_open(path, 0, 0);
@@ -560,8 +560,7 @@ void mconsole_config(struct mc_request *req)
560560
int err;
561561

562562
ptr += strlen("config");
563-
while (isspace(*ptr))
564-
ptr++;
563+
ptr = skip_spaces(ptr);
565564
dev = mconsole_find_dev(ptr);
566565
if (dev == NULL) {
567566
mconsole_reply(req, "Bad configuration option", 1, 0);
@@ -588,7 +587,7 @@ void mconsole_remove(struct mc_request *req)
588587
int err, start, end, n;
589588

590589
ptr += strlen("remove");
591-
while (isspace(*ptr)) ptr++;
590+
ptr = skip_spaces(ptr);
592591
dev = mconsole_find_dev(ptr);
593592
if (dev == NULL) {
594593
mconsole_reply(req, "Bad remove option", 1, 0);
@@ -712,7 +711,7 @@ void mconsole_sysrq(struct mc_request *req)
712711
char *ptr = req->request.data;
713712

714713
ptr += strlen("sysrq");
715-
while (isspace(*ptr)) ptr++;
714+
ptr = skip_spaces(ptr);
716715

717716
/*
718717
* With 'b', the system will shut down without a chance to reply,
@@ -757,8 +756,7 @@ void mconsole_stack(struct mc_request *req)
757756
*/
758757

759758
ptr += strlen("stack");
760-
while (isspace(*ptr))
761-
ptr++;
759+
ptr = skip_spaces(ptr);
762760

763761
/*
764762
* Should really check for multiple pids or reject bad args here

arch/x86/kernel/cpu/mtrr/if.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/proc_fs.h>
55
#include <linux/module.h>
66
#include <linux/ctype.h>
7+
#include <linux/string.h>
78
#include <linux/init.h>
89

910
#define LINE_SIZE 80
@@ -133,23 +134,19 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
133134
return -EINVAL;
134135

135136
base = simple_strtoull(line + 5, &ptr, 0);
136-
while (isspace(*ptr))
137-
ptr++;
137+
ptr = skip_spaces(ptr);
138138

139139
if (strncmp(ptr, "size=", 5))
140140
return -EINVAL;
141141

142142
size = simple_strtoull(ptr + 5, &ptr, 0);
143143
if ((base & 0xfff) || (size & 0xfff))
144144
return -EINVAL;
145-
while (isspace(*ptr))
146-
ptr++;
145+
ptr = skip_spaces(ptr);
147146

148147
if (strncmp(ptr, "type=", 5))
149148
return -EINVAL;
150-
ptr += 5;
151-
while (isspace(*ptr))
152-
ptr++;
149+
ptr = skip_spaces(ptr + 5);
153150

154151
for (i = 0; i < MTRR_NUM_TYPES; ++i) {
155152
if (strcmp(ptr, mtrr_strings[i]))

drivers/leds/led-class.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static ssize_t led_brightness_store(struct device *dev,
5050
unsigned long state = simple_strtoul(buf, &after, 10);
5151
size_t count = after - buf;
5252

53-
if (*after && isspace(*after))
53+
if (isspace(*after))
5454
count++;
5555

5656
if (count == size) {

drivers/leds/ledtrig-timer.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static ssize_t led_delay_on_store(struct device *dev,
8383
unsigned long state = simple_strtoul(buf, &after, 10);
8484
size_t count = after - buf;
8585

86-
if (*after && isspace(*after))
86+
if (isspace(*after))
8787
count++;
8888

8989
if (count == size) {
@@ -127,7 +127,7 @@ static ssize_t led_delay_off_store(struct device *dev,
127127
unsigned long state = simple_strtoul(buf, &after, 10);
128128
size_t count = after - buf;
129129

130-
if (*after && isspace(*after))
130+
if (isspace(*after))
131131
count++;
132132

133133
if (count == size) {

drivers/md/dm-table.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/blkdev.h>
1313
#include <linux/namei.h>
1414
#include <linux/ctype.h>
15+
#include <linux/string.h>
1516
#include <linux/slab.h>
1617
#include <linux/interrupt.h>
1718
#include <linux/mutex.h>
@@ -600,11 +601,8 @@ int dm_split_args(int *argc, char ***argvp, char *input)
600601
return -ENOMEM;
601602

602603
while (1) {
603-
start = end;
604-
605604
/* Skip whitespace */
606-
while (*start && isspace(*start))
607-
start++;
605+
start = skip_spaces(end);
608606

609607
if (!*start)
610608
break; /* success, we hit the end */

drivers/md/md.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/buffer_head.h> /* for invalidate_bdev */
4040
#include <linux/poll.h>
4141
#include <linux/ctype.h>
42+
#include <linux/string.h>
4243
#include <linux/hdreg.h>
4344
#include <linux/proc_fs.h>
4445
#include <linux/random.h>
@@ -3439,8 +3440,7 @@ bitmap_store(mddev_t *mddev, const char *buf, size_t len)
34393440
}
34403441
if (*end && !isspace(*end)) break;
34413442
bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk);
3442-
buf = end;
3443-
while (isspace(*buf)) buf++;
3443+
buf = skip_spaces(end);
34443444
}
34453445
bitmap_unplug(mddev->bitmap); /* flush the bits to disk */
34463446
out:

drivers/parisc/pdc_stable.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,9 @@ static ssize_t pdcs_auto_write(struct kobject *kobj,
779779
read_unlock(&pathentry->rw_lock);
780780

781781
DPRINTK("%s: flags before: 0x%X\n", __func__, flags);
782-
783-
temp = in;
784-
785-
while (*temp && isspace(*temp))
786-
temp++;
787-
782+
783+
temp = skip_spaces(in);
784+
788785
c = *temp++ - '0';
789786
if ((c != 0) && (c != 1))
790787
goto parse_error;

drivers/platform/x86/thinkpad_acpi.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,8 @@ static int parse_strtoul(const char *buf,
10061006
{
10071007
char *endp;
10081008

1009-
while (*buf && isspace(*buf))
1010-
buf++;
1011-
*value = simple_strtoul(buf, &endp, 0);
1012-
while (*endp && isspace(*endp))
1013-
endp++;
1009+
*value = simple_strtoul(skip_spaces(buf), &endp, 0);
1010+
endp = skip_spaces(endp);
10141011
if (*endp || *value > max)
10151012
return -EINVAL;
10161013

drivers/pnp/interface.c

+10-26
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
310310
goto done;
311311
}
312312

313-
while (isspace(*buf))
314-
++buf;
313+
buf = skip_spaces(buf);
315314
if (!strnicmp(buf, "disable", 7)) {
316315
retval = pnp_disable_dev(dev);
317316
goto done;
@@ -353,54 +352,39 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
353352
pnp_init_resources(dev);
354353
mutex_lock(&pnp_res_mutex);
355354
while (1) {
356-
while (isspace(*buf))
357-
++buf;
355+
buf = skip_spaces(buf);
358356
if (!strnicmp(buf, "io", 2)) {
359-
buf += 2;
360-
while (isspace(*buf))
361-
++buf;
357+
buf = skip_spaces(buf + 2);
362358
start = simple_strtoul(buf, &buf, 0);
363-
while (isspace(*buf))
364-
++buf;
359+
buf = skip_spaces(buf);
365360
if (*buf == '-') {
366-
buf += 1;
367-
while (isspace(*buf))
368-
++buf;
361+
buf = skip_spaces(buf + 1);
369362
end = simple_strtoul(buf, &buf, 0);
370363
} else
371364
end = start;
372365
pnp_add_io_resource(dev, start, end, 0);
373366
continue;
374367
}
375368
if (!strnicmp(buf, "mem", 3)) {
376-
buf += 3;
377-
while (isspace(*buf))
378-
++buf;
369+
buf = skip_spaces(buf + 3);
379370
start = simple_strtoul(buf, &buf, 0);
380-
while (isspace(*buf))
381-
++buf;
371+
buf = skip_spaces(buf);
382372
if (*buf == '-') {
383-
buf += 1;
384-
while (isspace(*buf))
385-
++buf;
373+
buf = skip_spaces(buf + 1);
386374
end = simple_strtoul(buf, &buf, 0);
387375
} else
388376
end = start;
389377
pnp_add_mem_resource(dev, start, end, 0);
390378
continue;
391379
}
392380
if (!strnicmp(buf, "irq", 3)) {
393-
buf += 3;
394-
while (isspace(*buf))
395-
++buf;
381+
buf = skip_spaces(buf + 3);
396382
start = simple_strtoul(buf, &buf, 0);
397383
pnp_add_irq_resource(dev, start, 0);
398384
continue;
399385
}
400386
if (!strnicmp(buf, "dma", 3)) {
401-
buf += 3;
402-
while (isspace(*buf))
403-
++buf;
387+
buf = skip_spaces(buf + 3);
404388
start = simple_strtoul(buf, &buf, 0);
405389
pnp_add_dma_resource(dev, start, 0);
406390
continue;

drivers/s390/block/dasd_proc.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define KMSG_COMPONENT "dasd"
1515

1616
#include <linux/ctype.h>
17+
#include <linux/string.h>
1718
#include <linux/seq_file.h>
1819
#include <linux/vmalloc.h>
1920
#include <linux/proc_fs.h>
@@ -272,10 +273,10 @@ dasd_statistics_write(struct file *file, const char __user *user_buf,
272273
DBF_EVENT(DBF_DEBUG, "/proc/dasd/statictics: '%s'\n", buffer);
273274

274275
/* check for valid verbs */
275-
for (str = buffer; isspace(*str); str++);
276+
str = skip_spaces(buffer);
276277
if (strncmp(str, "set", 3) == 0 && isspace(str[3])) {
277278
/* 'set xxx' was given */
278-
for (str = str + 4; isspace(*str); str++);
279+
str = skip_spaces(str + 4);
279280
if (strcmp(str, "on") == 0) {
280281
/* switch on statistics profiling */
281282
dasd_profile_level = DASD_PROFILE_ON;

drivers/video/backlight/lcd.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static ssize_t lcd_store_power(struct device *dev,
101101
int power = simple_strtoul(buf, &endp, 0);
102102
size_t size = endp - buf;
103103

104-
if (*endp && isspace(*endp))
104+
if (isspace(*endp))
105105
size++;
106106
if (size != count)
107107
return -EINVAL;
@@ -140,7 +140,7 @@ static ssize_t lcd_store_contrast(struct device *dev,
140140
int contrast = simple_strtoul(buf, &endp, 0);
141141
size_t size = endp - buf;
142142

143-
if (*endp && isspace(*endp))
143+
if (isspace(*endp))
144144
size++;
145145
if (size != count)
146146
return -EINVAL;

drivers/video/display/display-sysfs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static ssize_t display_store_contrast(struct device *dev,
6767
contrast = simple_strtoul(buf, &endp, 0);
6868
size = endp - buf;
6969

70-
if (*endp && isspace(*endp))
70+
if (isspace(*endp))
7171
size++;
7272

7373
if (size != count)

drivers/video/output.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static ssize_t video_output_store_state(struct device *dev,
5050
int request_state = simple_strtoul(buf,&endp,0);
5151
size_t size = endp - buf;
5252

53-
if (*endp && isspace(*endp))
53+
if (isspace(*endp))
5454
size++;
5555
if (size != count)
5656
return -EINVAL;

fs/cachefiles/daemon.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/mount.h>
2222
#include <linux/statfs.h>
2323
#include <linux/ctype.h>
24+
#include <linux/string.h>
2425
#include <linux/fs_struct.h>
2526
#include "internal.h"
2627

@@ -257,8 +258,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
257258
if (args == data)
258259
goto error;
259260
*args = '\0';
260-
for (args++; isspace(*args); args++)
261-
continue;
261+
args = skip_spaces(++args);
262262
}
263263

264264
/* run the appropriate command handler */

fs/ext4/super.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -2137,11 +2137,8 @@ static int parse_strtoul(const char *buf,
21372137
{
21382138
char *endp;
21392139

2140-
while (*buf && isspace(*buf))
2141-
buf++;
2142-
*value = simple_strtoul(buf, &endp, 0);
2143-
while (*endp && isspace(*endp))
2144-
endp++;
2140+
*value = simple_strtoul(skip_spaces(buf), &endp, 0);
2141+
endp = skip_spaces(endp);
21452142
if (*endp || *value > max)
21462143
return -EINVAL;
21472144

0 commit comments

Comments
 (0)