Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp129750ybv; Wed, 12 Feb 2020 20:49:17 -0800 (PST) X-Google-Smtp-Source: APXvYqwxPr74MAPC8OJ+HtNihqHg8ZN6/Pk5//nUuEZHKwYZqltHScA3S9orkjjT9NnkPy9iwcOV X-Received: by 2002:a9d:2264:: with SMTP id o91mr12012981ota.328.1581569357598; Wed, 12 Feb 2020 20:49:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581569357; cv=none; d=google.com; s=arc-20160816; b=RH/FNNs/11gaXnf4u8xl/TyP/GuqTBSlqzXu9Jpe/wtiHlM9cx2gvs7KrAWCdRXONn SWgMPF3CmzeL3d+plJPXqELAnUFaxd/JPilbQwvN1zoXJye128nGx9qcdz2/pjNwQL77 pfVosJ9iu/DH8QNbN3IE+7IR0IdlL2J21Xu6umLrTz4b55S2zCN58WFjvfjW3GYf0KVX MeO3nGtnkNOECxmclrGbBRd2643yX3sGt/uWfZ+pii2i9CUXROlr1V2UEvoB9DOAJzME +gYUtuO+sIhITBmZY7Sq0UqhxpE3GkCyt3O9VMh8IPlfk1mcHyxUm5f4u1a4czhmDvz8 WN+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=7/CcunjhfTtGVig8//wEMG7B6RExVxi+D/D2nkNmQZU=; b=Kaab7PZpzVBHzwjzOoevubBkT/nZHckvKz7XSM9JVgQ6hFsm14KOEcLoAPtPT2oQQA kNlO0Ypqhvqb1yQUPRcXbMBRKQ/8nEVJql6NMibeBI2dpwurSa1nHTEKU8QE9w3YD5FE 9UyVRuyhW3yrOpYmF07wDrH1/9aba/iyfubm+byYa/0W2VX2cT0GHVwc4wfO7FZ9bugw KKx4zh3D+fvdt/2CHKcxGugZhRdVZQxeQ9ikWelduod7+uXaGJy2p2o9e0ZDSEwHOiS0 hutH6HmcWkE+CMUjwd82JYY9JZXEXWua0uotYVtdg/xvnG96NSLrv3wp5F0rPlHKiDDQ gt/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jh1EgfLf; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h203si641420oif.3.2020.02.12.20.49.04; Wed, 12 Feb 2020 20:49:17 -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; dkim=pass header.i=@kernel.org header.s=default header.b=jh1EgfLf; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729413AbgBMEsa (ORCPT + 99 others); Wed, 12 Feb 2020 23:48:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:42728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727076AbgBMEsa (ORCPT ); Wed, 12 Feb 2020 23:48:30 -0500 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6AA5D206DB; Thu, 13 Feb 2020 04:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581569308; bh=6XgnjQAmLJi/ywxNwipKTQhR87xeEOBguUpFp+51AZE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jh1EgfLfdu4815kbBoKihNSuOoGATxgqPZ4iw0rzQQ2ZqhT7JMSZ0mIJ45bEw4bi7 saPkUFAAcU7OLbMBK2Qtr1gD6VnqpipJJgjch+psQ0Bq5IBwAnYKrohld7tKKVe5is yx2uJL66693LcBnPC2ulCOcnA949yPgj0xr47W5w= Date: Wed, 12 Feb 2020 20:48:27 -0800 From: Andrew Morton To: Yang Shi Cc: David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] mm: vmpressure: don't need call kfree if kstrndup fails Message-Id: <20200212204827.df1de9015a3c03c79a8d7155@linux-foundation.org> In-Reply-To: <48d53caf-4b89-69c3-cf9b-47b8627db0bd@linux.alibaba.com> References: <1581398649-125989-1-git-send-email-yang.shi@linux.alibaba.com> <48d53caf-4b89-69c3-cf9b-47b8627db0bd@linux.alibaba.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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, ","); _