From patchwork Fri Oct 14 04:29:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 2495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3c08:b0:7f:eb39:1b51 with SMTP id e8csp187333dys; Thu, 13 Oct 2022 21:42:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM591WqmTSNO4SmSnFTJp8CA1IcAN+Ig37MYtZ4NSib2sjbb+j8leC5WD5pnC1CytAG6qxpD X-Received: by 2002:a17:902:c209:b0:17f:7da5:b884 with SMTP id 9-20020a170902c20900b0017f7da5b884mr3450966pll.26.1665722551867; Thu, 13 Oct 2022 21:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665722551; cv=none; d=google.com; s=arc-20160816; b=ExGd0reSeq0+LyRd4ZufNnatezHcejKDIsjo9c7WONNqfZsnAHfoknP7oLWd93P66z PHY0jhkZaBULfyNvsltRiVqtNm8KECCE4iVvWe/yM8XhLrIelMaYOqxxPHFJxrcKCLRo O2Ah/cVFjIQbvP7oz8QCEdLWYGmEW0szYJE0ulaMeyCxZaXdPyNlWuoGC2RDaSIpwKqK n0SjkFiUScMIFwaJt3vBAc+7gl3pB8swIEF1UdS2AQnY4GZ76Kbf+bnvG9Vzuj9yy30n c6bSds+eTua9bR8pLQXf0L2Z/khDAFGAVayI7B5PlVQVHqmfIXZsyZvvEESipUyrTnyM ocKg== 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=2xI1z/PcUWXLcHFAKISTNvqMTPdmUcpb09xX0LOmwJ0=; b=GfncteNfSNN2bwTVclvKK/VW5kIxycD2CeRKwZQ6A1lpj+PM4x69UzPStdeQHWGO8n cuetcgEPA0eh2AzRH3pGjijcktzcuaqYSUtzJlaZEltGfffRaB+UNO5VOsEDMOJyM3UC Q/f5ftgQVyaWmK1vhl4CxbJzYS+j3ulN8akC8PuhDHUZiYHrckf6+aOz6Vx1h8mhDyEp EGIgXFO1UxTkW7rRg6ep0Gi/OkUltmMUPZgeUA+El1zQc9BOE9PZNJu8oSwNt33erVqz j81jUfF8SGtbKgQtWDVMZg6ylL9n9IObQ0aiQX+zjSfLIhFPzBNcsSd1H293iyN/Bgr3 sORg== 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 j2-20020a056a00174200b00554245aac47si1491104pfc.283.2022.10.13.21.42.19; Thu, 13 Oct 2022 21:42:31 -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 S229646AbiJNE3U (ORCPT + 99 others); Fri, 14 Oct 2022 00:29:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbiJNE3R (ORCPT ); Fri, 14 Oct 2022 00:29:17 -0400 Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4430A19C07E; Thu, 13 Oct 2022 21:29:16 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id E95FF1E80D6E; Fri, 14 Oct 2022 12:29:10 +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 g1NBD0ZV7jeF; Fri, 14 Oct 2022 12:29:08 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 376C01E80D53; Fri, 14 Oct 2022 12:29:08 +0800 (CST) From: Li kunyu To: shuah@kernel.org Cc: trenn@suse.com, ray.huang@amd.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] power: cpupower: utils: Add malloc return value check Date: Fri, 14 Oct 2022 12:29:11 +0800 Message-Id: <20221014042911.298308-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746636690777002472?= X-GMAIL-MSGID: =?utf-8?q?1746636690777002472?= Add the check and judgment statement of malloc return value. Signed-off-by: Li kunyu --- 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 9547b29254a7..eafdbd6d760c 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 = (void *)malloc(sizeof(char) * str_len); + if (unlikely(!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 = (void *)malloc(sizeof(char) * str_len); + if (unlikely(!offline_cpus_str)) + return; if (!bitmask_isallclear(offline_cpus)) { bitmask_displaylist(offline_cpus_str, str_len, offline_cpus);