Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3023305rwb; Mon, 15 Aug 2022 16:20:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR4JHiKxJLostDZzq92For8hZ3aD1rgDWzd+iQBBmEcCYCJuy+bFd3Hnn9rWsCBaeZEUt3dM X-Received: by 2002:a63:5b61:0:b0:41d:3227:37b8 with SMTP id l33-20020a635b61000000b0041d322737b8mr15560703pgm.265.1660605653225; Mon, 15 Aug 2022 16:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605653; cv=none; d=google.com; s=arc-20160816; b=CU4MF7fQTS6ABJGPYQ/FGfO83ecEoZFAnZWeaOUL3dA0aKLsvMHyGU1CBMQI7wZSXr HUiVRSF2muhiY/kVDGswLgORqBZHKbMgLkTx32J9irBCAvtyfAGJPE5aA1ZxIM+IOMX4 ZOkgMQJsn9CYxpi1kVJ6mmo+o6gFUOsYhdl/fpBZchcn2z7bUa71YMfujO3S92dGwazw JXh2JyOcBwqTHLtiwtUhoI+udQGHlv9fuQMLRInHd3G6jZ83SgdZYEvvhDn9WGNB1D+4 ok3FrTqiSg4u1A0zE/kPa0OVzyCZ7jlO5SZ8h2IHR/zJviz+Bgkdbu2HPjaWaHzh7a3C ADdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZXoIqlx4ZAegx4BN3pZiVBXWHb5fdhdfnU9pkhTs6cM=; b=Dp4NZC5i67sHZgBMj+rKIHVNHjI/dsh857I+u7Vn29bkENN+2+6mrAmCpFzpRLhNks RlFtO2tOhr2BlKEHKj9Y/AGYrYFYtXpv4f6jtomLdC87npgX0iVx/BKdwGeVuTp9YONc i12uDLPeL7vd9IOl6aK5C9C7pGYT0Ns9JBqsZWCe11MUbhWyD4g+ENOsLM4c+1lsJwUK u3sqtBwXcVQcv8IJsljZyBBPlXVNWLrvVVqDbVEjUKJxnv4zHrPIWjfBjKTeWvp1bol8 poGpjJY1ENwzIDnnjnS6VNRGk/aH35eiFLKLTVotZt+GzsjeJmMG12pLavXsK/82jWNR xk4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lXnHVm72; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020a17090a2b0300b001f7283763fesi17293116pjc.44.2022.08.15.16.20.41; Mon, 15 Aug 2022 16:20:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lXnHVm72; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347113AbiHOWDJ (ORCPT + 99 others); Mon, 15 Aug 2022 18:03:09 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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