From nobody Thu Dec 18 23:43:29 2025 Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [111.22.67.135]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8CBB166F11 for ; Thu, 29 Aug 2024 05:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.22.67.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724910991; cv=none; b=PXTXaaOWSnaApPOENYCo6o2pNy+5cRGZm52YT5OmdQbRJIx7PNK8bWIG0N5f3yDIgrcgXf7XU+xnKMWrjNo6ANipHTUxJCDh6uATMKA73ghrtLCjJ4LWra6BeTTG8+GkruRWixoDEs7LEghz8Ow0Nbxls5xypHDOgQs3Efkqj3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724910991; c=relaxed/simple; bh=MFg+ITjK7BXdRP6IrxNH4jBB6eGK0jmaSr5cqf/2EZM=; h=From:To:Cc:Subject:Date:Message-Id; b=Q7m9S0VX7ES+e28Z0gIZieuvEKnaGYSFCqDYke/3Cd4+LzNR8lDPfDd0OExtYICB1u5NbhmxqHQhGYs1YV4IbKidnQveee88Zw3YZouDQK60l5Wrb3hrOb0JUEC2Kr5P9Orhj+NLEiJneuOcJgEM+yb9Pl5WfApN1z/G5+J8wso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; arc=none smtp.client-ip=111.22.67.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com 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 2ee766d00d85eef-b2ef3; Thu, 29 Aug 2024 13:56:24 +0800 (CST) X-RM-TRANSID: 2ee766d00d85eef-b2ef3 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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) =20 static char *get_comm(char *buf) { - char *comm_str =3D malloc(TASK_COMM_LEN); + char *comm_str =3D calloc(TASK_COMM_LEN, sizeof(char)); =20 - memset(comm_str, 0, TASK_COMM_LEN); + if (!comm_str) { + fprintf(stderr, "Out of memory\n"); + return NULL; + } =20 search_pattern(&comm_pattern, comm_str, buf); errno =3D 0; --=20 2.17.1