public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: typec: nb7vpq904m: Add an error handling path in nb7vpq904m_probe()
@ 2023-07-18 21:40 Christophe JAILLET
  2023-07-31  8:38 ` Neil Armstrong
  2023-07-31 13:16 ` Heikki Krogerus
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2023-07-18 21:40 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Dmitry Baryshkov,
	Neil Armstrong
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-usb

In case of error in the nb7vpq904m_probe() probe function, some resources
need to be freed, as already done in the remove function.

Add the missing error handling path and adjust code accordingly.

Fixes: 88d8f3ac9c67 ("usb: typec: add support for the nb7vpq904m Type-C Linear Redriver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This changes the order with some devm_ allocated resources. I hope this is
fine. At least it is consistent with the remove function.
---
 drivers/usb/typec/mux/nb7vpq904m.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/typec/mux/nb7vpq904m.c b/drivers/usb/typec/mux/nb7vpq904m.c
index 80e580d50129..4d1122d95013 100644
--- a/drivers/usb/typec/mux/nb7vpq904m.c
+++ b/drivers/usb/typec/mux/nb7vpq904m.c
@@ -463,16 +463,18 @@ static int nb7vpq904m_probe(struct i2c_client *client)
 
 	ret = nb7vpq904m_register_bridge(nb7);
 	if (ret)
-		return ret;
+		goto err_disable_gpio;
 
 	sw_desc.drvdata = nb7;
 	sw_desc.fwnode = dev->fwnode;
 	sw_desc.set = nb7vpq904m_sw_set;
 
 	nb7->sw = typec_switch_register(dev, &sw_desc);
-	if (IS_ERR(nb7->sw))
-		return dev_err_probe(dev, PTR_ERR(nb7->sw),
-				     "Error registering typec switch\n");
+	if (IS_ERR(nb7->sw)) {
+		ret = dev_err_probe(dev, PTR_ERR(nb7->sw),
+				    "Error registering typec switch\n");
+		goto err_disable_gpio;
+	}
 
 	retimer_desc.drvdata = nb7;
 	retimer_desc.fwnode = dev->fwnode;
@@ -480,12 +482,21 @@ static int nb7vpq904m_probe(struct i2c_client *client)
 
 	nb7->retimer = typec_retimer_register(dev, &retimer_desc);
 	if (IS_ERR(nb7->retimer)) {
-		typec_switch_unregister(nb7->sw);
-		return dev_err_probe(dev, PTR_ERR(nb7->retimer),
-				     "Error registering typec retimer\n");
+		ret = dev_err_probe(dev, PTR_ERR(nb7->retimer),
+				    "Error registering typec retimer\n");
+		goto err_switch_unregister;
 	}
 
 	return 0;
+
+err_switch_unregister:
+	typec_switch_unregister(nb7->sw);
+
+err_disable_gpio:
+	gpiod_set_value(nb7->enable_gpio, 0);
+	regulator_disable(nb7->vcc_supply);
+
+	return ret;
 }
 
 static void nb7vpq904m_remove(struct i2c_client *client)
-- 
2.34.1


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

* Re: [PATCH] usb: typec: nb7vpq904m: Add an error handling path in nb7vpq904m_probe()
  2023-07-18 21:40 [PATCH] usb: typec: nb7vpq904m: Add an error handling path in nb7vpq904m_probe() Christophe JAILLET
@ 2023-07-31  8:38 ` Neil Armstrong
  2023-07-31 13:16 ` Heikki Krogerus
  1 sibling, 0 replies; 3+ messages in thread
From: Neil Armstrong @ 2023-07-31  8:38 UTC (permalink / raw)
  To: Christophe JAILLET, Heikki Krogerus, Greg Kroah-Hartman,
	Dmitry Baryshkov
  Cc: linux-kernel, kernel-janitors, linux-usb

On 18/07/2023 23:40, Christophe JAILLET wrote:
> In case of error in the nb7vpq904m_probe() probe function, some resources
> need to be freed, as already done in the remove function.
> 
> Add the missing error handling path and adjust code accordingly.
> 
> Fixes: 88d8f3ac9c67 ("usb: typec: add support for the nb7vpq904m Type-C Linear Redriver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This changes the order with some devm_ allocated resources. I hope this is
> fine. At least it is consistent with the remove function.
> ---
>   drivers/usb/typec/mux/nb7vpq904m.c | 25 ++++++++++++++++++-------
>   1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux/nb7vpq904m.c b/drivers/usb/typec/mux/nb7vpq904m.c
> index 80e580d50129..4d1122d95013 100644
> --- a/drivers/usb/typec/mux/nb7vpq904m.c
> +++ b/drivers/usb/typec/mux/nb7vpq904m.c
> @@ -463,16 +463,18 @@ static int nb7vpq904m_probe(struct i2c_client *client)
>   
>   	ret = nb7vpq904m_register_bridge(nb7);
>   	if (ret)
> -		return ret;
> +		goto err_disable_gpio;
>   
>   	sw_desc.drvdata = nb7;
>   	sw_desc.fwnode = dev->fwnode;
>   	sw_desc.set = nb7vpq904m_sw_set;
>   
>   	nb7->sw = typec_switch_register(dev, &sw_desc);
> -	if (IS_ERR(nb7->sw))
> -		return dev_err_probe(dev, PTR_ERR(nb7->sw),
> -				     "Error registering typec switch\n");
> +	if (IS_ERR(nb7->sw)) {
> +		ret = dev_err_probe(dev, PTR_ERR(nb7->sw),
> +				    "Error registering typec switch\n");
> +		goto err_disable_gpio;
> +	}
>   
>   	retimer_desc.drvdata = nb7;
>   	retimer_desc.fwnode = dev->fwnode;
> @@ -480,12 +482,21 @@ static int nb7vpq904m_probe(struct i2c_client *client)
>   
>   	nb7->retimer = typec_retimer_register(dev, &retimer_desc);
>   	if (IS_ERR(nb7->retimer)) {
> -		typec_switch_unregister(nb7->sw);
> -		return dev_err_probe(dev, PTR_ERR(nb7->retimer),
> -				     "Error registering typec retimer\n");
> +		ret = dev_err_probe(dev, PTR_ERR(nb7->retimer),
> +				    "Error registering typec retimer\n");
> +		goto err_switch_unregister;
>   	}
>   
>   	return 0;
> +
> +err_switch_unregister:
> +	typec_switch_unregister(nb7->sw);
> +
> +err_disable_gpio:
> +	gpiod_set_value(nb7->enable_gpio, 0);
> +	regulator_disable(nb7->vcc_supply);
> +
> +	return ret;
>   }
>   
>   static void nb7vpq904m_remove(struct i2c_client *client)


Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>

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

