From patchwork Thu Aug 29 09:21:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Jun X-Patchwork-Id: 13782830 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 C6CE4C83010 for ; Thu, 29 Aug 2024 09:21:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 323836B00AD; Thu, 29 Aug 2024 05:21:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D2586B00AF; Thu, 29 Aug 2024 05:21:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19ADC6B00B0; Thu, 29 Aug 2024 05:21:54 -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 ED0FB6B00AD for ; Thu, 29 Aug 2024 05:21:53 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 61A55140C82 for ; Thu, 29 Aug 2024 09:21:53 +0000 (UTC) X-FDA: 82504740906.25.A3B4691 Received: from cmccmta1.chinamobile.com (cmccmta4.chinamobile.com [111.22.67.137]) by imf10.hostedemail.com (Postfix) with ESMTP id F15E3C0018 for ; Thu, 29 Aug 2024 09:21:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of zhujun2@cmss.chinamobile.com designates 111.22.67.137 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=1724923267; 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=vNxdSST9tfhBsMGtTZfPGQ7LUnZcnNDJNGf1S01DCxo=; b=02K9rI2cr0yKuABfBCrPkmQywFKuQnUsGYpFtqlK5Jw/CUgWhlIMKLmDD0sB0a2jbiWyHc 7B9+aVG1Zlhe3EMPY1xobdU81A4F4pIaPs+sroG9cLq22osTd0kx/5delCUB9K3KQbQBfy Kos55X/eH4xy8+vEiHGy6yA8lKKfh6Q= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of zhujun2@cmss.chinamobile.com designates 111.22.67.137 as permitted sender) smtp.mailfrom=zhujun2@cmss.chinamobile.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724923267; a=rsa-sha256; cv=none; b=4Y3uo6GUe3gZHp+YFNhELvlMclUo00H70LvZ5EPs+wZBWiFtBnFV7Q/RrKF5l4s0ZgoqUw jPM+o3jBNDvprtrzvfwjufhCu8qCpuQNGEScG0tbLyGZFCQ51QJSW3CxmSvkErD9LGjxM7 6ylt7ZfruujcXhmlB4JIfzfkKdwEtlY= 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-app04-12004 (RichMail) with SMTP id 2ee466d03da9905-861f8; Thu, 29 Aug 2024 17:21:46 +0800 (CST) X-RM-TRANSID: 2ee466d03da9905-861f8 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from ubuntu.localdomain (unknown[223.108.79.99]) by rmsmtp-syy-appsvr03-12003 (RichMail) with SMTP id 2ee366d03daab3b-9c796; Thu, 29 Aug 2024 17:21:46 +0800 (CST) X-RM-TRANSID: 2ee366d03daab3b-9c796 From: Zhu Jun To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhujun2@cmss.chinamobile.com Subject: [PATCH v2] tools/mm: Use calloc and check the memory allocation failure Date: Thu, 29 Aug 2024 02:21:44 -0700 Message-Id: <20240829092144.5851-1-zhujun2@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: F15E3C0018 X-Stat-Signature: xm8j8xbumpog35bpogm8e7n4hj74aoi6 X-HE-Tag: 1724923309-669567 X-HE-Meta: U2FsdGVkX188I3qyy4vbS8RH46ildTEW+672mgugOWUUPjsDFGbVVYOdN4LnfiTUfoGEakodQEwFhyFELy2+KmdkEBecnDVcIcLmqQKiv1RrbjJd7izK8Kvb/Yfw3wmgJAusrT1OoguQkLeZHexxuJRyMyTNvkvzmsoPtCVNco4Lfr1Ca7pgwivuyTiVoPjUoWp4UkJqEXX3xBUIMq1LaM9cd/V8R9H/MffRHPnqDaneBWtQOk5RmXBn+t7cBAKHXzx7z3h+omOvYPhozPk8KYxVkjbN6DIrk5frcC0robn2Z06ldto8po4J/qG5z0/15QqkIFpKLj5f03lKmI9YKZipQ+BA/ZO5TVuYhixAlUH/Z3S7UKSCuSpjzB5w+rZth5W0IUxq+RhIWoDf9SqepyV5OGJsv7DyNAt+xLN/Os5b2d5FCRvAB/Q5XzaHt6SYX+xMgTuDGiJgzLPzAxvRID5h0r7HlaU5akixOiMLKKsb7ZShEgJN7yWozGw2PLQFI+gaNBGhI2SbDpuxOBITxJVfBw+S8dpMmiJ2hKWWyEHgL4NOw9c09jrNHyGUJY7vvc4bJ04Jq5pZz50nu8k4H/vqCrNtOw5gxwpiiKVmYB4RcUpAmEqF9YIDGUs8nKe5LrVferrKNDKZ8mglpsjfvlmHVa9HVzFTfiK/OsunzSOaTaT0iYuA6uPU0lTgvZbmLrgojgfnDkWqaSZdnO/g/p1N70BVn/THQ0kCjz4lXj1/w95KZDlT5ReQdAG8nFmpIy0THaOVUWQjAwblMxmUFQQOSmmqk4NYaqH2UBgQGCpR4sO7ub1C3R6Zju7szkht/aaeGm9YOItVZ6vBpnNQC6jxMNYL/CrqPXHwrzHEJPh13ilSXt6h3YyCTgEP4HgOh0lWmQISusuw9QSxd/gHRL0QUVRjIY7KrHPPCbPKOL8RTTKwtP9zvBgC9agdDeg17cr7tYKDv4ELsi0F6Hs ze0jlECn Jj49xFshtfoTzYe6CCyT/7ITPS5mR8SROVUukQqejcVSf5NMid64OwfEz4YzSQurgWcOR 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 --- v1->v2: modify commit message and delete fprintf line 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;