soc: qcom: pmic_glink_altmode: Use common error handling code in pmic_glink_altmode_probe()
PATCH 1/1 soc: qcom: pmic_glink_altmode: Use common error handling code in pmic_glink_altmode_probe()
From: Markus Elfring <[email protected]>
Date: Wed, 28 Feb 2024 18:45:13 +0100
Add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.
This issue was transformed by using the Coccinelle software.
--- drivers/soc/qcom/pmic_glink_altmode.c | 57 +++++++++++++-------------- 1 file changed, 27 insertions(+), 30 deletions(-)
drivers/soc/qcom/pmic_glink_altmode.c +27 -30
@@ -434,8 +434,7 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, ret =fwnode_property_read_u32 (fwnode,"reg" , &port);if (ret <0 ) {dev_err (dev,"missing reg property of %pOFn\n" , fwnode); -fwnode_handle_put (fwnode); -return ret; + goto put_fwnode; }if (port >=ARRAY_SIZE (altmode->ports)) {
@@ -445,8 +444,8 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev,if (altmode->ports[port].altmode) {dev_err (dev,"multiple connector definition for port %u\n" , port); -fwnode_handle_put (fwnode); -return -EINVAL ; + ret = -EINVAL ; + goto put_fwnode; } alt_port = &altmode->ports[port];
@@ -456,8 +455,8 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, alt_port->bridge =devm_drm_dp_hpd_bridge_alloc (dev,to_of_node (fwnode));if (IS_ERR (alt_port->bridge)) { -fwnode_handle_put (fwnode); -return PTR_ERR (alt_port->bridge); + ret =PTR_ERR (alt_port->bridge); + goto put_fwnode; } alt_port->dp_alt.svid =USB_TYPEC_DP_SID ;
@@ -466,48 +465,42 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, alt_port->typec_mux =fwnode_typec_mux_get (fwnode);if (IS_ERR (alt_port->typec_mux)) { -fwnode_handle_put (fwnode); -return dev_err_probe (dev,PTR_ERR (alt_port->typec_mux), -"failed to acquire mode-switch for port: %d\n" , - port); + ret =dev_err_probe (dev,PTR_ERR (alt_port->typec_mux), +"failed to acquire mode-switch for port: %d\n" , + port); + goto put_fwnode; } ret =devm_add_action_or_reset (dev, pmic_glink_altmode_put_mux, alt_port->typec_mux); -if (ret) { -fwnode_handle_put (fwnode); -return ret; - } +if (ret) + goto put_fwnode; alt_port->typec_retimer =fwnode_typec_retimer_get (fwnode);if (IS_ERR (alt_port->typec_retimer)) { -fwnode_handle_put (fwnode); -return dev_err_probe (dev,PTR_ERR (alt_port->typec_retimer), -"failed to acquire retimer-switch for port: %d\n" , - port); + ret =dev_err_probe (dev,PTR_ERR (alt_port->typec_retimer), +"failed to acquire retimer-switch for port: %d\n" , + port); + goto put_fwnode; } ret =devm_add_action_or_reset (dev, pmic_glink_altmode_put_retimer, alt_port->typec_retimer); -if (ret) { -fwnode_handle_put (fwnode); -return ret; - } +if (ret) + goto put_fwnode; alt_port->typec_switch =fwnode_typec_switch_get (fwnode);if (IS_ERR (alt_port->typec_switch)) { -fwnode_handle_put (fwnode); -return dev_err_probe (dev,PTR_ERR (alt_port->typec_switch), -"failed to acquire orientation-switch for port: %d\n" , - port); + ret =dev_err_probe (dev,PTR_ERR (alt_port->typec_switch), +"failed to acquire orientation-switch for port: %d\n" , + port); + goto put_fwnode; } ret =devm_add_action_or_reset (dev, pmic_glink_altmode_put_switch, alt_port->typec_switch); -if (ret) { -fwnode_handle_put (fwnode); -return ret; - } +if (ret) + goto put_fwnode; }for (port =0 ; port <ARRAY_SIZE (altmode->ports); port++) {
@@ -526,6 +519,10 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, pmic_glink_altmode_pdr_notify, altmode);return PTR_ERR_OR_ZERO (altmode->client); + +put_fwnode: +fwnode_handle_put (fwnode); +return ret; }static const struct auxiliary_device_id pmic_glink_altmode_id_table[] = {
--
2.43.2
Quoted 10 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 28 Feb 2024 18:45:13 +0100Add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.
This issue was transformed by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
(+CC Peter)
Hmm.. this looks very similar to the problem that __free solves with <linux/cleanup.h>..
I know no better, but wouldn't the same mechanism, down to the usage of DEFINE_FREE work fine for _put-like functions?
Konrad
Quoted 14 lines · Konrad Dybcio
Quoted 10 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 28 Feb 2024 18:45:13 +0100Add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.
This issue was transformed by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
Quoted 7 lines
(+CC Peter)
Hmm.. this looks very similar to the problem that
__freesolves with <linux/cleanup.h>..I know no better, but wouldn't the same mechanism, down to the usage of
DEFINE_FREEwork fine for _put-like functions?
Jonathan Cameron has created something like this:
https://lore.kernel.org/all/[email protected]/
It hasn't been merged yet and it would need a bit of adjusting for this use case but it's basically what you want.
regards,
dan carpenter