From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D3BFC25B08 for ; Mon, 15 Aug 2022 22:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347252AbiHOWDL (ORCPT ); Mon, 15 Aug 2022 18:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347956AbiHOWA6 (ORCPT ); Mon, 15 Aug 2022 18:00:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B6A52ED6A; Mon, 15 Aug 2022 12:35:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6CABE6114B; Mon, 15 Aug 2022 19:35:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74D06C433D6; Mon, 15 Aug 2022 19:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592134; bh=Jrrwpx5iQuNpEFJqO6sMVwwy8PYagWRKnEgBRYZS9fU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lXnHVm72FtZ2HgRcjorLwardk7vmpuE/cACoCLonBSMWTXVPlXVup8lEGhAi8gBLu 8XPj17Hil3nLY8L/EHqzQNlzD19vQ95V9XnO7jbyxZ1Q3DBDsdPx7ANs8kTkAKLVZ1 /eia8ykGGHaTRflCRsau/M1h97q8twLN004XK5WI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, jianchunfu , Daniel Bristot de Oliveira , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.18 0739/1095] rtla/utils: Use calloc and check the potential memory allocation failure Date: Mon, 15 Aug 2022 20:02:18 +0200 Message-Id: <20220815180459.961331642@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: jianchunfu [ Upstream commit b5f37a0b6f667f5c72340ca9dcd7703f261cb981 ] Replace malloc with calloc and add memory allocating check of mon_cpus before used. Link: https://lkml.kernel.org/r/20220615073348.6891-1-jianchunfu@cmss.chinamobile.com Fixes: 7d0dc9576dc3 ("rtla/timerlat: Add --dma-latency option") Signed-off-by: jianchunfu Acked-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin --- tools/tracing/rtla/src/utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 5352167a1e75..5ae2fa96fde1 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -106,8 +106,9 @@ int parse_cpu_list(char *cpu_list, char **monitored_cpus) nr_cpus = sysconf(_SC_NPROCESSORS_CONF); - mon_cpus = malloc(nr_cpus * sizeof(char)); - memset(mon_cpus, 0, (nr_cpus * sizeof(char))); + mon_cpus = calloc(nr_cpus, sizeof(char)); + if (!mon_cpus) + goto err; for (p = cpu_list; *p; ) { cpu = atoi(p); -- 2.35.1