Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp63799ybv; Wed, 12 Feb 2020 19:15:54 -0800 (PST) X-Google-Smtp-Source: APXvYqz+sWXF6JbtZkdnegFbOD3hkMEl024ObDMoDZBAqt4LG3NMB0oZMX0bjaqpM8SDXPJ2TQ7H X-Received: by 2002:a9d:32f:: with SMTP id 44mr11442602otv.234.1581563754545; Wed, 12 Feb 2020 19:15:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581563754; cv=none; d=google.com; s=arc-20160816; b=i9XMn6HVI2LH3FhkZBCdbVmfC4R/4X1Ql2OKeu8DmlRremL6+SiShQNUS0IHkzS7Te ZZ0lCtCISMyNG1b7scUOybg1Dgkj5/4oL//6003eY9+SbHdlGFQno4zxibXjF0Mf6v2c c59nZnbFIJQW7FPJ3PCVQ/ShIS4pTeYpJL1GziDOECayo4xF4uZeIhiak5ilyMIDTXF9 s1WjipJDJgRTM5wVXuzwBZYNRN/M8S+wyNJikQD4InVm6k304El9rD867YKZ2BK7szji +mjKP3uRzPBaqr9oa1oz+6HVFFCzUTUpRfN+gUtNvLgt1tfxdrL2JOiBb9bngTNxb284 8Gng== 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=IG/tKbHhvyJw+pV+hMpdsdvyCBbc6q8k4N93KUzAJ1A=; b=m7zctgZNCokp9ZNoeg8HIXHtMjrZYx2Rd5aHx7kpz1ja/eLwlBqHyqBrXV0QtWwJMe J/HWOHzxdhdPJ1g/s31hQHIiynoXiXWXJCTwkVBMoiKuYWPBAb1BQYRI2kuRbMqLl/AM Kt8B0M34oMG0MVGQcoHG6UnjqxvpeztjL55SGkOrFsxPEjL+pYk4mLXMDcN7A0tuuW29 79jPsRB7MnmwgozXJQtnySX2fpn2KfOPNCByCUEcOeG8vu1Yton7DUqjNiFsobPbEyoP 3wDFWL2RSmN8XuWlg/NHn2bw2MS54N44gdhs98/kWehHs1YVSFX19Z9IPMii4oJT5f97 IKyA== 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 d8si410287otp.295.2020.02.12.19.15.41; Wed, 12 Feb 2020 19:15:54 -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 S1729471AbgBMDOe (ORCPT + 99 others); Wed, 12 Feb 2020 22:14:34 -0500 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:43817 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729378AbgBMDOe (ORCPT ); Wed, 12 Feb 2020 22:14:34 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R861e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0TprWUQG_1581563668; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TprWUQG_1581563668) by smtp.aliyun-inc.com(127.0.0.1); Thu, 13 Feb 2020 11:14:30 +0800 Subject: Re: [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails To: David Hildenbrand , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1581398649-125989-1-git-send-email-yang.shi@linux.alibaba.com> From: Yang Shi Message-ID: <48d53caf-4b89-69c3-cf9b-47b8627db0bd@linux.alibaba.com> Date: Wed, 12 Feb 2020 19:14:27 -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: Content-Type: text/plain; charset=windows-1252; 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 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? > > Reviewed-by: David Hildenbrand > >> Signed-off-by: Yang Shi >> --- >> mm/vmpressure.c | 6 ++---- >> 1 file changed, 2 insertions(+), 4 deletions(-) >> >> diff --git a/mm/vmpressure.c b/mm/vmpressure.c >> index 4bac22f..0590f00 100644 >> --- a/mm/vmpressure.c >> +++ b/mm/vmpressure.c >> @@ -371,10 +371,8 @@ int vmpressure_register_event(struct mem_cgroup *memcg, >> 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, ","); >> >