From patchwork Wed Oct 19 01:46:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 4400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp78086wrs; Tue, 18 Oct 2022 18:50:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM520j5tmgyjk/wzIK0kOSJa9CS3cVnztGD9wczDqt1n3HqYW//JD7RSkK0P5sMKOUjHFtaW X-Received: by 2002:a17:907:a073:b0:78d:9e06:8ba9 with SMTP id ia19-20020a170907a07300b0078d9e068ba9mr4749388ejc.338.1666144255277; Tue, 18 Oct 2022 18:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666144255; cv=none; d=google.com; s=arc-20160816; b=vilzpFPb6CfFxNsUwmy3pQFwMWabtgMVO4UpoQGdegBoHgxHt2SDSbCclGp+kmCqyk dnibhxJOGOmT1VGCUM7pWOt0AGyFJq6Daux92vyKA5bOUgHkVm7BBoVHuTcN9S2D7Nuj rZ9D8/NVNHH8buYT2NysWfz5x5P8wagFly427MxkfNcOTVUFphRcajvEE3EIJnS4INmn i9iAw/2aOb95Q4k3bJFePnmLUKmLJYT6s0HZW6XPu+Yr3kce2dxDeuQVzZPzXfM+ecUD PxFNyN6y8VUyyxTXyeJf9jF7scMX8K1QJDb2nutR6CPFFFrloNm+reyG9XvtTCgGvsr1 +MRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=7sXEvL2kwm70WnNmwYa1qSN+fOdAB8R1BwraOQTAZkM=; b=ruS7CSZ/Ve9h/87bSQ/tMxm6WFvxGwAO/KF+SQYjg4uofnL7zMBgdkNn72eYdntMpw 7hvEgVnDqSc3FDPriMHiLksKMXiWaD2irNvoj5bYBYP95woHEVnt3Iw1Y1uYgWf46zen hmfbGYl2W2z4+ZPR7pzpTrlppfVgG04ZJIfaht9Nqt0GGzNkVbzHo9/ZIvL9DXa7c18j S9UCnXHor7P9gJdr0bjYdkd/5Y36NergSHl/COMfFbU3BN6NK4oY4HWFVBTy1BNGX8VN TptyoZQWrksTWBjj3pWGoq3ynnh/K3Ci/tf8AzWuFH6HcXTyr4Sd9PpYSMvy/QHSGTiu EX5w== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170906794f00b0078db137967dsi13823483ejo.566.2022.10.18.18.50.31; Tue, 18 Oct 2022 18:50:55 -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 S229657AbiJSBqe (ORCPT + 99 others); Tue, 18 Oct 2022 21:46:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbiJSBqd (ORCPT ); Tue, 18 Oct 2022 21:46:33 -0400 Received: from mail.nfschina.com (unknown [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8811989CFF; Tue, 18 Oct 2022 18:46:32 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 08FDF1E80D90; Wed, 19 Oct 2022 09:45:41 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pZUlp8UY5es3; Wed, 19 Oct 2022 09:45:38 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 37E811E80D76; Wed, 19 Oct 2022 09:45:38 +0800 (CST) From: Li kunyu To: shuah@kernel.org, trenn@suse.com Cc: ray.huang@amd.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [v2 PATCH] power: cpupower: utils: Add malloc return value check Date: Wed, 19 Oct 2022 09:46:14 +0800 Message-Id: <20221019014614.3120-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,MAY_BE_FORGED, SPF_HELO_NONE,SPF_NONE autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747078878771798419?= X-GMAIL-MSGID: =?utf-8?q?1747078878771798419?= Add the check and judgment statement of malloc return value. Signed-off-by: Li kunyu --- v2: Remove unlikely() check tools/power/cpupower/utils/helpers/misc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index 36dbd0562240..083d5a6bb74e 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c @@ -139,6 +139,8 @@ void print_online_cpus(void) str_len = online_cpus->size * 5; online_cpus_str = malloc(sizeof(char) * str_len); + if (!online_cpus_str) + return; if (!bitmask_isallclear(online_cpus)) { bitmask_displaylist(online_cpus_str, str_len, online_cpus); @@ -157,6 +159,8 @@ void print_offline_cpus(void) str_len = offline_cpus->size * 5; offline_cpus_str = malloc(sizeof(char) * str_len); + if (!offline_cpus_str) + return; if (!bitmask_isallclear(offline_cpus)) { bitmask_displaylist(offline_cpus_str, str_len, offline_cpus);