public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function
@ 2022-10-12 10:10 Li kunyu
  2022-10-12 15:39 ` Shuah Khan
  0 siblings, 1 reply; 6+ messages in thread
From: Li kunyu @ 2022-10-12 10:10 UTC (permalink / raw)
  To: trenn, shuah, ray.huang; +Cc: linux-pm, linux-kernel, Li kunyu

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function
  2022-10-12 10:10 [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function Li kunyu
@ 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
  0 siblings, 2 replies; 6+ messages in thread
From: Shuah Khan @ 2022-10-12 15:39 UTC (permalink / raw)
  To: Li kunyu, trenn, shuah, ray.huang; +Cc: linux-pm, linux-kernel, Shuah Khan

On 10/12/22 04:10, Li kunyu wrote:
> 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>

Can you tell me more about why this change is needed and how you determined
the need for this change?

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 6+ messages in thread

* (no subject)
  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
  1 sibling, 0 replies; 6+ messages in thread
From: Li kunyu @ 2022-10-13  1:49 UTC (permalink / raw)
  To: skhan; +Cc: kunyu, linux-kernel, linux-pm, ray.huang, shuah, trenn


I'm glad to get your reply. In previous tests, it was found that variable initialization and assignment use mov related instructions. Therefore, when I analyze the code and find that removing some variable initialization and assignment does not affect the function and security, I will try to remove variable initialization.

Find the malloc function and find that its return value is void * type, so it does not need to cast.

thanks,
kunyu


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function
  2022-10-12 15:39 ` Shuah Khan
  2022-10-13  1:49   ` Li kunyu
@ 2022-10-13  2:01   ` Li kunyu
  2022-10-13 15:58     ` Shuah Khan
  1 sibling, 1 reply; 6+ messages in thread
From: Li kunyu @ 2022-10-13  2:01 UTC (permalink / raw)
  To: skhan; +Cc: kunyu, linux-kernel, linux-pm, ray.huang, shuah, trenn


I'm glad to get your reply. In previous tests, it was found that variable initialization and assignment use mov related instructions. Therefore, when I analyze the code and find that removing some variable initialization and assignment does not affect the function and security, I will try to remove variable initialization.

Find the malloc function and find that its return value is void * type, so it does not need to cast.

thanks,
kunyu


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Shuah Khan @ 2022-10-13 15:58 UTC (permalink / raw)
  To: kunyu; +Cc: linux-kernel, linux-pm, ray.huang, shuah, trenn, Shuah Khan

On 10/12/22 20:01, Li kunyu wrote:
> 
> I'm glad to get your reply. In previous tests, it was found that variable initialization and assignment use mov related instructions. Therefore, when I analyze the code and find that removing some variable initialization and assignment does not affect the function and security, I will try to remove variable initialization.
> 
> Find the malloc function and find that its return value is void * type, so it does not need to cast.
> 
> thanks,
> kunyu
> 

I am not seeing any reasons for removing the initialization.
There is no need to do that.

Missing error handling after malloc() call is the real problem
that can be fixed in this code path.

If you would like to fix that, send me a patch for that.

Hmm. Your reply to list looks strange - please double check and fix it

"Re:[PATCH]"@lists.nfsmail.com etc...

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function
  2022-10-13 15:58     ` Shuah Khan
@ 2022-10-14  3:49       ` Li kunyu
  0 siblings, 0 replies; 6+ messages in thread
From: Li kunyu @ 2022-10-14  3:49 UTC (permalink / raw)
  To: skhan; +Cc: kunyu, linux-kernel, linux-pm, ray.huang, shuah, trenn


OK, I will make a new patch to determine the malloc memory allocation.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-14  3:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-12 10:10 [PATCH] power: cpupower: utils: Optimize print_online_cpus and print_offline_cpus function Li kunyu
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox