Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3230865rwb; Mon, 15 Aug 2022 21:47:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR7xiE2IFbzf9m9K1iyhAonZ9foneVEHwszpZxvZWlKIvDXCf4A+J/W3re+Zjy/pj4lq1Q6S X-Received: by 2002:a05:6a00:2490:b0:52f:206c:5e3b with SMTP id c16-20020a056a00249000b0052f206c5e3bmr19139477pfv.47.1660625254626; Mon, 15 Aug 2022 21:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660625254; cv=none; d=google.com; s=arc-20160816; b=OXQ/Bwe/csjjDI30+BUAXflZ9oowNT3l857Sbglmk1CY6KRD0q3Qpwwr+0tCXS8Lmt JLULcl94qBO2g5YIKyu6SmfGWinLVbhdy/6E6HGQv8yzHAJc7hdCrO8nvlo9e4ofJa5y Y8hT6YU4latil+r3A4vOGFC+tzr9X4ueApeeEY+gGrfludV1MyjMeSUnDVvOzrg6wLUF FYoN9pgnTPKcoTQC7BQs2riIQ7AmkvQqRdVFyCiFjmUMMwo6ExuTB8xPsfjnGjV0/NeK Hgump1E+VfUkCdNQtRkXMnK5dL7SdN6kwGdMgGq+WhNYSgmADFUyVaG8ir5w7xM4/X3j EwtQ== 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=Im4wSE4bx7YcU+PZKc7KAFEC4X0PXCm7bJBHVd/7aKPHoP2uHIAWkKCRViqkVn9h7y P9sqR+zgCkUMyy6yWKVu0Orz3sdbeKs9gp7+Fn33rtEQdtg0K6oDKwl8OgWWTaPA/m/x z5tj5rY5W9aXjaynz8X+1zeOP3KFjRcdcxZ5FDnyDBcfJSnnVR15aLqRxU9iFkbquZ/5 wJAFus25C1f4n+vPmcQ1ZufYUk1JuwAnf5u05Fu4UdUNdPc0y2vhvARDg43/U59wWU+E aXOqGHtJDsaVSHX3FyUu/Y8LexglkM/rzyf5LhEmRn6FGgevGS3xkpK9eX5pdQkuOQii PONw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="m13Xt/WW"; 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 n18-20020a170903111200b001726a59e2desi7163457plh.133.2022.08.15.21.47.16; Mon, 15 Aug 2022 21:47:34 -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="m13Xt/WW"; 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 S232064AbiHPEp0 (ORCPT + 99 others); Tue, 16 Aug 2022 00:45:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232847AbiHPElm (ORCPT ); Tue, 16 Aug 2022 00:41:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86F681709DB; Mon, 15 Aug 2022 13:34:44 -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 17E73611DB; Mon, 15 Aug 2022 20:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 011A7C433D6; Mon, 15 Aug 2022 20:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595656; bh=Jrrwpx5iQuNpEFJqO6sMVwwy8PYagWRKnEgBRYZS9fU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m13Xt/WWQ1QlRBcVIddBIbJbu+zAjxw+T1s8qCfzpu52MRoBFxVpGP1vvi4MnMK7K SCmIH+7f0fEFTPoo5rbPjoiZID8ZiB6cVPPnlJDhKcuaVNSKowsL2rpSThMsyOWneT YYdvTjKLxJus1npcna0ESwStfCQwf8lmfJq1+TVY= 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.19 0791/1157] rtla/utils: Use calloc and check the potential memory allocation failure Date: Mon, 15 Aug 2022 20:02:27 +0200 Message-Id: <20220815180511.112567675@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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