Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7d2860b authored by André Goddard Rosa's avatar André Goddard Rosa Committed by Linus Torvalds
Browse files

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: default avatarAndré 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 84c95c9a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/sysctl.h>
#include <asm/uaccess.h>
#include <linux/module.h>
@@ -1178,7 +1179,7 @@ debug_get_uint(char *buf)
{
	int rc;

	for(; isspace(*buf); buf++);
	buf = skip_spaces(buf);
	rc = simple_strtoul(buf, &buf, 10);
	if(*buf){
		rc = -EINVAL;
+7 −9
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

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

	ptr += strlen("proc");
	while (isspace(*ptr)) ptr++;
	ptr = skip_spaces(ptr);

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

	ptr += strlen("proc");
	while (isspace(*ptr))
		ptr++;
	ptr = skip_spaces(ptr);
	snprintf(path, sizeof(path), "/proc/%s", ptr);

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

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

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

	ptr += strlen("sysrq");
	while (isspace(*ptr)) ptr++;
	ptr = skip_spaces(ptr);

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

	ptr += strlen("stack");
	while (isspace(*ptr))
		ptr++;
	ptr = skip_spaces(ptr);

	/*
	 * Should really check for multiple pids or reject bad args here
+4 −7
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
#include <linux/proc_fs.h>
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/init.h>

#define LINE_SIZE 80
@@ -133,8 +134,7 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
		return -EINVAL;

	base = simple_strtoull(line + 5, &ptr, 0);
	while (isspace(*ptr))
		ptr++;
	ptr = skip_spaces(ptr);

	if (strncmp(ptr, "size=", 5))
		return -EINVAL;
@@ -142,14 +142,11 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
	size = simple_strtoull(ptr + 5, &ptr, 0);
	if ((base & 0xfff) || (size & 0xfff))
		return -EINVAL;
	while (isspace(*ptr))
		ptr++;
	ptr = skip_spaces(ptr);

	if (strncmp(ptr, "type=", 5))
		return -EINVAL;
	ptr += 5;
	while (isspace(*ptr))
		ptr++;
	ptr = skip_spaces(ptr + 5);

	for (i = 0; i < MTRR_NUM_TYPES; ++i) {
		if (strcmp(ptr, mtrr_strings[i]))
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ static ssize_t led_brightness_store(struct device *dev,
	unsigned long state = simple_strtoul(buf, &after, 10);
	size_t count = after - buf;

	if (*after && isspace(*after))
	if (isspace(*after))
		count++;

	if (count == size) {
+2 −2
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ static ssize_t led_delay_on_store(struct device *dev,
	unsigned long state = simple_strtoul(buf, &after, 10);
	size_t count = after - buf;

	if (*after && isspace(*after))
	if (isspace(*after))
		count++;

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

	if (*after && isspace(*after))
	if (isspace(*after))
		count++;

	if (count == size) {
Loading