* Re: [PATCH] usb: typec: nb7vpq904m: Add an error handling path in nb7vpq904m_probe()
  2023-07-18 21:40 [PATCH] usb: typec: nb7vpq904m: Add an error handling path in nb7vpq904m_probe() Christophe JAILLET
  2023-07-31  8:38 ` Neil Armstrong
@ 2023-07-31 13:16 ` Heikki Krogerus
  1 sibling, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2023-07-31 13:16 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Greg Kroah-Hartman, Dmitry Baryshkov, Neil Armstrong,
	linux-kernel, kernel-janitors, linux-usb

On Tue, Jul 18, 2023 at 11:40:05PM +0200, Christophe JAILLET wrote:
> In case of error in the nb7vpq904m_probe() probe function, some resources
> need to be freed, as already done in the remove function.
> 
> Add the missing error handling path and adjust code accordingly.
> 
> Fixes: 88d8f3ac9c67 ("usb: typec: add support for the nb7vpq904m Type-C Linear Redriver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> This changes the order with some devm_ allocated resources. I hope this is
> fine. At least it is consistent with the remove function.
> ---
>  drivers/usb/typec/mux/nb7vpq904m.c | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux/nb7vpq904m.c b/drivers/usb/typec/mux/nb7vpq904m.c
> index 80e580d50129..4d1122d95013 100644
> --- a/drivers/usb/typec/mux/nb7vpq904m.c
> +++ b/drivers/usb/typec/mux/nb7vpq904m.c
> @@ -463,16 +463,18 @@ static int nb7vpq904m_probe(struct i2c_client *client)
>  
>  	ret = nb7vpq904m_register_bridge(nb7);
>  	if (ret)
> -		return ret;
> +		goto err_disable_gpio;
>  
>  	sw_desc.drvdata = nb7;
>  	sw_desc.fwnode = dev->fwnode;
>  	sw_desc.set = nb7vpq904m_sw_set;
>  
>  	nb7->sw = typec_switch_register(dev, &sw_desc);
> -	if (IS_ERR(nb7->sw))
> -		return dev_err_probe(dev, PTR_ERR(nb7->sw),
> -				     "Error registering typec switch\n");
> +	if (IS_ERR(nb7->sw)) {
> +		ret = dev_err_probe(dev, PTR_ERR(nb7->sw),
> +				    "Error registering typec switch\n");
> +		goto err_disable_gpio;
> +	}
>  
>  	retimer_desc.drvdata = nb7;
>  	retimer_desc.fwnode = dev->fwnode;
> @@ -480,12 +482,21 @@ static int nb7vpq904m_probe(struct i2c_client *client)
>  
>  	nb7->retimer = typec_retimer_register(dev, &retimer_desc);
>  	if (IS_ERR(nb7->retimer)) {
> -		typec_switch_unregister(nb7->sw);
> -		return dev_err_probe(dev, PTR_ERR(nb7->retimer),
> -				     "Error registering typec retimer\n");
> +		ret = dev_err_probe(dev, PTR_ERR(nb7->retimer),
> +				    "Error registering typec retimer\n");
> +		goto err_switch_unregister;
>  	}
>  
>  	return 0;
> +
> +err_switch_unregister:
> +	typec_switch_unregister(nb7->sw);
> +
> +err_disable_gpio:
> +	gpiod_set_value(nb7->enable_gpio, 0);
> +	regulator_disable(nb7->vcc_supply);
> +
> +	return ret;
>  }
>  
>  static void nb7vpq904m_remove(struct i2c_client *client)
> -- 
> 2.34.1

-- 
heikki

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

end of thread, other threads:[~2023-07-31 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-18 21:40 [PATCH] usb: typec: nb7vpq904m: Add an error handling path in nb7vpq904m_probe() Christophe JAILLET
2023-07-31  8:38 ` Neil Armstrong
2023-07-31 13:16 ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox