From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D196FEE642A for ; Thu, 12 Sep 2024 04:28:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA5136B009A; Thu, 12 Sep 2024 00:28:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E55206B009B; Thu, 12 Sep 2024 00:28:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D43C66B009D; Thu, 12 Sep 2024 00:28:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B707F6B009A for ; Thu, 12 Sep 2024 00:28:58 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0BA671C5383 for ; Thu, 12 Sep 2024 04:28:58 +0000 (UTC) X-FDA: 82554805956.12.B4E2C1A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 12A0540005 for ; Thu, 12 Sep 2024 04:28:55 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726115283; a=rsa-sha256; cv=none; b=MKGbpCR7QB1Vqz6qHojAkr2g5i+BNCPfJdSTacoIBgdHh2iEK0iNaiM42MpECJ89Wi0Qo3 RgqT4XRdOdOTZi3nXjij40I52XfaherYpzrAQM9cqvATZ2MrArHN1TVYwheFnJVso4euJu C+bbIqFWPLT70Opne3PuRlFygVmIiKI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726115283; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mze5SkpuVYmeHJJty4FTf3ekLwZUlgH37pWCndKxDaI=; b=YGD3s4IiVvaZwkK3mjl88W+MS2CoCGrryuCs8PJ94jVtejHb3SJ03tglLOCLEBzYvwpC8N DlOFIYDAv5j41e0Dem4Vp3tJmbtSITELsuMY4tMgSoA3bG+sJbwJFrVKLtHQN8B7JC+VVc WB0xYiWSUMP8ZQSAZxps793f9Ia+U7s= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 86A70DA7; Wed, 11 Sep 2024 21:29:24 -0700 (PDT) Received: from [10.162.41.18] (e116581.arm.com [10.162.41.18]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BA4C53F73B; Wed, 11 Sep 2024 21:28:53 -0700 (PDT) Message-ID: <09efaf91-4d85-47c9-857f-94f1a9c9bce8@arm.com> Date: Thu, 12 Sep 2024 09:58:50 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RESEND] tools/mm: Use calloc and check the memory allocation failure To: Zhu Jun , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240912032457.2780-1-zhujun2@cmss.chinamobile.com> Content-Language: en-US From: Dev Jain In-Reply-To: <20240912032457.2780-1-zhujun2@cmss.chinamobile.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: 87i41w4ngckj469ug4jstfcrnfze15iw X-Rspamd-Queue-Id: 12A0540005 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1726115335-838746 X-HE-Meta: U2FsdGVkX1+YyNd7xgLoDKa6Y9MHfnG5b2IHT40HokX578RFL2V/o3+rMlijqy0YamVVhS/ci/gYU6aAjKmuXxL1eK2eo/rG0yMd3dIC30VT5Co3ZjFjwJk2ZKCKJJURFeutIHLCWao/oNpzO9YKXOUaPwCns4zjo6Wv9edagDATyM2Yf2Ls//nmlgW9wgHjcU8a3/ypHIlSpa/6D5GlqWYd0TFAsLhajxO8oSHdOfZFoJkUaGoDQb+sp/a8VhMQ6Bj0bsDUQmBx9kizzPdXR40iZnPUZSy85zyx0837KwnOZLc5Mi2PuO1BWv3drVAyylvX+HCzW/dknUBXbw+4KpoEglHBtfuz9kY2c7x8rP96Rjh+eS8Bx9yGINh0aP8St3jjOZMRvWnnH73le4gst394rsIi3/nr4j6YGwv0arniGZ9NAxBHINLu7mMp/LeRaMAI/lMfEJFPkp6WfmsVBolffB6VF3vlzlw++rnv11MQejVh2FgDV8uN4dvYmMcX+ketcSHDRODihJ7ybV7U0inyEKIDOPJvg9KkCjQLGf9hSe4ZdNzxzfMlvUm/U8zR2y9dAh2OFTHeeUTQqZ6v79aZ+/fNwoR60OR795nYWDoVO8LRniwwjWQUxCbEWAQ0Os0VxTxojkH4IP3a50UcB/zBjjeI6AualgfsjkIP+kZEnz+Hciea0ndsEWFmvEGo4vJlupzRVNHRkNsHD6+WVOH8Jzed696PBhN1AZ7V33tyDElkgIo2FaAqdUmS74XfN1ouum8Yua7IZyX8exTgh5eZfsO90oBu44LQDw5cB8dkYxvt3FNF8kGe1eo0BcdUQKfoe4/f+LBmpH6LVftAskDsVYI3mPTwE2/T1UT6WMdBNUJjZQcfc4w12O52dy7MfzMHkYfam0L82qo98Et7VTIAUQYKSbebubN00rrDbUQ3jAfvVirw34N+nxMhu4pZER0F4WHp1OZc2QqSpeV w4ep6GZp tDXtENPlppEKb5kTWEC76MPS/D569eC3vUyDDcHyEF8fG7DoFysmgeRjuv/71jsrJFMI9sP7VUoQl+v4aCQpDpSGxmNb47gfhJMs//dQP2EoaBJOyyDbzW3k6JLJ73X1YGkNv/Y0hv5MMnFPSX3r68a1Athoy7jKwCco4AQmZ0xJjerAfMV4L8LMizZ6dukY/AjwVyK/oo5fpl9o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 9/12/24 08:54, Zhu Jun wrote: > Replace malloc with calloc and add null pointer check > in case of allocation failure. > > Signed-off-by: Zhu Jun > --- > tools/mm/page_owner_sort.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c > index e1f264444342..8c78265cef67 100644 > --- a/tools/mm/page_owner_sort.c > +++ b/tools/mm/page_owner_sort.c > @@ -368,9 +368,10 @@ static __u64 get_ts_nsec(char *buf) > > static char *get_comm(char *buf) > { > - char *comm_str = malloc(TASK_COMM_LEN); > + char *comm_str = calloc(TASK_COMM_LEN, sizeof(char)); > > - memset(comm_str, 0, TASK_COMM_LEN); > + if (!comm_str) > + return NULL; > > search_pattern(&comm_pattern, comm_str, buf); > errno = 0; Hello Zhu, It is pointless to resend if you haven't addressed the queries raised by Andrew. He notes that the callers aren't handling a possible NULL return, so there is no point in even checking for a mem alloc failure. I haven't wandered in tools/mm but from a programming PoV what Andrew says is correct...if you are returning NULL then you also must decide what to do with that in the caller, and so on, on which I cannot comment :)