ACPI-processor: Fine-tuning for several function implementations
Subsystems (2)
cover ACPI-processor: Fine-tuning for several function implementations
From: Markus Elfring <[email protected]>
Date: Tue, 9 Sep 2016 20:15:05 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (30):
Use kmalloc_array() in acpi_processor_get_performance_states() Improve two size determinations in acpi_processor_get_performance_states() Rename jump labels in acpi_processor_get_performance_states()
Delete two unnecessary initialisations in acpi_processor_get_performance_states() Rename jump labels in acpi_processor_preregister_performance()
Move a success indication in acpi_processor_preregister_performance() Rename jump labels in acpi_processor_get_psd()
Delete two unnecessary initialisations in acpi_processor_get_psd() Improve a size determination in acpi_processor_get_psd()
Rename jump labels in acpi_processor_get_performance_control() Delete two unnecessary initialisations in acpi_processor_get_performance_control() Rename jump labels in acpi_processor_ppc_notifier()
Delete an unnecessary initialisation in acpi_processor_ppc_notifier() Delete an unnecessary initialisation in acpi_processor_get_performance_info() Delete an unnecessary initialisation in acpi_processor_get_platform_limit() Use kmalloc_array() in acpi_processor_get_throttling_states() Improve another size determination in acpi_processor_get_throttling_states() Rename jump labels in acpi_processor_get_throttling_states()
Delete two unnecessary initialisations in acpi_processor_get_throttling_states() Fix jump targets in acpi_processor_get_throttling_info()
Rename jump labels in acpi_processor_get_tsd()
Delete two unnecessary initialisations in acpi_processor_get_tsd() Improve a size determination in acpi_processor_get_tsd()
Rename jump labels in acpi_processor_get_throttling_control()
Delete two unnecessary initialisations in acpi_processor_get_throttling_control() Fix jump targets in acpi_processor_reevaluate_tstate()
Delete an unnecessary initialisation in acpi_processor_reevaluate_tstate() Rename a jump label in acpi_processor_get_platform_limit()
Delete an unnecessary initialisation in acpi_processor_get_platform_limit() Improve jump targets in acpi_processor_update_tsd_coord()
drivers/acpi/processor_perflib.c | 87 +++++++++++++-------------- drivers/acpi/processor_throttling.c | 116 ++++++++++++++++-------------------- 2 files changed, 93 insertions(+), 110 deletions(-)
Signature · 1 line
2.10.0
PATCH 1/30 ACPI-processor: Use kmalloc_array() in acpi_processor_get_performance_states()
From: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 10:20:10 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/acpi/processor_perflib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/processor_perflib.c +3 -2
@@ -346,9 +346,9 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr) pss->package.count)); pr->performance->state_count = pss->package.count; - pr->performance->states -kmalloc (sizeof (struct acpi_processor_px ) * pss->package.count, -GFP_KERNEL ); + pr->performance->states =kmalloc_array (pss->package.count, +sizeof (*pr->performance->states), +GFP_KERNEL );if (!pr->performance->states) { result = -ENOMEM ; goto end;
Signature · 1 line
2.10.0
PATCH 2/30 ACPI-processor: Improve two size determinations in acpi_processor_get_performance_states()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 11:11:12 +0200
Replace the specification of a data structure by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/acpi/processor_perflib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/processor_perflib.c +3 -2
@@ -358,7 +358,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)struct acpi_processor_px *px = &(pr->performance->states[i]); - state.length =sizeof (struct acpi_processor_px ); + state.length =sizeof (*px); state.pointer = px;ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"Extracting state %d\n" , i));
@@ -400,7 +400,8 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)* Copy this valid entry over last_invalid entry */ memcpy (&(pr->performance->states[last_invalid]), - px,sizeof (struct acpi_processor_px )); + px, +sizeof (*px)); ++last_invalid; } }
Signature · 1 line
2.10.0
PATCH 3/30 ACPI-processor: Rename jump labels in acpi_processor_get_performance_states()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 11:27:45 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/acpi/processor_perflib.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/acpi/processor_perflib.c +4 -5
@@ -339,7 +339,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)if (!pss || (pss->type !=ACPI_TYPE_PACKAGE )) { printk(KERN_ERR PREFIX "Invalid _PSS data\n"); result = -EFAULT ; - goto end; + goto free_buffer; } ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n",
@@ -351,7 +351,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr) GFP_KERNEL);if (!pr->performance->states) { result = -ENOMEM ; - goto end; + goto free_buffer; }for (i =0 ; i < pr->performance->state_count; i++) {
@@ -369,7 +369,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)ACPI_EXCEPTION ((AE_INFO , status,"Invalid _PSS data" )); result = -EFAULT ;kfree (pr->performance->states); - goto end; + goto free_buffer; }amd_fixup_frequency (px, i);
@@ -417,8 +417,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)if (last_invalid >0 ) pr->performance->state_count = last_invalid; - - end: + free_buffer:kfree (buffer.pointer);return result;
Signature · 1 line
2.10.0
PATCH 4/30 ACPI-processor: Delete two unnecessary initialisations in acpi_processor_get_performance_states()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 11:48:52 +0200
The local variables "pss" and "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_perflib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/processor_perflib.c +2 -2
@@ -320,11 +320,11 @@ static void amd_fixup_frequency(struct acpi_processor_px *px, int i) {};static int acpi_processor_get_performance_states (struct acpi_processor *pr) {int result =0 ; -acpi_status status =AE_OK ; +acpi_status status;struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL };struct acpi_buffer format = {sizeof ("NNNNNN" ),"NNNNNN" };struct acpi_buffer state = {0 ,NULL }; -union acpi_object *pss =NULL ; +union acpi_object *pss;int i;int last_invalid =-1 ;
Signature · 1 line
2.10.0
PATCH 5/30 ACPI-processor: Rename jump labels in acpi_processor_preregister_performance()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 12:38:40 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/acpi/processor_perflib.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/acpi/processor_perflib.c +7 -9
@@ -621,12 +621,12 @@ int acpi_processor_preregister_performance(if (pr->performance) { retval = -EBUSY ; - goto err_out; + goto unlock; }if (!performance || !per_cpu_ptr (performance, i)) { retval = -EINVAL ; - goto err_out; + goto unlock; } }
@@ -644,7 +644,7 @@ int acpi_processor_preregister_performance( } }if (retval) - goto err_ret; + goto clear_cpu;/* * Now that we have _PSD data from all CPUs, lets setup P-state
@@ -689,12 +689,12 @@ int acpi_processor_preregister_performance(if (match_pdomain->num_processors != count_target) { retval = -EINVAL ; - goto err_ret; + goto clear_cpu; }if (pdomain->coord_type != match_pdomain->coord_type) { retval = -EINVAL ; - goto err_ret; + goto clear_cpu; }cpumask_set_cpu (j, covered_cpus);
@@ -719,8 +719,7 @@ int acpi_processor_preregister_performance( pr->performance->shared_cpu_map); } } - -err_ret: + clear_cpu:for_each_possible_cpu (i) { pr =per_cpu (processors, i);if (!pr || !pr->performance)
@@ -734,8 +733,7 @@ err_ret: } pr->performance =NULL ;/* Will be set for real in register */ } - -err_out: + unlock:mutex_unlock (&performance_mutex);free_cpumask_var (covered_cpus);return retval;
Signature · 1 line
2.10.0
PATCH 6/30 ACPI-processor: Move a success indication in acpi_processor_preregister_performance()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 13:03:56 +0200
The local variable "retval" was initialised with a zero at the beginning as an indication for a successful function execution despite of the possibility that following function calls could fail.
Move the desired assignment down to the source code place where some system clean-up is performed.
--- drivers/acpi/processor_perflib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/processor_perflib.c +3 -1
@@ -595,7 +595,7 @@ int acpi_processor_preregister_performance( struct acpi_processor_performance __percpu *performance) {int count_target; -int retval =0 ; +int retval;unsigned int i, j;cpumask_var_t covered_cpus;struct acpi_processor *pr;
@@ -719,6 +719,8 @@ int acpi_processor_preregister_performance( pr->performance->shared_cpu_map); } } + + retval =0 ; clear_cpu:for_each_possible_cpu (i) { pr =per_cpu (processors, i);
Signature · 1 line
2.10.0
PATCH 7/30 ACPI-processor: Rename jump labels in acpi_processor_get_psd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 13:50:41 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/acpi/processor_perflib.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/acpi/processor_perflib.c +6 -7
@@ -545,13 +545,13 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)if (!psd || (psd->type !=ACPI_TYPE_PACKAGE )) { printk(KERN_ERR PREFIX "Invalid _PSD data\n"); result = -EFAULT ; - goto end; + goto free_buffer; }if (psd->package.count !=1 ) { printk(KERN_ERR PREFIX "Invalid _PSD data\n"); result = -EFAULT ; - goto end; + goto free_buffer; } pdomain = &(pr->performance->domain_info);
@@ -564,19 +564,19 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)if (ACPI_FAILURE (status)) { printk(KERN_ERR PREFIX "Invalid _PSD data\n"); result = -EFAULT ; - goto end; + goto free_buffer; }if (pdomain->num_entries !=ACPI_PSD_REV0_ENTRIES ) { printk(KERN_ERR PREFIX "Unknown _PSD:num_entries\n"); result = -EFAULT ; - goto end; + goto free_buffer; }if (pdomain->revision !=ACPI_PSD_REV0_REVISION ) { printk(KERN_ERR PREFIX "Unknown _PSD:revision\n"); result = -EFAULT ; - goto end; + goto free_buffer; } if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
@@ -584,9 +584,8 @@ static int acpi_processor_get_psd(struct acpi_processor *pr) pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) { printk(KERN_ERR PREFIX "Invalid _PSD:coord_type\n"); result = -EFAULT ; - goto end; } -end: + free_buffer:kfree (buffer.pointer);return result; }
Signature · 1 line
2.10.0
PATCH 8/30 ACPI-processor: Delete two unnecessary initialisations in acpi_processor_get_psd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 13:55:52 +0200
The local variables "psd" and "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_perflib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/processor_perflib.c +2 -2
@@ -529,11 +529,11 @@ EXPORT_SYMBOL(acpi_processor_notify_smm);static int acpi_processor_get_psd (struct acpi_processor *pr) {int result =0 ; -acpi_status status =AE_OK ; +acpi_status status;struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL };struct acpi_buffer format = {sizeof ("NNNNN" ),"NNNNN" };struct acpi_buffer state = {0 ,NULL }; -union acpi_object *psd =NULL ; +union acpi_object *psd;struct acpi_psd_package *pdomain; status =acpi_evaluate_object (pr->handle,"_PSD" ,NULL , &buffer);
Signature · 1 line
2.10.0
PATCH 9/30 ACPI-processor: Improve a size determination in acpi_processor_get_psd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 18:48:37 +0200
Replace the specification of a data structure by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/acpi/processor_perflib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_perflib.c +1 -1
@@ -556,7 +556,7 @@ static int acpi_processor_get_psd(struct acpi_processor *pr) pdomain = &(pr->performance->domain_info); - state.length =sizeof (struct acpi_psd_package ); + state.length =sizeof (*pdomain); state.pointer = pdomain; status = acpi_extract_package(&(psd->package.elements[0]),
Signature · 1 line
2.10.0
PATCH 10/30 ACPI-processor: Rename jump labels in acpi_processor_get_performance_control()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 18:50:48 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/acpi/processor_perflib.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/acpi/processor_perflib.c +4 -5
@@ -240,7 +240,7 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr) || (pct->package.count != 2)) { printk(KERN_ERR PREFIX "Invalid _PCT data\n"); result = -EFAULT ; - goto end; + goto free_buffer; }/*
@@ -254,7 +254,7 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr) || (obj.buffer.pointer = NULL)) { printk(KERN_ERR PREFIX "Invalid _PCT data (control_register)\n"); result = -EFAULT ; - goto end; + goto free_buffer; }memcpy (&pr->performance->control_register, obj.buffer.pointer,sizeof (struct acpi_pct_register ));
@@ -270,13 +270,12 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr) || (obj.buffer.pointer = NULL)) { printk(KERN_ERR PREFIX "Invalid _PCT data (status_register)\n"); result = -EFAULT ; - goto end; + goto free_buffer; }memcpy (&pr->performance->status_register, obj.buffer.pointer,sizeof (struct acpi_pct_register )); - - end: + free_buffer:kfree (buffer.pointer);return result;
Signature · 1 line
2.10.0
PATCH 11/30 ACPI-processor: Delete two unnecessary initialisations in acpi_processor_get_performance_control()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 19:01:36 +0200
The local variables "pct" and "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_perflib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/processor_perflib.c +2 -2
@@ -223,9 +223,9 @@ void acpi_processor_ppc_exit(void)static int acpi_processor_get_performance_control (struct acpi_processor *pr) {int result =0 ; -acpi_status status =0 ; +acpi_status status;struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; -union acpi_object *pct =NULL ; +union acpi_object *pct;union acpi_object obj = {0 };
Signature · 1 line
2.10.0
PATCH 12/30 ACPI-processor: Rename jump labels in acpi_processor_ppc_notifier()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 19:04:05 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/acpi/processor_perflib.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/acpi/processor_perflib.c +3 -4
@@ -90,18 +90,17 @@ static int acpi_processor_ppc_notifier(struct notifier_block *nb, pr =per_cpu (processors, policy->cpu);if (!pr || !pr->performance) - goto out; + goto unlock; ppc = (unsigned int )pr->performance_platform_limit;if (ppc >= pr->performance->state_count) - goto out; + goto unlock;cpufreq_verify_within_limits (policy,0 , pr->performance->states[ppc]. core_frequency *1000 ); - - out: + unlock:mutex_unlock (&performance_mutex);return 0 ;
Signature · 1 line
2.10.0
PATCH 13/30 ACPI-processor: Delete an unnecessary initialisation in acpi_processor_ppc_notifier()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 19:06:18 +0200
The local variable "ppc" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_perflib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_perflib.c +1 -1
@@ -73,7 +73,7 @@ static int acpi_processor_ppc_notifier(struct notifier_block *nb, {struct cpufreq_policy *policy = data;struct acpi_processor *pr; -unsigned int ppc =0 ; +unsigned int ppc;if (event =CPUFREQ_START && ignore_ppc <=0 ) { ignore_ppc =0 ;
Signature · 1 line
2.10.0
I have nothing to do with ACPI. Please stop spamming me, or you'll end up on a kill file...
Paolo
----- Original Message -----
Quoted 60 lines
From: "SF Markus Elfring" <[email protected]>
To: [email protected], "Len Brown" <[email protected]>, "Rafael J. Wysocki" <[email protected]>
Cc: "LKML" <[email protected]>, [email protected], "Julia Lawall" <[email protected]>, "Paolo Bonzini" <[email protected]>
Sent: Saturday, September 10, 2016 11:30:08 AM
Subject: [PATCH 00/30] ACPI-processor: Fine-tuning for several function implementationsFrom: Markus Elfring <[email protected]>
Date: Tue, 9 Sep 2016 20:15:05 +0200Several update suggestions were taken into account from static source code analysis.
Markus Elfring (30):
Usekmalloc_array()inacpi_processor_get_performance_states()Improve two size determinations inacpi_processor_get_performance_states()Rename jump labels inacpi_processor_get_performance_states()Delete two unnecessary initialisations inacpi_processor_get_performance_states()
Rename jump labels inacpi_processor_preregister_performance()Move a success indication inacpi_processor_preregister_performance()Rename jump labels inacpi_processor_get_psd()
Delete two unnecessary initialisations inacpi_processor_get_psd()Improve a size determination inacpi_processor_get_psd()
Rename jump labels inacpi_processor_get_performance_control()Delete two unnecessary initialisations inacpi_processor_get_performance_control()
Rename jump labels inacpi_processor_ppc_notifier()
Delete an unnecessary initialisation inacpi_processor_ppc_notifier()Delete an unnecessary initialisation inacpi_processor_get_performance_info()
Delete an unnecessary initialisation inacpi_processor_get_platform_limit()Usekmalloc_array()inacpi_processor_get_throttling_states()Improve another size determination inacpi_processor_get_throttling_states()
Rename jump labels inacpi_processor_get_throttling_states()Delete two unnecessary initialisations inacpi_processor_get_throttling_states()
Fix jump targets inacpi_processor_get_throttling_info()
Rename jump labels inacpi_processor_get_tsd()
Delete two unnecessary initialisations inacpi_processor_get_tsd()Improve a size determination inacpi_processor_get_tsd()
Rename jump labels inacpi_processor_get_throttling_control()Delete two unnecessary initialisations inacpi_processor_get_throttling_control()
Fix jump targets inacpi_processor_reevaluate_tstate()
Delete an unnecessary initialisation inacpi_processor_reevaluate_tstate()Rename a jump label inacpi_processor_get_platform_limit()Delete an unnecessary initialisation inacpi_processor_get_platform_limit()Improve jump targets inacpi_processor_update_tsd_coord()drivers/acpi/processor_perflib.c | 87 +++++++++++++-------------- drivers/acpi/processor_throttling.c | 116 ++++++++++++++++-------------------- 2 files changed, 93 insertions(+), 110 deletions(-)--
2.10.0
PATCH 14/30 ACPI-processor: Delete an unnecessary initialisation in acpi_processor_get_performance_info()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 19:09:32 +0200
The local variable "result" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_perflib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_perflib.c +1 -1
@@ -423,7 +423,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)int acpi_processor_get_performance_info (struct acpi_processor *pr) { -int result =0 ; +int result;if (!pr || !pr->performance || !pr->handle)return -EINVAL ;
Signature · 1 line
2.10.0
PATCH 15/30 ACPI-processor: Delete an unnecessary initialisation in acpi_processor_get_platform_limit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 19:12:06 +0200
The local variable "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_perflib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_perflib.c +1 -1
@@ -112,7 +112,7 @@ static struct notifier_block acpi_ppc_notifier_block = {static int acpi_processor_get_platform_limit (struct acpi_processor *pr) { -acpi_status status =0 ; +acpi_status status;unsigned long long ppc =0 ;
Signature · 1 line
2.10.0
PATCH 16/30 ACPI-processor: Use kmalloc_array() in acpi_processor_get_throttling_states()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 19:15:02 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/acpi/processor_throttling.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/acpi/processor_throttling.c +4 -2
@@ -533,9 +533,10 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) tss->package.count)); pr->throttling.state_count = tss->package.count; - pr->throttling.states_tss -kmalloc (sizeof (struct acpi_processor_tx_tss ) * tss->package.count, -GFP_KERNEL ); + pr->throttling.states_tss =kmalloc_array (tss->package.count, +sizeof (*pr-> + throttling.states_tss), +GFP_KERNEL );if (!pr->throttling.states_tss) { result = -ENOMEM ; goto end;
Signature · 1 line
2.10.0
PATCH 17/30 ACPI-processor: Improve another size determination in acpi_processor_get_throttling_states()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 19:19:27 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/acpi/processor_throttling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_throttling.c +1 -1
@@ -548,7 +548,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) (struct acpi_processor_tx_tss *)&(pr->throttling. states_tss[i]); - state.length =sizeof (struct acpi_processor_tx_tss ); + state.length =sizeof (*tx); state.pointer = tx;ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"Extracting state %d\n" , i));
Signature · 1 line
2.10.0
PATCH 18/30 ACPI-processor: Rename jump labels in acpi_processor_get_throttling_states()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 19:26:33 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/acpi/processor_throttling.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/acpi/processor_throttling.c +5 -6
@@ -526,7 +526,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)if (!tss || (tss->type !=ACPI_TYPE_PACKAGE )) { printk(KERN_ERR PREFIX "Invalid _TSS data\n"); result = -EFAULT ; - goto end; + goto free_buffer; } ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
@@ -539,7 +539,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) GFP_KERNEL);if (!pr->throttling.states_tss) { result = -ENOMEM ; - goto end; + goto free_buffer; }for (i =0 ; i < pr->throttling.state_count; i++) {
@@ -559,7 +559,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)ACPI_EXCEPTION ((AE_INFO , status,"Invalid _TSS data" )); result = -EFAULT ;kfree (pr->throttling.states_tss); - goto end; + goto free_buffer; }if (!tx->freqpercentage) {
@@ -567,11 +567,10 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) "Invalid _TSS data: freq is zero\n"); result = -EFAULT ;kfree (pr->throttling.states_tss); - goto end; + goto free_buffer; } } - - end: + free_buffer:kfree (buffer.pointer);return result;
Signature · 1 line
2.10.0
PATCH 19/30 ACPI-processor: Delete two unnecessary initialisations in acpi_processor_get_throttling_states()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 20:00:43 +0200
The local variables "tss" and "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_throttling.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/processor_throttling.c +2 -2
@@ -507,11 +507,11 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)static int acpi_processor_get_throttling_states (struct acpi_processor *pr) {int result =0 ; -acpi_status status =AE_OK ; +acpi_status status;struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL };struct acpi_buffer format = {sizeof ("NNNNN" ),"NNNNN" };struct acpi_buffer state = {0 ,NULL }; -union acpi_object *tss =NULL ; +union acpi_object *tss;int i; status =acpi_evaluate_object (pr->handle,"_TSS" ,NULL , &buffer);
Signature · 1 line
2.10.0
PATCH 20/30 ACPI-processor: Fix jump targets in acpi_processor_get_throttling_info()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 20:32:46 +0200
1. Adjust jump targets according to the current Linux coding style convention.
2. Delete a duplicate check then at the end.
3. Omit the explicit initialisation for the local variable "result" at the beginning which became unnecessary with this refactoring.
--- drivers/acpi/processor_throttling.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/acpi/processor_throttling.c +6 -8
@@ -1184,7 +1184,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,int acpi_processor_get_throttling_info (struct acpi_processor *pr) { -int result =0 ; +int result;struct acpi_processor_throttling *pthrottling; ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -1249,7 +1249,7 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr) result =acpi_processor_get_throttling (pr);if (result) - goto end; + goto disable_throttling;if (pr->throttling.state) { ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -1257,13 +1257,11 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr) pr->throttling.state)); result =acpi_processor_set_throttling (pr,0 , false);if (result) - goto end; + goto disable_throttling; } - - end: -if (result) - pr->flags.throttling =0 ; - +return 0 ; + disable_throttling: + pr->flags.throttling =0 ;return result; }
Signature · 1 line
2.10.0
PATCH 21/30 ACPI-processor: Rename jump labels in acpi_processor_get_tsd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 20:50:12 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/acpi/processor_throttling.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/acpi/processor_throttling.c +6 -7
@@ -605,13 +605,13 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr)if (!tsd || (tsd->type !=ACPI_TYPE_PACKAGE )) { printk(KERN_ERR PREFIX "Invalid _TSD data\n"); result = -EFAULT ; - goto end; + goto free_buffer; }if (tsd->package.count !=1 ) { printk(KERN_ERR PREFIX "Invalid _TSD data\n"); result = -EFAULT ; - goto end; + goto free_buffer; } pdomain = &(pr->throttling.domain_info);
@@ -624,19 +624,19 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr)if (ACPI_FAILURE (status)) { printk(KERN_ERR PREFIX "Invalid _TSD data\n"); result = -EFAULT ; - goto end; + goto free_buffer; }if (pdomain->num_entries !=ACPI_TSD_REV0_ENTRIES ) { printk(KERN_ERR PREFIX "Unknown _TSD:num_entries\n"); result = -EFAULT ; - goto end; + goto free_buffer; }if (pdomain->revision !=ACPI_TSD_REV0_REVISION ) { printk(KERN_ERR PREFIX "Unknown _TSD:revision\n"); result = -EFAULT ; - goto end; + goto free_buffer; } pthrottling = &pr->throttling;
@@ -654,8 +654,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr) pthrottling->tsd_valid_flag =0 ; pthrottling->shared_type =DOMAIN_COORD_TYPE_SW_ALL ; } - - end: + free_buffer:kfree (buffer.pointer);return result; }
Signature · 1 line
2.10.0
PATCH 22/30 ACPI-processor: Delete two unnecessary initialisations in acpi_processor_get_tsd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 20:52:33 +0200
The local variables "tsd" and "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_throttling.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/processor_throttling.c +2 -2
@@ -582,11 +582,11 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)static int acpi_processor_get_tsd (struct acpi_processor *pr) {int result =0 ; -acpi_status status =AE_OK ; +acpi_status status;struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL };struct acpi_buffer format = {sizeof ("NNNNN" ),"NNNNN" };struct acpi_buffer state = {0 ,NULL }; -union acpi_object *tsd =NULL ; +union acpi_object *tsd;struct acpi_tsd_package *pdomain;struct acpi_processor_throttling *pthrottling;
Signature · 1 line
2.10.0
PATCH 23/30 ACPI-processor: Improve a size determination in acpi_processor_get_tsd()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 20:55:45 +0200
Replace the specification of a data structure by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/acpi/processor_throttling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_throttling.c +1 -1
@@ -616,7 +616,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr) pdomain = &(pr->throttling.domain_info); - state.length =sizeof (struct acpi_tsd_package ); + state.length =sizeof (*pdomain); state.pointer = pdomain; status = acpi_extract_package(&(tsd->package.elements[0]),
Signature · 1 line
2.10.0
PATCH 24/30 ACPI-processor: Rename jump labels in acpi_processor_get_throttling_control()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 21:12:17 +0200
Adjust jump labels according to the current Linux coding style convention.
--- drivers/acpi/processor_throttling.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/acpi/processor_throttling.c +5 -7
@@ -442,7 +442,7 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) || (ptc->package.count != 2)) { printk(KERN_ERR PREFIX "Invalid _PTC data\n"); result = -EFAULT ; - goto end; + goto free_buffer; }/*
@@ -457,7 +457,7 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) printk(KERN_ERR PREFIX "Invalid _PTC data (control_register)\n"); result = -EFAULT ; - goto end; + goto free_buffer; }memcpy (&pr->throttling.control_register, obj.buffer.pointer,sizeof (struct acpi_ptc_register ));
@@ -473,7 +473,7 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) || (obj.buffer.pointer = NULL)) { printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n"); result = -EFAULT ; - goto end; + goto free_buffer; } memcpy(&pr->throttling.status_register, obj.buffer.pointer,
@@ -485,17 +485,15 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) throttling->control_register.bit_offset) > 32) { printk(KERN_ERR PREFIX "Invalid _PTC control register\n"); result = -EFAULT ; - goto end; + goto free_buffer; }if ((throttling->status_register.bit_width + throttling->status_register.bit_offset) >32 ) { printk(KERN_ERR PREFIX "Invalid _PTC status register\n"); result = -EFAULT ; - goto end; } - - end: + free_buffer:kfree (buffer.pointer);return result;
Signature · 1 line
2.10.0
PATCH 25/30 ACPI-processor: Delete two unnecessary initialisations in acpi_processor_get_throttling_control()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 21:17:12 +0200
The local variables "ptc" and "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_throttling.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/processor_throttling.c +2 -2
@@ -423,9 +423,9 @@ end:static int acpi_processor_get_throttling_control (struct acpi_processor *pr) {int result =0 ; -acpi_status status =0 ; +acpi_status status;struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; -union acpi_object *ptc =NULL ; +union acpi_object *ptc;union acpi_object obj = {0 };struct acpi_processor_throttling *throttling;
Signature · 1 line
2.10.0
PATCH 26/30 ACPI-processor: Fix jump targets in acpi_processor_reevaluate_tstate()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 21:40:40 +0200
1. Adjust jump targets according to the current Linux coding style convention.
2. Delete a duplicate check then at the end.
3. Do not use curly brackets at two source code places where a single statement should be sufficient.
--- drivers/acpi/processor_throttling.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/acpi/processor_throttling.c +9 -14
@@ -379,23 +379,19 @@ void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, {int result =0 ; -if (action =CPU_DEAD ) { +if (action =CPU_DEAD )/* When one CPU is offline, the T-state throttling * will be invalidated. */ - pr->flags.throttling =0 ; -return ; - } + goto disable_throttling;/* the following is to recheck whether the T-state is valid for * the online CPU */ -if (!pr->throttling.state_count) { +if (!pr->throttling.state_count)/* If the number of T-state is invalid, it is * invalidated. */ - pr->flags.throttling =0 ; -return ; - } + goto disable_throttling; pr->flags.throttling =1 ;/* Disable throttling (if enabled). We'll let subsequent
@@ -405,17 +401,16 @@ void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, result =acpi_processor_get_throttling (pr);if (result) - goto end; + goto disable_throttling;if (pr->throttling.state) { result =acpi_processor_set_throttling (pr,0 , false);if (result) - goto end; + goto disable_throttling; } - -end: -if (result) - pr->flags.throttling =0 ; +return ; + disable_throttling: + pr->flags.throttling =0 ; }/* * _PTC - Processor Throttling Control (and status) register location
Signature · 1 line
2.10.0
PATCH 27/30 ACPI-processor: Delete an unnecessary initialisation in acpi_processor_reevaluate_tstate()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 21:42:34 +0200
The local variable "result" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_throttling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_throttling.c +1 -1
@@ -377,7 +377,7 @@ int acpi_processor_tstate_has_changed(struct acpi_processor *pr)void acpi_processor_reevaluate_tstate (struct acpi_processor *pr,unsigned long action) { -int result =0 ; +int result;if (action =CPU_DEAD )/* When one CPU is offline, the T-state throttling
Signature · 1 line
2.10.0
PATCH 28/30 ACPI-processor: Rename a jump label in acpi_processor_get_platform_limit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 21:50:04 +0200
Adjust a jump label according to the current Linux coding style convention.
--- drivers/acpi/processor_throttling.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/acpi/processor_throttling.c +2 -3
@@ -294,7 +294,7 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)return -EINVAL ;if (ignore_tpc) - goto end; + goto limit_throttling; status =acpi_evaluate_integer (pr->handle,"_TPC" ,NULL , &tpc);if (ACPI_FAILURE (status)) {
@@ -303,8 +303,7 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr) }return -ENODEV ; } - -end: + limit_throttling: pr->throttling_platform_limit = (int )tpc;return 0 ; }
Signature · 1 line
2.10.0
PATCH 29/30 ACPI-processor: Delete an unnecessary initialisation in acpi_processor_get_platform_limit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 22:00:07 +0200
The local variable "status" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/acpi/processor_throttling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/processor_throttling.c +1 -1
@@ -287,7 +287,7 @@ static int acpi_processor_throttling_notifier(unsigned long event, void *data)*/ static int acpi_processor_get_platform_limit (struct acpi_processor *pr) { -acpi_status status =0 ; +acpi_status status;unsigned long long tpc =0 ;if (!pr)
Signature · 1 line
2.10.0
PATCH 30/30 ACPI-processor: Improve jump targets in acpi_processor_update_tsd_coord()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 22:18:30 +0200
* Adjust jump targets according to the current Linux coding style convention.
* Delete a duplicate check then.
--- drivers/acpi/processor_throttling.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/acpi/processor_throttling.c +4 -7
@@ -97,11 +97,9 @@ static int acpi_processor_update_tsd_coord(void)*/ if (!pthrottling->tsd_valid_flag) { retval = -EINVAL ; -break ; + goto free_cpumask; } } -if (retval) - goto err_ret;for_each_possible_cpu (i) { pr =per_cpu (processors, i);
@@ -147,12 +145,12 @@ static int acpi_processor_update_tsd_coord(void)*/ if (match_pdomain->num_processors != count_target) { retval = -EINVAL ; - goto err_ret; + goto free_cpumask; }if (pdomain->coord_type != match_pdomain->coord_type) { retval = -EINVAL ; - goto err_ret; + goto free_cpumask; }cpumask_set_cpu (j, covered_cpus);
@@ -180,8 +178,7 @@ static int acpi_processor_update_tsd_coord(void) pthrottling->shared_cpu_map); } } - -err_ret: + free_cpumask:free_cpumask_var (covered_cpus);for_each_possible_cpu (i) {
Signature · 1 line
2.10.0
Re: [PATCH 2/30] ACPI-processor: Improve two size determinations in acpi_processor_get_performance_states()
In reply to SF Markus ElfringQuoted 17 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 6 Sep 2016 11:11:12 +0200Replace the specification of a data structure by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- drivers/acpi/processor_perflib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/acpi/processor_perflib.c +0
-0
drivers/acpi/processor_perflib.c static int acpi_processor_get_performance_states(struct acpi_processor *pr) · line 361
Quoted 5 lines
drivers/acpi/processor_perflib.c +1
-1@@ -358,7 +358,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)struct acpi_processor_px *px = &(pr->performance->states[i]); - state.length =sizeof (struct acpi_processor_px ); + state.length =sizeof (*px);
How is this better?
Now the person reading the code has to go and lookup what px is in order to know what its size is and which goes in there. Sure, it is a couple of lines up but this is not always the case...
drivers/acpi/processor_perflib.c static int acpi_processor_get_performance_states(struct acpi_processor *pr) · line 405
Quoted 11 lines
drivers/acpi/processor_perflib.c +2
-1state.pointer = px;ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"Extracting state %d\n" , i));@@ -400,7 +400,8 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)* Copy this valid entry over last_invalid entry */ memcpy (&(pr->performance->states[last_invalid]), - px,sizeof (struct acpi_processor_px )); + px, +sizeof (*px)); ++last_invalid;
... like here, for example.
In any case, I won't take this one if I were the maintainer.
Signature · 4 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.Quoted 37 lines
Date: Tue, 9 Sep 2016 20:15:05 +0200
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (30):
Usekmalloc_array()inacpi_processor_get_performance_states()Improve two size determinations inacpi_processor_get_performance_states()Rename jump labels inacpi_processor_get_performance_states()
Delete two unnecessary initialisations inacpi_processor_get_performance_states()Rename jump labels inacpi_processor_preregister_performance()
Move a success indication inacpi_processor_preregister_performance()Rename jump labels inacpi_processor_get_psd()
Delete two unnecessary initialisations inacpi_processor_get_psd()Improve a size determination inacpi_processor_get_psd()
Rename jump labels inacpi_processor_get_performance_control()Delete two unnecessary initialisations inacpi_processor_get_performance_control()Rename jump labels inacpi_processor_ppc_notifier()
Delete an unnecessary initialisation inacpi_processor_ppc_notifier()Delete an unnecessary initialisation inacpi_processor_get_performance_info()Delete an unnecessary initialisation inacpi_processor_get_platform_limit()Usekmalloc_array()inacpi_processor_get_throttling_states()Improve another size determination inacpi_processor_get_throttling_states()Rename jump labels inacpi_processor_get_throttling_states()
Delete two unnecessary initialisations inacpi_processor_get_throttling_states()Fix jump targets inacpi_processor_get_throttling_info()
Rename jump labels inacpi_processor_get_tsd()
Delete two unnecessary initialisations inacpi_processor_get_tsd()Improve a size determination inacpi_processor_get_tsd()
Rename jump labels inacpi_processor_get_throttling_control()
Delete two unnecessary initialisations inacpi_processor_get_throttling_control()Fix jump targets inacpi_processor_reevaluate_tstate()
Delete an unnecessary initialisation inacpi_processor_reevaluate_tstate()Rename a jump label inacpi_processor_get_platform_limit()
Delete an unnecessary initialisation inacpi_processor_get_platform_limit()Improve jump targets inacpi_processor_update_tsd_coord()
Quoted 3 lines
drivers/acpi/processor_perflib.c | 87 +++++++++++++-------------- drivers/acpi/processor_throttling.c | 116 ++++++++++++++++-------------------- 2 files changed, 93 insertions(+), 110 deletions(-)
How do you think about to take another look at change possibilities for these source files?
Regards,
Markus