* [PATCH] lib/parser.c: switch match_strdup() over to use kmemdup_nul()
@ 2018-08-30 19:44 Eric Biggers
2018-08-30 23:19 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2018-08-30 19:44 UTC (permalink / raw)
To: linux-kernel, Andrew Morton; +Cc: Eric Biggers
From: Eric Biggers <ebiggers@google.com>
This simplifies the code. No change in behavior.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
lib/parser.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
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);
--
2.19.0.rc0.228.g281dcd1b4d0-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lib/parser.c: switch match_strdup() over to use kmemdup_nul()
2018-08-30 19:44 [PATCH] lib/parser.c: switch match_strdup() over to use kmemdup_nul() Eric Biggers
@ 2018-08-30 23:19 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2018-08-30 23:19 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-kernel
On Thu, 30 Aug 2018 12:44:36 -0700 Eric Biggers <ebiggers@kernel.org> wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> This simplifies the code. No change in behavior.
>
> ...
>
> --- 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);
Huh. I never noticed kmemdup_nul() fly past - it rather happened on
the sly. We do have some fun goodies in there.
We could make match_strdup() an inline now. But that will probably
produce a fatter kernel, as each callsite would then need to prepare
three args rather than one.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-08-30 23:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-30 19:44 [PATCH] lib/parser.c: switch match_strdup() over to use kmemdup_nul() Eric Biggers
2018-08-30 23:19 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox