* [PATCH v1] mm, vmpressure: use kstrndup instead of kmalloc+strncpy
@ 2018-05-03 20:18 Andy Shevchenko
2018-05-04 11:45 ` Michal Hocko
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2018-05-03 20:18 UTC (permalink / raw)
To: David Rientjes, linux-mm, Andrew Morton; +Cc: Andy Shevchenko
Using kstrndup() simplifies the code.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
mm/vmpressure.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 85350ce2d25d..7142207224d3 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -390,12 +390,11 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
char *token;
int ret = 0;
- spec_orig = spec = kzalloc(MAX_VMPRESSURE_ARGS_LEN + 1, GFP_KERNEL);
+ spec_orig = spec = kstrndup(args, MAX_VMPRESSURE_ARGS_LEN, GFP_KERNEL);
if (!spec) {
ret = -ENOMEM;
goto out;
}
- strncpy(spec, args, MAX_VMPRESSURE_ARGS_LEN);
/* Find required level */
token = strsep(&spec, ",");
--
2.17.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] mm, vmpressure: use kstrndup instead of kmalloc+strncpy
2018-05-03 20:18 [PATCH v1] mm, vmpressure: use kstrndup instead of kmalloc+strncpy Andy Shevchenko
@ 2018-05-04 11:45 ` Michal Hocko
0 siblings, 0 replies; 2+ messages in thread
From: Michal Hocko @ 2018-05-04 11:45 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: David Rientjes, linux-mm, Andrew Morton
On Thu 03-05-18 23:18:07, Andy Shevchenko wrote:
> Using kstrndup() simplifies the code.
if for nothing else then the len+1 being handled by kstrndup is an
improvement.
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> mm/vmpressure.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/vmpressure.c b/mm/vmpressure.c
> index 85350ce2d25d..7142207224d3 100644
> --- a/mm/vmpressure.c
> +++ b/mm/vmpressure.c
> @@ -390,12 +390,11 @@ int vmpressure_register_event(struct mem_cgroup *memcg,
> char *token;
> int ret = 0;
>
> - spec_orig = spec = kzalloc(MAX_VMPRESSURE_ARGS_LEN + 1, GFP_KERNEL);
> + spec_orig = spec = kstrndup(args, MAX_VMPRESSURE_ARGS_LEN, GFP_KERNEL);
> if (!spec) {
> ret = -ENOMEM;
> goto out;
> }
> - strncpy(spec, args, MAX_VMPRESSURE_ARGS_LEN);
>
> /* Find required level */
> token = strsep(&spec, ",");
> --
> 2.17.0
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-04 11:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-03 20:18 [PATCH v1] mm, vmpressure: use kstrndup instead of kmalloc+strncpy Andy Shevchenko
2018-05-04 11:45 ` Michal Hocko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).