Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp131493ybv; Wed, 12 Feb 2020 20:51:52 -0800 (PST) X-Google-Smtp-Source: APXvYqx4yt3cfem6FurZfdXI4PmorB+t2WxBmuipfL8p818eYRwUqBrOJ7keRdAnSCvIip6/0Sce X-Received: by 2002:a9d:f45:: with SMTP id 63mr12459732ott.0.1581569512231; Wed, 12 Feb 2020 20:51:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581569512; cv=none; d=google.com; s=arc-20160816; b=MUG5hRgHPR2wXSHtmYvNTZADSbC/ME15mPQEpOfogvltLz0DdhslQ7ynuL0pjaahEc eo1YMU+IX8GOLLLP7iaHajW+zh8wB06GRUP4Xtn1aIVqd8Tk4SgrKw078DM9wdUmJS3u f3fc6MaNunZzSUKYEfoNTpreTbKjte8ztP0iOaNnngTy3TnoebbQzZjDNthe3BEoWozQ fZTvDjfCk09iiOOhSk6bBE4QdgMo3wOQ2FSEsNzhIRvYmEEfk8rulr3O0s2CQan+fteS Rn3d0oPBbTB5gdbT3cXalpesKCToOwdJJwAawkqR7j6smGcLZHTEi7aKGj7wMAl7XFQB I5QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=v/2zqlPxwjc8kkJ/cA3Ekg3gLou24FZPqgJ7R+WUJ6k=; b=tCEAHIdmtgmsJ2Rg7psYG1Rev+ca+lxbhgGoKi34bUQ6pdxDNgXrWClmi2WYjyKBzb COS62UzeTxM5NjHqZyVlhwLHiiz5ZEDWYEqFvIMkVWhdZXEMrJbKKQkGzxQZg5F7ZCS3 q37U9/JikFhydAFdSDd5bd/7RsLcPp1bZsoubwgD7CQBXG3CdY/XcxR7PEUB4JwZnwVV h7+9nwWCjbojI3jBb4Y3hoSWjuR/l7ndpmZVMUEppW+gNWUJvnVTWUtovITdavm63ppN Rxwc6MAQgm0Mr7r7aPzc25ROY7RW77ZZUC+5YuVDCTDpxxDuiodflgJNJKKfLDLmS79H 6Cig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t24si594703oth.319.2020.02.12.20.51.39; Wed, 12 Feb 2020 20:51:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729406AbgBMEva (ORCPT + 99 others); Wed, 12 Feb 2020 23:51:30 -0500 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:45761 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727076AbgBMEv3 (ORCPT ); Wed, 12 Feb 2020 23:51:29 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R671e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04455;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0TpsO4JW_1581569484; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TpsO4JW_1581569484) by smtp.aliyun-inc.com(127.0.0.1); Thu, 13 Feb 2020 12:51:25 +0800 Subject: Re: [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails To: Andrew Morton Cc: David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1581398649-125989-1-git-send-email-yang.shi@linux.alibaba.com> <48d53caf-4b89-69c3-cf9b-47b8627db0bd@linux.alibaba.com> <20200212204827.df1de9015a3c03c79a8d7155@linux-foundation.org> From: Yang Shi Message-ID: Date: Wed, 12 Feb 2020 20:51:22 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20200212204827.df1de9015a3c03c79a8d7155@linux-foundation.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/12/20 8:48 PM, Andrew Morton wrote: > On Wed, 12 Feb 2020 19:14:27 -0800 Yang Shi wrote: > >> On 2/12/20 3:21 AM, David Hildenbrand wrote: >>> On 11.02.20 06:24, Yang Shi wrote: >>>> When kstrndup fails (returns NULL) there is no memory is allocated by >>>> kmalloc, so no need to call kfree(). >>> "When kstrndup fails, no memory was allocated and we can exit directly." >> Thanks for correcting the commit log. >> >> Andrew, do you prefer I send an updated version or you would just update >> the patch in -mm tree? > I have already done this. Thanks! > > From: Yang Shi > Subject: mm: vmpressure: don't need call kfree if kstrndup fails > > When kstrndup fails, no memory was allocated and we can exit directly. > > [david@redhat.com: reword changelog] > Link: http://lkml.kernel.org/r/1581398649-125989-1-git-send-email-yang.shi@linux.alibaba.com > Signed-off-by: Yang Shi > Reviewed-by: Andrew Morton > Reviewed-by: David Hildenbrand > Acked-by: David Rientjes > Signed-off-by: Andrew Morton > --- > > 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, ","); > _