* [PATCH] cpupower: Combine two condition checks into one statement in get_cpu_topology()
@ 2017-11-20 18:19 SF Markus Elfring
2017-11-21 19:47 ` Shuah Khan
0 siblings, 1 reply; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-20 18:19 UTC (permalink / raw)
To: linux-pm, Shuah Khan, Thomas Renninger; +Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 20 Nov 2017 19:10:14 +0100
The same assignments were used in an if branch of two separate statements.
* Merge their condition checks into a single statement instead.
* Adjust the indentation there.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
tools/power/cpupower/lib/cpupower.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib/cpupower.c
index 9c395ec924de..81c828e5920e 100644
--- a/tools/power/cpupower/lib/cpupower.c
+++ b/tools/power/cpupower/lib/cpupower.c
@@ -140,18 +140,12 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
for (cpu = 0; cpu < cpus; cpu++) {
cpu_top->core_info[cpu].cpu = cpu;
cpu_top->core_info[cpu].is_online = cpupower_is_cpu_online(cpu);
- if(sysfs_topology_read_file(
- cpu,
- "physical_package_id",
- &(cpu_top->core_info[cpu].pkg)) < 0) {
- cpu_top->core_info[cpu].pkg = -1;
- cpu_top->core_info[cpu].core = -1;
- continue;
- }
- if(sysfs_topology_read_file(
- cpu,
- "core_id",
- &(cpu_top->core_info[cpu].core)) < 0) {
+ if (sysfs_topology_read_file(cpu, "physical_package_id",
+ &(cpu_top->core_info[cpu].pkg))
+ < 0 ||
+ sysfs_topology_read_file(cpu, "core_id",
+ &(cpu_top->core_info[cpu].core))
+ < 0) {
cpu_top->core_info[cpu].pkg = -1;
cpu_top->core_info[cpu].core = -1;
continue;
--
2.15.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cpupower: Combine two condition checks into one statement in get_cpu_topology()
2017-11-20 18:19 [PATCH] cpupower: Combine two condition checks into one statement in get_cpu_topology() SF Markus Elfring
@ 2017-11-21 19:47 ` Shuah Khan
2017-11-21 20:37 ` SF Markus Elfring
0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2017-11-21 19:47 UTC (permalink / raw)
To: SF Markus Elfring, linux-pm, Thomas Renninger
Cc: LKML, kernel-janitors, Shuah Khan, Shuah Khan
On 11/20/2017 11:19 AM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 20 Nov 2017 19:10:14 +0100
>
> The same assignments were used in an if branch of two separate statements.
>
> * Merge their condition checks into a single statement instead.
>
> * Adjust the indentation there.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> tools/power/cpupower/lib/cpupower.c | 18 ++++++------------
> 1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib/cpupower.c
> index 9c395ec924de..81c828e5920e 100644
> --- a/tools/power/cpupower/lib/cpupower.c
> +++ b/tools/power/cpupower/lib/cpupower.c
> @@ -140,18 +140,12 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
> for (cpu = 0; cpu < cpus; cpu++) {
> cpu_top->core_info[cpu].cpu = cpu;
> cpu_top->core_info[cpu].is_online = cpupower_is_cpu_online(cpu);
> - if(sysfs_topology_read_file(
> - cpu,
> - "physical_package_id",
> - &(cpu_top->core_info[cpu].pkg)) < 0) {
> - cpu_top->core_info[cpu].pkg = -1;
> - cpu_top->core_info[cpu].core = -1;
> - continue;
> - }
> - if(sysfs_topology_read_file(
> - cpu,
> - "core_id",
> - &(cpu_top->core_info[cpu].core)) < 0) {
> + if (sysfs_topology_read_file(cpu, "physical_package_id",
> + &(cpu_top->core_info[cpu].pkg))
> + < 0 ||
> + sysfs_topology_read_file(cpu, "core_id",
> + &(cpu_top->core_info[cpu].core))
> + < 0) {
This change takes the easily readable code into hard to read code,
even though it removes the duplicate code in the conditional.
Please find a better way to make it not so hard to read.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cpupower: Combine two condition checks into one statement in get_cpu_topology()
2017-11-21 19:47 ` Shuah Khan
@ 2017-11-21 20:37 ` SF Markus Elfring
0 siblings, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-21 20:37 UTC (permalink / raw)
To: shuah, linux-pm, Thomas Renninger; +Cc: LKML, kernel-janitors, Shuah Khan
>> @@ -140,18 +140,12 @@ int get_cpu_topology(struct cpupower_topology *cpu_top)
>> for (cpu = 0; cpu < cpus; cpu++) {
>> cpu_top->core_info[cpu].cpu = cpu;
>> cpu_top->core_info[cpu].is_online = cpupower_is_cpu_online(cpu);
>> - if(sysfs_topology_read_file(
>> - cpu,
>> - "physical_package_id",
>> - &(cpu_top->core_info[cpu].pkg)) < 0) {
>> - cpu_top->core_info[cpu].pkg = -1;
>> - cpu_top->core_info[cpu].core = -1;
>> - continue;
>> - }
>> - if(sysfs_topology_read_file(
>> - cpu,
>> - "core_id",
>> - &(cpu_top->core_info[cpu].core)) < 0) {
>> + if (sysfs_topology_read_file(cpu, "physical_package_id",
>> + &(cpu_top->core_info[cpu].pkg))
>> + < 0 ||
>> + sysfs_topology_read_file(cpu, "core_id",
>> + &(cpu_top->core_info[cpu].core))
>> + < 0) {
>
> This change takes the easily readable code into hard to read code,
I got other views around code readability for the shown software
design direction.
> even though it removes the duplicate code in the conditional.
Would you like to reduce a bit of duplicate code here?
> Please find a better way to make it not so hard to read.
Which source code layout would you find more appropriate then
in this use case?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-21 20:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-20 18:19 [PATCH] cpupower: Combine two condition checks into one statement in get_cpu_topology() SF Markus Elfring
2017-11-21 19:47 ` Shuah Khan
2017-11-21 20:37 ` SF Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).