From 30f7bc99a2a97cce9cda17d411c748550c0ece7b Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 30 Oct 2018 15:05:22 -0700 Subject: lib/parser.c: switch match_strdup() over to use kmemdup_nul() This simplifies the code. No change in behavior. Link: http://lkml.kernel.org/r/20180830194436.188867-1-ebiggers@kernel.org Signed-off-by: Eric Biggers Reviewed-by: Andrew Morton Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- lib/parser.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'lib/parser.c') diff --git a/lib/parser.c b/lib/parser.c index 3278958b472a..0142ef28f0eb 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -327,10 +327,6 @@ EXPORT_SYMBOL(match_strlcpy); */ char *match_strdup(const substring_t *s) { - size_t sz = s->to - s->from + 1; - char *p = kmalloc(sz, GFP_KERNEL); - if (p) - match_strlcpy(p, s, sz); - return p; + return kmemdup_nul(s->from, s->to - s->from, GFP_KERNEL); } EXPORT_SYMBOL(match_strdup); -- cgit v1.2.3 From 4ed97b3c6d088e063e065142fc3217fae5cc29f8 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 30 Oct 2018 15:05:26 -0700 Subject: lib/parser.c: switch match_u64int() over to use match_strdup() This simplifies the code. No change in behavior. Link: http://lkml.kernel.org/r/20180830194814.192880-1-ebiggers@kernel.org Signed-off-by: Eric Biggers Reviewed-by: Andrew Morton Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- lib/parser.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib/parser.c') diff --git a/lib/parser.c b/lib/parser.c index 0142ef28f0eb..618c36ec8efe 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -166,13 +166,10 @@ static int match_u64int(substring_t *s, u64 *result, int base) char *buf; int ret; u64 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 = kstrtoull(buf, base, &val); if (!ret) -- cgit v1.2.3 From 36c8d1e7a27f94b4d812b2a0abf106dab0fa377e Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 30 Oct 2018 15:05:30 -0700 Subject: lib/parser.c: switch match_number() over to use match_strdup() This simplifies the code. No change in behavior. Link: http://lkml.kernel.org/r/20180830194727.191555-1-ebiggers@kernel.org Signed-off-by: Eric Biggers Reviewed-by: Andrew Morton Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- lib/parser.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib/parser.c') diff --git a/lib/parser.c b/lib/parser.c index 618c36ec8efe..dd70e5e6c9e2 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -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); -- cgit v1.2.3