Skip to contentSkip to conversation

lib/parser.c: switch match_number() over to use match_strdup()

PATCH In review Eric Biggers 1 participant 2 messages Aug 30, 2018 – Sep 5, 2018 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/parser.c: switch match_number() over to use match_strdup()

From: Eric Biggers <[email protected]>

This simplifies the code. No change in behavior.

---
 lib/parser.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
lib/parser.c +1 -4
index 0142ef28f0eb..96656a6dd59b 100644
@@ -131,13 +131,10 @@ static int match_number(substring_t *s, int *result, int base)
 	char *buf;
 	int ret;
 	long val;
-	size_t len = s->to - s->from;
 
-	buf = kmalloc(len + 1, GFP_KERNEL);
+	buf = match_strdup(s);
 	if (!buf)
 		return -ENOMEM;
-	memcpy(buf, s->from, len);
-	buf[len] = '\0';
 
 	ret = 0;
 	val = simple_strtol(buf, &endp, base);
Signature · 1 line
2.19.0.rc0.228.g281dcd1b4d0-goog
#1 lore raw
Quoted 19 lines · Eric Biggers

From: Eric Biggers <[email protected]>

This simplifies the code. No change in behavior.

---
 lib/parser.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
lib/parser.c +0 -1
index 0142ef28f0eb..96656a6dd59b 100644
@@ -131,13 +131,10 @@ static int match_number(substring_t *s, int *result, int base)
 	char *buf;
 	int ret;
 	long val;
-	size_t len = s->to - s->from;

lib/parser.c static int match_number(substring_t *s, int *result, int base) · line 140

Quoted 10 lines
lib/parser.c +1 -3
 
-	buf = kmalloc(len + 1, GFP_KERNEL);
+	buf = match_strdup(s);
 	if (!buf)
 		return -ENOMEM;
-	memcpy(buf, s->from, len);
-	buf[len] = '\0';
 
 	ret = 0;
 	val = simple_strtol(buf, &endp, base);

Hi Andrew, are you planning to take this patch too? The similar patch

lib/parser.c: switch match_u64int() over to use match_strdup()

is in -mm now, but this one is not.

Thanks,

- Eric