mm, vmpressure: use kstrndup instead of kmalloc+strncpy
Subsystems (2)
PATCH 1/1 mm, vmpressure: use kstrndup instead of kmalloc+strncpy
Using kstrndup() simplifies the code.
Signed-off-by Andy Shevchenko <[email protected]>
--- mm/vmpressure.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/vmpressure.c +1 -2
@@ -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,"," );
Signature · 1 line
2.17.0
Quoted 1 line · Andy Shevchenko
Using
kstrndup()simplifies the code.
if for nothing else then the len+1 being handled by kstrndup is an improvement.
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>
Acked-by Michal Hocko <[email protected]>
Quoted 24 lines
--- mm/vmpressure.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/vmpressure.c +1
-2@@ -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,"," );Signature · 1 line
2.17.0
Signature · 2 lines
Michal Hocko SUSE Labs