Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3556926rwi; Wed, 12 Oct 2022 03:56:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5NAxlbIjzoqzyPDpp7wdxBuseFoGva8/zhnn8A60Ga4g77X1RswoXrYZmZj6lNwBUVmDYE X-Received: by 2002:a17:90a:d3cb:b0:20d:92d6:a047 with SMTP id d11-20020a17090ad3cb00b0020d92d6a047mr1679315pjw.155.1665572166615; Wed, 12 Oct 2022 03:56:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665572166; cv=none; d=google.com; s=arc-20160816; b=jaL/pWKSbE+3z6Ty846uaDvwpTbxndqUnmQ/Ctdrv7jR28WzS2N2kPfUY3OpkRmNPy /dEwoUyWBRYGXMrlc36yOu6IOqD+euTrBUO8mMAphSClWaTNRAn2BFNP/ySHmL/Acp5v 0eFoFOE+1wrcMy0tFdHHt560UmsYPoEtVftpWX9m9DiIc51KGzhwfIJynXS13EaMLBM+ 3/sIZcDAVBZ3aaoQRhvV5FcOvnVF8rjvclepdsBb7yPkrZQrUCmL6/wxmOJhZ5hLNmm6 j2NLUrpIQgGNqHHIgpofM959FRfqfsCczqvss6YmnUD8WtpI9EcNLLnqu7uQf3oAjWfg 629g== 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=CnMfNCZo266RCACTnAU2lc6REjaUym217C5OS7WrtSM=; b=KKuX7NWWgfEz3eQmDR0hyciqdDPnTzZfH4WnxeVM+2q8yAmxKZ754a9Z3G2VAi31ai RYN/8/b1Y/HQdTJdEaQp8dbgTSIIzFTLIF3MsMXGrxW2mlN+hKAki7IW1JhEzRoz3Wn5 P+rNuzHjRRhviAJEYKthrD7HwI0md1DZVM54FU3U/1ApVSWFOb7Woh/WvIxqdRJBknKe ogMAvIDLAAvJ8FGqE0lE0yJAxV+H7HpEea7luAhpHREu9ERsqccqyZ0f9lByZGZi6fVs Hzp2pTre7KVmUq5P0J5D8rAefrkjQSRr4iXP2BFLGfr66r4mP/vNMoN0DNPwHJzwZsCl lnDg== 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 b4-20020a170902d88400b00179e79571c9si16201729plz.325.2022.10.12.03.55.54; Wed, 12 Oct 2022 03:56:06 -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 S230030AbiJLKM1 (ORCPT + 99 others); Wed, 12 Oct 2022 06:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbiJLKLa (ORCPT ); Wed, 12 Oct 2022 06:11:30 -0400 Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6772BC09A4; Wed, 12 Oct 2022 03:10:47 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 5FD6D1E80D32; Wed, 12 Oct 2022 18:10:56 +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 ObQc2tPT1UaK; Wed, 12 Oct 2022 18:10:53 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id ABD711E80D6E; Wed, 12 Oct 2022 18:10:53 +0800 (CST) From: Li kunyu To: trenn@suse.com, shuah@kernel.org, ray.huang@amd.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function Date: Wed, 12 Oct 2022 18:10:39 +0800 Message-Id: <20221012101039.3142-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 1. Remove the initialization assignment of variables, and they will be assigned first. 2. Remove the mandatory conversion of returned value of malloc function, which returns void* type. Signed-off-by: Li kunyu --- tools/power/cpupower/utils/helpers/misc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index 9547b29254a7..36dbd0562240 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c @@ -134,11 +134,11 @@ void get_cpustate(void) */ void print_online_cpus(void) { - int str_len = 0; - char *online_cpus_str = NULL; + int str_len; + char *online_cpus_str; str_len = online_cpus->size * 5; - online_cpus_str = (void *)malloc(sizeof(char) * str_len); + online_cpus_str = malloc(sizeof(char) * str_len); if (!bitmask_isallclear(online_cpus)) { bitmask_displaylist(online_cpus_str, str_len, online_cpus); @@ -152,11 +152,11 @@ void print_online_cpus(void) */ void print_offline_cpus(void) { - int str_len = 0; - char *offline_cpus_str = NULL; + int str_len; + char *offline_cpus_str; str_len = offline_cpus->size * 5; - offline_cpus_str = (void *)malloc(sizeof(char) * str_len); + offline_cpus_str = malloc(sizeof(char) * str_len); if (!bitmask_isallclear(offline_cpus)) { bitmask_displaylist(offline_cpus_str, str_len, offline_cpus); -- 2.18.2