From patchwork Fri Sep 6 09: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: 13793734 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 6F3BECE7AF1 for ; Fri, 6 Sep 2024 09:25:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4BC66B0082; Fri, 6 Sep 2024 05:25:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFC2C6B0088; Fri, 6 Sep 2024 05:25:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEA296B0089; Fri, 6 Sep 2024 05:25:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B5CF26B0082 for ; Fri, 6 Sep 2024 05:25:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 58DDE161207 for ; Fri, 6 Sep 2024 09:25:04 +0000 (UTC) X-FDA: 82533779328.22.B798A4F Received: from cmccmta2.chinamobile.com (cmccmta8.chinamobile.com [111.22.67.151]) by imf16.hostedemail.com (Postfix) with ESMTP id 660FC180012 for ; Fri, 6 Sep 2024 09:25:01 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of zhujun2@cmss.chinamobile.com designates 111.22.67.151 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=1725614653; 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=Y1DYzQawkws4XSdwtdWm0lN+ngmkESVLBqjitZjAn5Grk7dARmxnDT7LZ64VtW7YaXjMzv tOFiGcaQNarNCmLkoWcZXkkTewMzCkkSl5IbXqePbYstekzLLRQHOk9jF5PQ+XGIZrmLvE UqPnwQ/cTNXM6MXDcPdKX9oRHEXIyy0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of zhujun2@cmss.chinamobile.com designates 111.22.67.151 as permitted sender) smtp.mailfrom=zhujun2@cmss.chinamobile.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725614653; a=rsa-sha256; cv=none; b=n0D56uM/2qVO1bswndg/YCucMlNiaUngFttwF/omc6zV/lYidCp3/57nBPHCWvnWy1KF/l ckrWB0CJZ+4BLePEWmyqhmtlfzKz3SRWPWAkghp8zC1eB5tXNJg6AWHVfzGpUDyLNigS4w xD/cKjhi+5nsu46+UXz/AVtU9L9J6fk= 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-app06-12006 (RichMail) with SMTP id 2ee666daca68e47-c6709; Fri, 06 Sep 2024 17:24:59 +0800 (CST) X-RM-TRANSID: 2ee666daca68e47-c6709 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from ubuntu.localdomain (unknown[10.54.5.255]) by rmsmtp-syy-appsvr05-12005 (RichMail) with SMTP id 2ee566daca6ae10-a2d31; Fri, 06 Sep 2024 17:24:59 +0800 (CST) X-RM-TRANSID: 2ee566daca6ae10-a2d31 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: Fri, 6 Sep 2024 02:24:57 -0700 Message-Id: <20240906092457.11581-1-zhujun2@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 660FC180012 X-Stat-Signature: kygueg9qccnnpzajzptxbbi4rmiemddz X-HE-Tag: 1725614701-627375 X-HE-Meta: U2FsdGVkX1/OZWYq2hR22YBdHQR/V1C3+LQvRX5qJ0c6i75GZBj8xSu1uOvvi+yjKFO7CmAIEl4oGD/HQRnlKShLE4mQCOfKoidwVLpl4bRKrGAFiKWg6xypDhAQNykG4smB86rbt9HQLcNzJrR16mpchubmYsFkMAXY0PU+KbO9nr3zPeKKk2z9fDntfRXewTeHyNhH1dEJkK7jkGoRN/SJf21zA9UmReYfSTGJ4uPqTU57ZvxNjUVL8KQkZCz4Y9yjxIWQxN81/07VJ00HEA9XdlccvmgV6zBqYfHOlByICSFt1YoSpMDPYP45XBfXzg7cEcNTDFDpi+kWxKpustK6hFjPK8/U8MsnXADtMISX//mE0DnZU+UPP2K9wPbylCU7AaUq0DvN61edwLOKik7lGEJZiT8sdtc/1Bjkuz+GIasa3LPgPYEMkcFzbzlbUyipb0KlrNKDouaox0pQn5jyo4qzhG2eV++tbVTv8BDxIMvsg+Xhdrsbw742XxLbeRGM6QARu3aNEkDYfZt+cFybdPra/dGIBDLA8bB2z4x56nDcXMK7djgYB3TxEe04z9s39uJpWzP5QlBhuljSQeAmwLrKomPtwtrFlLLRZmtQi08QCsP0TgCA/XWxSx7J4P3YCsIWt3IXXMjZgjt+y6YnUiaXQ18iCCAgy+TJS/9BcHwfLadZ48NrmVthC23i23as6ge/fX+H5xCqvVrf59tMASYg2xT3S+xPajU1wtCFxH3mVOPWyWV+lsPPkY53Gh+ecJ72vwZjUKHyisCV6MqrL/sJWgyHBqqzfb0fE+/oeQDAMLeOnb+VnlQ8bMmFiQkHt65/V4y8JYk0zn9Pw9LIiL3JBjBlc+lf6BKzNqtT0cvTCqiuc88FXcf7PPc9Od4OClXkdZl1lcPk8g6OMNEl32IgCao8OY2QPRLz/h40WveKIoBxw/VCDMC3y0i2jlQ1Fi2zCrBh/VACC09 g2XcfFSs 42xhAY/lURATtRbuE5jJew2WzFQ== 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;