dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc: qcom: pmic_glink_altmode: Use common error handling code in pmic_glink_altmode_probe()
@ 2024-02-28 18:05 Markus Elfring
  2024-02-28 23:26 ` Konrad Dybcio
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2024-02-28 18:05 UTC (permalink / raw)
  To: linux-arm-msm, kernel-janitors, Bjorn Andersson,
	Dmitry Baryshkov, Johan Hovold, Konrad Dybcio
  Cc: LKML, freedreno, dri-devel, linux-phy, Abhinav Kumar,
	Andrzej Hajda, Daniel Vetter, David Airlie, Jernej Skrabec,
	Jonas Karlman, Kishon Vijay Abraham I, Kuogee Hsieh,
	Laurent Pinchart, Maarten Lankhorst, Maxime Ripard,
	Neil Armstrong, Rob Clark, Robert Foss, Thomas Zimmermann

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/soc/qcom/pmic_glink_altmode.c | 57 +++++++++++++--------------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/drivers/soc/qcom/pmic_glink_altmode.c b/drivers/soc/qcom/pmic_glink_altmode.c
index b3808fc24c69..c987a45e1703 100644
--- a/drivers/soc/qcom/pmic_glink_altmode.c
+++ b/drivers/soc/qcom/pmic_glink_altmode.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] soc: qcom: pmic_glink_altmode: Use common error handling code in pmic_glink_altmode_probe()
  2024-02-28 18:05 [PATCH] soc: qcom: pmic_glink_altmode: Use common error handling code in pmic_glink_altmode_probe() Markus Elfring
@ 2024-02-28 23:26 ` Konrad Dybcio
  2024-02-29  7:31   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Konrad Dybcio @ 2024-02-28 23:26 UTC (permalink / raw)
  To: Markus Elfring, linux-arm-msm, kernel-janitors, Bjorn Andersson,
	Dmitry Baryshkov, Johan Hovold
  Cc: LKML, freedreno, dri-devel, linux-phy, Abhinav Kumar,
	Andrzej Hajda, Daniel Vetter, David Airlie, Jernej Skrabec,
	Jonas Karlman, Kishon Vijay Abraham I, Kuogee Hsieh,
	Laurent Pinchart, Maarten Lankhorst, Maxime Ripard,
	Neil Armstrong, Rob Clark, Robert Foss, Thomas Zimmermann,
	Peter Zijlstra



On 2/28/24 19:05, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---

(+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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] soc: qcom: pmic_glink_altmode: Use common error handling code in pmic_glink_altmode_probe()
  2024-02-28 23:26 ` Konrad Dybcio
@ 2024-02-29  7:31   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-02-29  7:31 UTC (permalink / raw)
  To: Konrad Dybcio, Jonathan Cameron
  Cc: Markus Elfring, linux-arm-msm, kernel-janitors, Bjorn Andersson,
	Dmitry Baryshkov, Johan Hovold, LKML, freedreno, dri-devel,
	linux-phy, Abhinav Kumar, Andrzej Hajda, Daniel Vetter,
	David Airlie, Jernej Skrabec, Jonas Karlman,
	Kishon Vijay Abraham I, Kuogee Hsieh, Laurent Pinchart,
	Maarten Lankhorst, Maxime Ripard, Neil Armstrong, Rob Clark,
	Robert Foss, Thomas Zimmermann, Peter Zijlstra

On Thu, Feb 29, 2024 at 12:26:49AM +0100, Konrad Dybcio wrote:
> 
> 
> On 2/28/24 19:05, Markus Elfring wrote:
> > From: Markus Elfring <elfring@users.sourceforge.net>
> > 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.
> > 
> > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> > ---
> 
> (+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?

Jonathan Cameron has created something like this:
https://lore.kernel.org/all/20240225142714.286440-1-jic23@kernel.org/

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-29  7:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28 18:05 [PATCH] soc: qcom: pmic_glink_altmode: Use common error handling code in pmic_glink_altmode_probe() Markus Elfring
2024-02-28 23:26 ` Konrad Dybcio
2024-02-29  7:31   ` Dan Carpenter

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).