misc: bh1770glc: Use common error handling code in bh1770_power_state_store()
Subsystems (2)
PATCH 1/1 misc: bh1770glc: Use common error handling code in bh1770_power_state_store()
From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 18:00:31 +0200
Adjust jump targets so that a bit of exception handling can be better reused in an if branch of this function.
This issue was detected by using the Coccinelle software.
--- drivers/misc/bh1770glc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/misc/bh1770glc.c +5 -6
@@ -660,15 +660,14 @@ static ssize_t bh1770_power_state_store(struct device *dev,pm_runtime_get_sync (dev); ret =bh1770_lux_rate (chip, chip->lux_rate_index); -if (ret <0 ) { -pm_runtime_put (dev); - goto leave; - } +if (ret <0 ) + goto put_runtime; ret =bh1770_lux_interrupt_control (chip,BH1770_ENABLE );if (ret <0 ) { +put_runtime:pm_runtime_put (dev); - goto leave; + goto unlock; }/* This causes interrupt after the next measurement cycle */
@@ -681,7 +680,7 @@ static ssize_t bh1770_power_state_store(struct device *dev,pm_runtime_put (dev); } ret = count; -leave: +unlock:mutex_unlock (&chip->mutex);return ret; }
Signature · 1 line
2.14.3
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 18:00:31 +0200Adjust jump targets so that a bit of exception handling can be better reused in an if branch of this function.
What is the benefit brought by this change?
Anyhow, are you seriously suggesting adding a goto to a label define within a if block? Is this somehow an Halloween related joke?
Quoted 41 lines
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- drivers/misc/bh1770glc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/misc/bh1770glc.c +5
-6@@ -660,15 +660,14 @@ static ssize_t bh1770_power_state_store(struct device *dev,pm_runtime_get_sync (dev); ret =bh1770_lux_rate (chip, chip->lux_rate_index); -if (ret <0 ) { -pm_runtime_put (dev); - goto leave; - } +if (ret <0 ) + goto put_runtime; ret =bh1770_lux_interrupt_control (chip,BH1770_ENABLE );if (ret <0 ) { +put_runtime:pm_runtime_put (dev); - goto leave; + goto unlock; }/* This causes interrupt after the next measurement cycle */ @@ -681,7 +680,7 @@ static ssize_t bh1770_power_state_store(struct device *dev,pm_runtime_put (dev); } ret = count; -leave: +unlock:mutex_unlock (&chip->mutex);return ret; }
Greg Kroah-Hartman
maintainerQuoted 8 lines · Daniele Nicolodi
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 27 Oct 2017 18:00:31 +0200Adjust jump targets so that a bit of exception handling can be better reused in an if branch of this function.
What is the benefit brought by this change?
Please note, you are responding to someone who lots and lots of kernel maintainers/developers have blacklisted, myself included. It's just not worth your effort, I recommend doing the same, as I'm not applying any patches from this author, unless some other maintainer wants to take the time to validate and send them on to me.
kill-files are a good thing, please use them :)
good luck!
greg k-h
Quoted 4 lines
Quoted 2 lines
Adjust jump targets so that a bit of exception handling can be better reused in an if branch of this function.
What is the benefit brought by this change?
Will you notice that the object code size can be a bit smaller because the call of the function “pm_runtime_put” is specified at two places in the implementation in comparison to three places before?
Quoted 2 lines
Anyhow, are you seriously suggesting adding a goto to a label define within a if block?
Yes. - For this update suggestion.
Quoted 1 line
Is this somehow an Halloween related joke?
I hope not.
Another software design approach would be to move two statements from the affected if branch to the end of this function. Such an adjustment would have the consequence that the statement “goto unlock” will be transformed into a jump to a backward target.
Would you prefer such an implementation variant instead?
Regards,
Markus