From patchwork Thu Sep 12 03:24:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Jun X-Patchwork-Id: 13801333 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 375D4EDE996 for ; Thu, 12 Sep 2024 03:25:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEF2E6B009F; Wed, 11 Sep 2024 23:25:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9DF26B00A1; Wed, 11 Sep 2024 23:25:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 966566B00A3; Wed, 11 Sep 2024 23:25:08 -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 794786B009F for ; Wed, 11 Sep 2024 23:25:08 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2420441210 for ; Thu, 12 Sep 2024 03:25:08 +0000 (UTC) X-FDA: 82554645096.12.653A70D Received: from cmccmta3.chinamobile.com (cmccmta6.chinamobile.com [111.22.67.139]) by imf19.hostedemail.com (Postfix) with ESMTP id E104C1A0004 for ; Thu, 12 Sep 2024 03:25:04 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of zhujun2@cmss.chinamobile.com designates 111.22.67.139 as permitted sender) smtp.mailfrom=zhujun2@cmss.chinamobile.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726111401; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=RYPP5QOCy/qsdETtSUPjZKhg8i4AKwXoC+GsxmwX/zY=; b=sMmVEVoRNt4db7R6WblvRVqsDbuInGAsgZEaUDGCmkTf+MAVclSKrCSCOxO7FRpy4DOasO ICZPWU3c01CwOBdufI7Fh1m4rM25O5e++2ZkL5zR5oPVwRKbo/r6SpxzxPSN6/jj78MH0K I31Epkd6ssWh9lad3YEdsJfXl7+dcLc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726111401; a=rsa-sha256; cv=none; b=hgs2DlZ2z+y2NMaVeHiuOqNPp+FJilr+jS8AUeFV4KwSQFe31qGQFhX3yS7AawWkdQcV3I 7STL2fQ7iFxzDrJfEkh1Ua0cnJ5Wv5aJhWMeJXBYfV1ZQHjqGz+BgYSh8Yp2reaqT/qtSB cd+RQIz8FssMRbxFgJ7g+ELQaMqwKbk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of zhujun2@cmss.chinamobile.com designates 111.22.67.139 as permitted sender) smtp.mailfrom=zhujun2@cmss.chinamobile.com; dmarc=none X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app09-12009 (RichMail) with SMTP id 2ee966e25f0d438-2a43c; Thu, 12 Sep 2024 11:25:01 +0800 (CST) X-RM-TRANSID: 2ee966e25f0d438-2a43c X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from ubuntu.localdomain (unknown[10.54.5.255]) by rmsmtp-syy-appsvr01-12001 (RichMail) with SMTP id 2ee166e25f0ceb5-fcb7b; Thu, 12 Sep 2024 11:25:01 +0800 (CST) X-RM-TRANSID: 2ee166e25f0ceb5-fcb7b From: Zhu Jun To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhujun2@cmss.chinamobile.com Subject: [RESEND] tools/mm: Use calloc and check the memory allocation failure Date: Wed, 11 Sep 2024 20:24:57 -0700 Message-Id: <20240912032457.2780-1-zhujun2@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E104C1A0004 X-Stat-Signature: iidjubr9wi6wcc85jmy5kfumfxqokqau X-HE-Tag: 1726111504-193407 X-HE-Meta: U2FsdGVkX18GYIUT/KLY2yjtom14T+iLENU6x5Zdo2+6Z2WzXeAZz/GB0wSHoMtGzWJaXYyaa6mlylERa09R/naAclXsOcf8pncC2o5stxTLTSNn2rS0cymKMB61SnXEFgRxEOhfPzwo6VbEjDrY7vBqfjMfv3Px2JOKyKhBSpASJEYpyJeSpsfjwSpMhcPlBewfjURQJY3Q04ri6kchqHb+ZpRrsw2vNkBEnjfocbaHZYZ6IvFyZ6E6ICc8S9KrVZdJxtY6NvqNC7+vO8QScXrOzJSVcLtkeCMKs+YO1Diugj+lTzYJbNbjLB5nDhBSDH2hJD3oVIzkuT+VCYZmwXAF2hY1tz4BQtlBhxTtKRs72t3nrO/SO4nmPGiR7JITm+EfE7106yE3VMhVBxE5CBiedu47uHDoMSIr7MoXYHsJilZ3MTyrG7H9K39O7Mn00cX3zy9ZHEunoYwIBfP2pTOBJJTHbtm9cj02DPqDfWheooNqmAWKE5OBicnk4oJPf3HHEC/bz7QdIIcmyYiHNyO3buGqjFDBNDpVPfmnxpYYNWeHETVzBujUHhVTE6NCces5OntGBRojqD28PNEHm07zXAtZPbxFtep+mv3tEVXjPzlVOUWdEMCj5pbMzytLR3kU0olGAPkNiOKQosrpf59s+xZ0RUFojFuxJIjKtMBpcnSplkfrTgir/4zNhH/otor22f5dOZpS9p3ckaxusv0Ykcjvl8X6YZZ5haK1LgBL3VAQpmQsfB/ENmDaErq1JaxbDRntKKs9sDid8psMRn8hZ/cy2LJsINEVu6y+66bRCNa0aInClUA+eQNmZtZoD4Ftn/QAEFRasLWu6qNWllr8sXNkxJCcPoOvKn54O+yDMjdhsfmrmefMFBakkMwPAM95ERtqIBaUWDFIZaU+xpZXs32Hp3cf5ip5jhT67p853uH6BgvinemIxcqMZ7vQpnCPq6aordFshA00/4X Wk+r6GU9 hZMLDzwcH3ASS6tMzdyTBFGsRlg== 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: 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;