Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1616131imn; Sun, 31 Jul 2022 14:31:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vGplyu8hMufxjZoWZxXGTFNrPHCAvF9sPM3rZ+haku0C5Dcu+rHtDvz2UNmo/NQVTv4+GA X-Received: by 2002:a17:907:6d86:b0:72b:5ad6:6df1 with SMTP id sb6-20020a1709076d8600b0072b5ad66df1mr10892380ejc.264.1659303075084; Sun, 31 Jul 2022 14:31:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659303075; cv=none; d=google.com; s=arc-20160816; b=vgkTyaSQ0spT8v5JuPScfR/8Oc4mO9y/9a4vT+W3hHYUuXg0bXDfe2inqmw5d+PXih gsEzHvBXyBYZaHbSIcvrl6cfqmdOkfHG1YZ9ETaHZ+3+jiz5LKXvZN2YQYetTn6+qixy 1AvRB64qir08N+c+6dppEONxdFXhABQb0JPpH6RUEkbCJGhtuYcRaKf4XO4aflPEuz6K LBQtTZuwj7CP4szt5enh5sm3KbO5OEkM6iWCzpuVKWoZUqgvCfNgB523k3/nNXJojmBD dtPIZ4/Avs8HmWKzTkN0FlQbN1grS1ncVioyZFYunGw5rnNUmZRizh0ehQh7rjY1r8ze PDPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=YZKgWpYzeUlhrv+9gK49CAKogwoiRusgzH23IKCkTiY=; b=zM5JuLYn5goJWY2vTVYCzOxfZEsuuio5Uq59sWVIRMG87u7M7v7RHivcqSEEAviPKK M4JlFtyU49SCyyHYSZzzC1hxyRjJcFxs/FC//VCKfNNvHi6uyeEb0SjEdzFTOOOXyJvA iB/eEX1KHsf87HAdJOiIl2DN52AkMXQ8jBCdaGh1/cor+axvmDFG4Z8zDcwWxCj8eB93 0p9EhqA1Jh7+zf+jZ1EyuPB+UtCJUGLFP8b6JLqicB4prN8Z94w7XRtRLwhA+dJrcF3x 6KZ9tsCGweON+9V74zfJ6iwZRvt1GmEtKo04+9d+amVU753ZUTmdsX61r5tMce3FOIMr fdDA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js7-20020a17090797c700b007308bd40223si597059ejc.669.2022.07.31.14.30.41; Sun, 31 Jul 2022 14:31:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238486AbiGaVJs (ORCPT + 99 others); Sun, 31 Jul 2022 17:09:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbiGaVJn (ORCPT ); Sun, 31 Jul 2022 17:09:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0FB9DF83 for ; Sun, 31 Jul 2022 14:09:42 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8E7B5B80D81 for ; Sun, 31 Jul 2022 21:09:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 619DEC433C1; Sun, 31 Jul 2022 21:09:40 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oIGBv-007GiH-1E; Sun, 31 Jul 2022 17:09:39 -0400 Message-ID: <20220731210939.214097203@goodmis.org> User-Agent: quilt/0.66 Date: Sun, 31 Jul 2022 17:09:19 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Daniel Bristot de Oliveira , jianchunfu Subject: [for-next][PATCH 1/4] rtla/utils: Use calloc and check the potential memory allocation failure References: <20220731210918.097591536@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 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) --- 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