From: Li kunyu <kunyu@nfschina.com>
To: trenn@suse.com, shuah@kernel.org, ray.huang@amd.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Li kunyu <kunyu@nfschina.com>
Subject: [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function
Date: Wed, 12 Oct 2022 18:10:39 +0800 [thread overview]
Message-ID: <20221012101039.3142-1-kunyu@nfschina.com> (raw)
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 <kunyu@nfschina.com>
---
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
next reply other threads:[~2022-10-12 10:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 10:10 Li kunyu [this message]
2022-10-12 15:39 ` Shuah Khan
2022-10-13 1:49 ` Li kunyu
2022-10-13 2:01 ` [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function Li kunyu
2022-10-13 15:58 ` Shuah Khan
2022-10-14 3:49 ` Li kunyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221012101039.3142-1-kunyu@nfschina.com \
--to=kunyu@nfschina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=ray.huang@amd.com \
--cc=shuah@kernel.org \
--cc=trenn@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®