Sony-laptop: Use common error handling code in sony_nc_setup_rfkill()
PATCH 1/1 Sony-laptop: Use common error handling code in sony_nc_setup_rfkill()
From: Markus Elfring <[email protected]>
Date: Mon, 30 Oct 2017 21:10:49 +0100
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
--- drivers/platform/x86/sony-laptop.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/platform/x86/sony-laptop.c +11 -9
@@ -1660,18 +1660,16 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,if (!rfk)return -ENOMEM ; -if (sony_call_snc_handle (sony_rfkill_handle,0x200 , &result) <0 ) { -rfkill_destroy (rfk); -return -1 ; - } +if (sony_call_snc_handle (sony_rfkill_handle,0x200 , &result) <0 ) + goto destroy_rfk; + hwblock = !(result &0x1 );if (sony_call_snc_handle (sony_rfkill_handle, - sony_rfkill_address[nc_type], - &result) <0 ) { -rfkill_destroy (rfk); -return -1 ; - } + sony_rfkill_address[nc_type], + &result) <0 ) + goto destroy_rfk; + swblock = !(result &0x2 );rfkill_init_sw_state (rfk, swblock);
@@ -1684,6 +1682,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device, } sony_rfkill_devices[nc_type] = rfk;return err; + +destroy_rfk: +rfkill_destroy (rfk); +return -1 ; }static void sony_nc_rfkill_update (void )
Signature · 1 line
2.14.3
Andy Shevchenko
NAKQuoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 30 Oct 2017 21:10:49 +0100Add a jump target so that a bit of exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
Apparently this patch done without reading the actual code.
NAK.
-1 is EPERM which sounds wrong here. If you would like to fix it, propagate a real error codes from sony_call_snc_handle().
Quoted 2 lines
if (!rfk)
return -ENOMEM;Okay error code.
drivers/platform/x86/sony-laptop.c static int sony_nc_setup_rfkill(struct acpi_device *device, · line 1665
Quoted 4 lines
drivers/platform/x86/sony-laptop.c +0
-3-if (sony_call_snc_handle (sony_rfkill_handle,0x200 , &result) <0 ) { -rfkill_destroy (rfk); -return -1 ;
Not okay.
drivers/platform/x86/sony-laptop.c static int sony_nc_setup_rfkill(struct acpi_device *device, · line 1673
Quoted 11 lines
drivers/platform/x86/sony-laptop.c +3
-5- } +if (sony_call_snc_handle (sony_rfkill_handle,0x200 , &result) <0 ) + goto destroy_rfk; + hwblock = !(result &0x1 ); if (sony_call_snc_handle(sony_rfkill_handle, - sony_rfkill_address[nc_type], - &result) <0 ) { -rfkill_destroy (rfk); -return -1 ;
Not okay and it might be different from previous case.
Quoted 9 lines
drivers/platform/x86/sony-laptop.c +4
-1- } + sony_rfkill_address[nc_type], + &result) < 0) + goto destroy_rfk; + swblock = !(result &0x2 );rfkill_init_sw_state (rfk, swblock);
drivers/platform/x86/sony-laptop.c static int sony_nc_setup_rfkill(struct acpi_device *device, · line 1688
Quoted 7 lines
drivers/platform/x86/sony-laptop.c +4
-0@@ -1684,6 +1682,10 @@ static int sony_nc_setup_rfkill(struct acpi_device *device, } sony_rfkill_devices[nc_type] = rfk;return err; + +destroy_rfk: +rfkill_destroy (rfk); +return -1 ;
P.S. Don't bother us with patches on which you didn't do your home work. Thanks for understanding.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 1 line
Apparently this patch done without reading the actual code.
I performed another simple software refactoring.
Quoted 4 lines
NAK.
-1 is EPERM which sounds wrong here. If you would like to fix it, propagate a real error codes from
sony_call_snc_handle().
I do not know at the moment why an error code which you find questionable was suggested by Marco Chiappero on 2012-05-19 and committed by Matthew Garrett on 2012-05-31 (according the commit d6f15ed876b83a1a0eba1d0473eef58acc95444a: use soft rfkill status stored in hw).
Quoted 4 lines
Quoted 2 lines
if (!rfk) return -ENOMEM;Okay error code.
Can any other identifier make more sense there?
Quoted 6 lines
Quoted 6 lines
drivers/platform/x86/sony-laptop.c +3
-1- } +if (sony_call_snc_handle (sony_rfkill_handle,0x200 , &result) <0 ) + goto destroy_rfk; + hwblock = !(result &0x1 );
Quoted 7 lines
drivers/platform/x86/sony-laptop.c static int sony_nc_setup_rfkill(struct acpi_device *device, · line 1673
Quoted 5 lines
if (sony_call_snc_handle(sony_rfkill_handle,
drivers/platform/x86/sony-laptop.c +0
-4- sony_rfkill_address[nc_type], - &result) < 0) { -rfkill_destroy (rfk); -return -1 ;Not okay and it might be different from previous case.
The shown function call was repeated with an other parameter. Which error reporting would you find more appropriate then?
Quoted 1 line
P.S. Don't bother us with patches on which you didn't do your home work.
Do we occasionally need to distinguish better between an ordinary refactoring and the adjustments for additional software improvements?
Regards,
Markus
Quoted 3 lines · SF Markus Elfring
Quoted 1 line
Apparently this patch done without reading the actual code.
I performed another simple software refactoring.
Which is _useless_ per se by the reasons you had been told already _several_ times about.
Either you do a real fix (propagate correct error codes to upper layers), or just don't bother at all.
Quoted 1 line
Quoted 1 line
NAK.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 3 lines
Quoted 1 line
I performed another simple software refactoring.
Which is _useless_ per se
I disagree in this case because the goal of a refactoring should be to adjust something in a desired direction without changing the provided functionality.
Quoted 1 line
by the reasons you had been told already _several_ times about.
There can be other reasons why you do not like a concrete change.
Quoted 2 lines
Either you do a real fix (propagate correct error codes to upper layers), or just don't bother at all.
Have the involved contributors any preferences on organisation of corresponding update steps?
* Correct exception handling first and then apply the shown source code reduction again.
* Combine better exception handling with smaller code in one patch.
* Addition of the tag “Fixes” in the commit message?
Regards,
Markus
v2 cover Sony-laptop: Adjustments for sony_nc_setup_rfkill()
In reply to Andy ShevchenkoFrom: Markus Elfring <[email protected]>
Date: Wed, 1 Nov 2017 19:34:56 +0100
Three update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Fix exception handling
Delete an unnecessary variable initialisation
Use common error handling code
---
v2:
Two additional suggestions were taken into account from a corresponding source code review.
drivers/platform/x86/sony-laptop.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)
Signature · 1 line
2.14.3
PATCH v2 1/3 Sony-laptop: Fix exception handling in sony_nc_setup_rfkill()
From: Markus Elfring <[email protected]>
Date: Wed, 1 Nov 2017 18:42:45 +0100
Source code review for a specific software refactoring showed the need for another correction because the error code "-1" was returned so far if a call of the function "sony_call_snc_handle" failed here. Thus assign the return value from these two function calls also to the variable "err" and provide it in case of a failure.
--- drivers/platform/x86/sony-laptop.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/platform/x86/sony-laptop.c +8 -6
@@ -1660,17 +1660,19 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,if (!rfk)return -ENOMEM ; -if (sony_call_snc_handle (sony_rfkill_handle,0x200 , &result) <0 ) { + err =sony_call_snc_handle (sony_rfkill_handle,0x200 , &result); +if (err <0 ) {rfkill_destroy (rfk); -return -1 ; +return err; } hwblock = !(result &0x1 ); -if (sony_call_snc_handle (sony_rfkill_handle, - sony_rfkill_address[nc_type], - &result) <0 ) { + err =sony_call_snc_handle (sony_rfkill_handle, + sony_rfkill_address[nc_type], + &result); +if (err <0 ) {rfkill_destroy (rfk); -return -1 ; +return err; } swblock = !(result &0x2 );
Signature · 1 line
2.14.3
Re: [PATCH v2 1/3] Sony-laptop: Fix exception handling in sony_nc_setup_rfkill()
Quoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 1 Nov 2017 18:42:45 +0100Source code review for a specific software refactoring showed the need for another correction because the error code "-1" was returned so far if a call of the function "
sony_call_snc_handle" failed here. Thus assign the return value from these two function calls also to the variable "err" and provide it in case of a failure.
Applied to my review and testing queue, thanks!
Quoted 42 lines
Fixes d6f15ed876b83a1a0eba1d0473eef58acc95444a ("sony-laptop: use soft rfkill status stored in hw")Suggested-by Andy Shevchenko <[email protected]>Link https://lkml.kernel.org/r/<CAHp75VcMkXCioCzmLE0+BTmkqc5RSOx9yPO0ectVHMrMvewgwg@mail.gmail.com> open hereSigned-off-by Markus Elfring <[email protected]>--- drivers/platform/x86/sony-laptop.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/platform/x86/sony-laptop.c +8
-7@@ -1660,17 +1660,19 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,if (!rfk)return -ENOMEM ; -if (sony_call_snc_handle (sony_rfkill_handle,0x200 , &result) <0 ) { + err =sony_call_snc_handle (sony_rfkill_handle,0x200 , &result); +if (err <0 ) {rfkill_destroy (rfk); -return -1 ; +return err; } hwblock = !(result &0x1 ); -if (sony_call_snc_handle (sony_rfkill_handle, - sony_rfkill_address[nc_type], - &result) <0 ) { + err =sony_call_snc_handle (sony_rfkill_handle, + sony_rfkill_address[nc_type], + &result); +if (err <0 ) {rfkill_destroy (rfk); -return -1 ; +return err; } swblock = !(result &0x2 ); --2.14.3
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 2/3 Sony-laptop: Delete an unnecessary variable initialisation in sony_nc_setup_rfkill()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 1 Nov 2017 19:00:59 +0100
The local variable "err" will eventually be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/platform/x86/sony-laptop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/sony-laptop.c +1 -1
@@ -1627,7 +1627,7 @@ static const struct rfkill_ops sony_rfkill_ops = {static int sony_nc_setup_rfkill (struct acpi_device *device,enum sony_nc_rfkill nc_type) { -int err =0 ; +int err;struct rfkill *rfk;enum rfkill_type type;const char *name;
Signature · 1 line
2.14.3
Re: [PATCH v2 2/3] Sony-laptop: Delete an unnecessary variable initialisation in sony_nc_setup_rfkill()
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 1 Nov 2017 19:00:59 +0100The local variable "err" will eventually be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
Applied to my review and testing queue, thanks!
Quoted 22 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/platform/x86/sony-laptop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/platform/x86/sony-laptop.c +1
-2@@ -1627,7 +1627,7 @@ static const struct rfkill_ops sony_rfkill_ops = {static int sony_nc_setup_rfkill (struct acpi_device *device,enum sony_nc_rfkill nc_type) { -int err =0 ; +int err;struct rfkill *rfk;enum rfkill_type type;const char *name; --2.14.3
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 3/3 Sony-laptop: Use common error handling code in sony_nc_setup_rfkill()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 1 Nov 2017 19:17:01 +0100
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
---
v2:
This software refactoring was repeated after the error code handling was adjusted for two function calls.
drivers/platform/x86/sony-laptop.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/platform/x86/sony-laptop.c +13 -12
@@ -1661,31 +1661,32 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,return -ENOMEM ; err =sony_call_snc_handle (sony_rfkill_handle,0x200 , &result); -if (err <0 ) { -rfkill_destroy (rfk); -return err; - } +if (err <0 ) + goto destroy_rfk; + hwblock = !(result &0x1 ); err =sony_call_snc_handle (sony_rfkill_handle, sony_rfkill_address[nc_type], &result); -if (err <0 ) { -rfkill_destroy (rfk); -return err; - } +if (err <0 ) + goto destroy_rfk; + swblock = !(result &0x2 );rfkill_init_sw_state (rfk, swblock);rfkill_set_hw_state (rfk, hwblock); err =rfkill_register (rfk); -if (err) { -rfkill_destroy (rfk); -return err; - } +if (err) + goto destroy_rfk; + sony_rfkill_devices[nc_type] = rfk;return err; + +destroy_rfk: +rfkill_destroy (rfk); +return err; }static void sony_nc_rfkill_update (void )
Signature · 1 line
2.14.3
Re: [PATCH v2 0/3] Sony-laptop: Adjustments for sony_nc_setup_rfkill()
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 1 Nov 2017 19:34:56 +0100Three update suggestions were taken into account
from static source code analysis.
I have applied first two, the last one is subject to discuss a necessity of it.
So, if Darren on my side than we won't apply it, if he opposes, I would hear an argument why we might need it.
Quoted 17 lines
Markus Elfring (3):
Fix exception handling
Delete an unnecessary variable initialisation
Use common error handling code
---v2:
Two additional suggestions were taken into account from a corresponding source code review.drivers/platform/x86/sony-laptop.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)--
2.14.3
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 0/3] Sony-laptop: Adjustments for sony_nc_setup_rfkill()
Quoted 1 line
I have applied first two,
Thanks for another change acceptance.
Quoted 1 line
the last one is subject to discuss a necessity of it.
I can offer another bit of information for this software development discussion.
The following build settings were active in my “Makefile” for this Linux test case.
…
HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O0 -fomit-frame-pointer -std=gnu89
…
The affected source file can be compiled for the processor architecture “x86_64” by a tool like “GCC 6.4.1+r251631-1.3” from the software distribution “openSUSE Tumbleweed” with the following command example.
my_cc=/usr/bin/gcc-6 \
&& my_module=drivers/platform/x86/sony-laptop.ko \
&& git checkout ':/^Sony-laptop: Delete an unnecessary variable initialisation in sony_nc_setup_rfkill' \
&& make -j4 CC="${my_cc}" HOSTCC="${my_cc}" allmodconfig "${my_module}" \
&& size "${my_module}" \
&& git checkout ':/^Sony-laptop: Use common error handling code in sony_nc_setup_rfkill' \
&& make -j4 CC="${my_cc}" HOSTCC="${my_cc}" allmodconfig "${my_module}" \
&& size "${my_module}"
Do you find the following details useful for further clarification?
text: -32 data: 0 bss: 0
Regards,
Markus
Re: [PATCH v2 0/3] Sony-laptop: Adjustments for sony_nc_setup_rfkill()
Quoted 30 lines · SF Markus Elfring
Quoted 1 line
I have applied first two,
Thanks for another change acceptance.
Quoted 1 line
the last one is subject to discuss a necessity of it.
I can offer another bit of information for this software development discussion.
The following build settings were active in my “Makefile” for this Linux test case.
…
HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O0 -fomit-frame-pointer -std=gnu89
…The affected source file can be compiled for the processor architecture “x86_64” by a tool like “GCC 6.4.1+r251631-1.3” from the software distribution “openSUSE Tumbleweed” with the following command example.
my_cc=/usr/bin/gcc-6 \
&& my_module=drivers/platform/x86/sony-laptop.ko \
&& git checkout ':/^Sony-laptop: Delete an unnecessary variable initialisation insony_nc_setup_rfkill' \
&& make -j4 CC="${my_cc}" HOSTCC="${my_cc}" allmodconfig "${my_module}" \
&& size "${my_module}" \
&& git checkout ':/^Sony-laptop: Use common error handling code insony_nc_setup_rfkill' \
&& make -j4 CC="${my_cc}" HOSTCC="${my_cc}" allmodconfig "${my_module}" \
&& size "${my_module}"
Quoted 5 lines
Do you find the following details useful for further clarification?
text: -32 data: 0 bss: 0
...but kernel is compiled with -O2 which, I suppose, will eliminate these repeats.
So, the main question is "WHY" you are doing this change.
I didn't find any convinced explanation (yet?).
As an example, I would understand it if the consequent patch will bring locking to the function.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: Sony-laptop: Adjustments for sony_nc_setup_rfkill()
Quoted 7 lines
Quoted 5 lines
Do you find the following details useful for further clarification?
text: -32 data: 0 bss: 0...but kernel is compiled with -O2 which,
Did you try to compare results for my update suggestion also with the default build configuration?
Quoted 1 line
I suppose, will eliminate these repeats.
My build results did not fit to your expectations.
Quoted 3 lines
So, the main question is "WHY" you are doing this change.
I didn't find any convinced explanation (yet?).
Do you find a reduction of 32 bytes for the object code not interesting enough just by achieving such a small effect because of the replacement of three function calls “rfkill_destroy” with goto statements?
Regards,
Markus
Re: Sony-laptop: Adjustments for sony_nc_setup_rfkill()
Quoted 5 lines · SF Markus Elfring
Quoted 5 lines
Quoted 5 lines
Do you find the following details useful for further clarification?
text: -32 data: 0 bss: 0
...
Quoted 7 lines
Quoted 3 lines
So, the main question is "WHY" you are doing this change.
I didn't find any convinced explanation (yet?).
Do you find a reduction of 32 bytes for the object code not interesting enough just by achieving such a small effect because of the replacement of three function calls “rfkill_destroy” with goto statements?
Okay, it's something.
Update a commit message in your patch, use bloat-o-meter (and put its output to the commit message) and resend, we might reconsider then.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: Sony-laptop: Adjustments for sony_nc_setup_rfkill()
Quoted 2 lines
Update a commit message in your patch, use bloat-o-meter (and put its output to the commit message) and resend, we might reconsider then.
Do you expect a resend only for the third update step of this small patch series (together with additional information)?
Regards,
Markus
Re: Sony-laptop: Adjustments for sony_nc_setup_rfkill()
Quoted 5 lines · SF Markus Elfring
Quoted 2 lines
Update a commit message in your patch, use bloat-o-meter (and put its output to the commit message) and resend, we might reconsider then.
Do you expect a resend only for the third update step of this small patch series (together with additional information)?
First two already applied.
So, the third patch is in question, please resend it with asked commit message update.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: Sony-laptop: Adjustments for sony_nc_setup_rfkill()
Quoted 1 line
First two already applied.
This is nice.
Quoted 2 lines
So, the third patch is in question, please resend it with asked commit message update.
I find such a resend questionable at the moment.
Which details do you expect from the software “scripts/bloat-o-meter” more than I provided for the discussed Linux module already?
Regards,
Markus