From patchwork Thu Aug 29 05:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Jun X-Patchwork-Id: 13782460 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 972D3C7115D for ; Thu, 29 Aug 2024 05:56:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5D796B00C4; Thu, 29 Aug 2024 01:56:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE5F26B00C6; Thu, 29 Aug 2024 01:56:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAC776B00C8; Thu, 29 Aug 2024 01:56:31 -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 9887D6B00C4 for ; Thu, 29 Aug 2024 01:56:31 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 100D0120A5D for ; Thu, 29 Aug 2024 05:56:31 +0000 (UTC) X-FDA: 82504223382.17.56B0522 Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [111.22.67.135]) by imf08.hostedemail.com (Postfix) with ESMTP id A9B33160005 for ; Thu, 29 Aug 2024 05:56:27 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of zhujun2@cmss.chinamobile.com designates 111.22.67.135 as permitted sender) smtp.mailfrom=zhujun2@cmss.chinamobile.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724910944; a=rsa-sha256; cv=none; b=3WU2a6rgk3WvXP+uOXHzYeQ3utk+WdbFiF0RmPMl8s0a7MmkmCWmE/SG+iUCnemF6tFTw7 V85rvCO9AGfev7Qujqd1RtSc/rR9RtRoB2OFw+6BZSJsQ2Gu7alOTOxiGW02uLWalahdHu WW1qlKZrLmmFVog1Q45mn86jrDlH8O4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of zhujun2@cmss.chinamobile.com designates 111.22.67.135 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=1724910944; 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=fSiPN4nQ6nwvt1XhzGEKpKXmpLM3XXrOuTZWX7lxhlU=; b=WVCtJXGyAzbKZZSQAiAO1zG1H+7814NQaVmznIxJpkEdsX0q01dqUTSi1VsEVNM9LiJ3uk iO5mfRn/o2ZKFDVBoSs9xc6F0cmiKSlC7JBG8mw+yWnMM+LixJUgg7xb4rwhtBJrgbv+PT Zgy7iSygrSyUvOLuY2KaWP66KFiSCtk= 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-app07-12007 (RichMail) with SMTP id 2ee766d00d88ef0-b2ef4; Thu, 29 Aug 2024 13:56:24 +0800 (CST) X-RM-TRANSID: 2ee766d00d88ef0-b2ef4 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from ubuntu.localdomain (unknown[223.108.79.99]) by rmsmtp-syy-appsvr07-12007 (RichMail) with SMTP id 2ee766d00d86c6c-914a4; Thu, 29 Aug 2024 13:56:24 +0800 (CST) X-RM-TRANSID: 2ee766d00d86c6c-914a4 From: Zhu Jun To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhujun2@cmss.chinamobile.com Subject: [PATCH] tools/mm: Use calloc and check the potential memory allocation failure Date: Wed, 28 Aug 2024 22:56:21 -0700 Message-Id: <20240829055621.3890-1-zhujun2@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 X-Stat-Signature: uujbcjbr1hjsckh4h78qtpd3w8hsfuk4 X-Rspamd-Queue-Id: A9B33160005 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724910987-896541 X-HE-Meta: U2FsdGVkX18u/O/6WrwOEhJhfGpPyk1BrlMXHOeeaIhFTiE45HJM0Ku5m8FaRCqexMjC1gBP7zEZsZHHlNpMs+f4vG54IGDxMygL5w+dQ/x81zu2+LsokShD2kYapmRh3At8FL2/xUnfFbDlm/b0YQxGZuwhkepG+5VKvBdULR7wl9UBsSe/i6U/yFITGQpP/PR4CvXYaty94rtxt8RZqOtfTefWOQqkVs1p2fSg5g40Hx7SYUGaESifiCM/rMMhu5k8omhhf62l9ezgIt3K5vsf5og8wr8+PEJfyIJxgVaq5xu+LJ8rcogzTtDv4+VI8lji560MLFO2CTLTDNzeibaqjkNEQ5vEP3uwEART/aEmQV3IbZ6dra+n+q7SlVUrn0wofD6Huu6MzKvmkNy+tFYB5Q7itdyPOBGfz6XhLRUvs27hSux3Z8KfipnMGcXKK2Xdk/cIelvczCWwa7jI4a5ePZnB9zmVQY3mupt82WhJlO3d0UkvjQKbMrLUj9JkHqvxJ/I7H6o/rlPflwbpbOi59grNTlsnjrnW1bCunkAu6iGqTj8GYheuG/N39hhecrQ1nxL0ZpZKHxjKPszht+gdkdxqehNtZqMOSmUYN31R7StmaTnJQFeuiM7KjZwYYWe0U54iq4NCSa+jg2VjZfuGWN3jRsJlid6EthDKk/AEhq/lqx/eygQyhdq75YeUHPryvw9hEIDXqZ3cu/SGwwzI7WPAMkQm9OerwgIhJD9E/Em0aUOw5xuQzBTE1WGMz7j/iQnCi5JxhxTQFt9lBoCYj7eMC9WmvHEwQgucxXwC8Xb87OVsiRa0jSHpPn017+PbUlmppdKcQs8MegIvKT5sx+dLdfTkmRbiftnpLwffMHs8qKdKwf0YwW+14MgkqbM7aAV+UgUE3O9VK/i5I3Jf84sYx+7D4DOSsLch3uA4byCYBwJ5bI07nWH2jcAeWxEOxFkDO8dZeArBu88 haKi4wCc +DQZ5qZ/5iIL24TG3tO2nMekBGMVfjhDpuqxG8midBtpNs0Qgw6QrIANsdVO4Hzvpup/p 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 memory allocating check of comm_str before used. Signed-off-by: Zhu Jun --- tools/mm/page_owner_sort.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c index e1f264444342..4e2329831810 100644 --- a/tools/mm/page_owner_sort.c +++ b/tools/mm/page_owner_sort.c @@ -368,9 +368,12 @@ 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) { + fprintf(stderr, "Out of memory\n"); + return NULL; + } search_pattern(&comm_pattern, comm_str, buf); errno = 0;