On Wed, 12 Feb 2020 19:14:27 -0800 Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx> wrote:
On 2/12/20 3:21 AM, David Hildenbrand wrote:I have already done this.
On 11.02.20 06:24, Yang Shi wrote:Thanks for correcting the commit log.
When kstrndup fails (returns NULL) there is no memory is allocated by"When kstrndup fails, no memory was allocated and we can exit directly."
kmalloc, so no need to call kfree().
Andrew, do you prefer I send an updated version or you would just update
the patch in -mm tree?
From: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx>
Subject: mm: vmpressure: don't need call kfree if kstrndup fails
When kstrndup fails, no memory was allocated and we can exit directly.
[david@xxxxxxxxxx: reword changelog]
Link: http://lkml.kernel.org/r/1581398649-125989-1-git-send-email-yang.shi@xxxxxxxxxxxxxxxxx
Signed-off-by: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx>
Reviewed-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Reviewed-by: David Hildenbrand <david@xxxxxxxxxx>
Acked-by: David Rientjes <rientjes@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---
mm/vmpressure.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
--- a/mm/vmpressure.c~mm-vmpressure-dont-need-call-kfree-if-kstrndup-fails
+++ a/mm/vmpressure.c
@@ -371,10 +371,8 @@ int vmpressure_register_event(struct mem
int ret = 0;
spec_orig = spec = kstrndup(args, MAX_VMPRESSURE_ARGS_LEN, GFP_KERNEL);
- if (!spec) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!spec)
+ return -ENOMEM;
/* Find required level */
token = strsep(&spec, ",");
_