linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails
@ 2022-11-14 17:44 Sven Peter
  2022-11-14 17:44 ` [PATCH 2/4] usb: typec: tipd: Fix spurious fwnode_handle_put in error path Sven Peter
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Sven Peter @ 2022-11-14 17:44 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman; +Cc: Sven Peter, linux-usb, linux-kernel

We can't just return if devm_tps6598_psy_register fails since previous
resources are not devres managed and have yet to be cleaned up.

Fixes: 10eb0b6ac63a ("usb: typec: tps6598x: Export some power supply properties")
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
 drivers/usb/typec/tipd/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 748ff4f6b5f6..ebc786d728e2 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -827,7 +827,7 @@ static int tps6598x_probe(struct i2c_client *client)
 
 	ret = devm_tps6598_psy_register(tps);
 	if (ret)
-		return ret;
+		goto err_role_put;
 
 	tps->port = typec_register_port(&client->dev, &typec_cap);
 	if (IS_ERR(tps->port)) {
-- 
2.25.1


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

* [PATCH 2/4] usb: typec: tipd: Fix spurious fwnode_handle_put in error path
  2022-11-14 17:44 [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails Sven Peter
@ 2022-11-14 17:44 ` Sven Peter
  2022-11-16 12:16   ` Heikki Krogerus
  2022-11-14 17:44 ` [PATCH 3/4] usb: typec: tipd: Fix typec_unregister_port error paths Sven Peter
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Sven Peter @ 2022-11-14 17:44 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman; +Cc: Sven Peter, linux-usb, linux-kernel

The err_role_put error path always calls fwnode_handle_put to release
the fwnode. This path can be reached after probe itself has already
released that fwnode though. Fix that by moving fwnode_handle_put in the
happy path to the very end.

Fixes: 18a6c866bb19 ("usb: typec: tps6598x: Add USB role switching logic")
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
 drivers/usb/typec/tipd/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index ebc786d728e2..824e573af570 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -834,7 +834,6 @@ static int tps6598x_probe(struct i2c_client *client)
 		ret = PTR_ERR(tps->port);
 		goto err_role_put;
 	}
-	fwnode_handle_put(fwnode);
 
 	if (tps->status & TPS_STATUS_PLUG_PRESENT) {
 		ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
@@ -858,6 +857,7 @@ static int tps6598x_probe(struct i2c_client *client)
 	}
 
 	i2c_set_clientdata(client, tps);
+	fwnode_handle_put(fwnode);
 
 	return 0;
 
-- 
2.25.1


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

* [PATCH 3/4] usb: typec: tipd: Fix typec_unregister_port error paths
  2022-11-14 17:44 [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails Sven Peter
  2022-11-14 17:44 ` [PATCH 2/4] usb: typec: tipd: Fix spurious fwnode_handle_put in error path Sven Peter
@ 2022-11-14 17:44 ` Sven Peter
  2022-11-16 12:20   ` Heikki Krogerus
  2022-11-14 17:44 ` [PATCH 4/4] usb: typec: tipd: Move tps6598x_disconnect error path to its own label Sven Peter
  2022-11-16 12:13 ` [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails Heikki Krogerus
  3 siblings, 1 reply; 8+ messages in thread
From: Sven Peter @ 2022-11-14 17:44 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman; +Cc: Sven Peter, linux-usb, linux-kernel

typec_unregister_port is only called for some error paths after
typec_register_port was successful. Ensure it's called in all
cases.

Fixes: 92440202a880 ("usb: typec: tipd: Only update power status on IRQ")
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
 drivers/usb/typec/tipd/core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 824e573af570..c35501a92b4d 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -839,7 +839,7 @@ static int tps6598x_probe(struct i2c_client *client)
 		ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
 		if (ret < 0) {
 			dev_err(tps->dev, "failed to read power status: %d\n", ret);
-			goto err_role_put;
+			goto err_unregister_port;
 		}
 		ret = tps6598x_connect(tps);
 		if (ret)
@@ -852,8 +852,7 @@ static int tps6598x_probe(struct i2c_client *client)
 					dev_name(&client->dev), tps);
 	if (ret) {
 		tps6598x_disconnect(tps, 0);
-		typec_unregister_port(tps->port);
-		goto err_role_put;
+		goto err_unregister_port;
 	}
 
 	i2c_set_clientdata(client, tps);
@@ -861,6 +860,8 @@ static int tps6598x_probe(struct i2c_client *client)
 
 	return 0;
 
+err_unregister_port:
+	typec_unregister_port(tps->port);
 err_role_put:
 	usb_role_switch_put(tps->role_sw);
 err_fwnode_put:
-- 
2.25.1


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

* [PATCH 4/4] usb: typec: tipd: Move tps6598x_disconnect error path to its own label
  2022-11-14 17:44 [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails Sven Peter
  2022-11-14 17:44 ` [PATCH 2/4] usb: typec: tipd: Fix spurious fwnode_handle_put in error path Sven Peter
  2022-11-14 17:44 ` [PATCH 3/4] usb: typec: tipd: Fix typec_unregister_port error paths Sven Peter
@ 2022-11-14 17:44 ` Sven Peter
  2022-11-16 12:30   ` Heikki Krogerus
  2022-11-16 12:13 ` [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails Heikki Krogerus
  3 siblings, 1 reply; 8+ messages in thread
From: Sven Peter @ 2022-11-14 17:44 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman; +Cc: Sven Peter, linux-usb, linux-kernel

While the code currently correctly calls tps6598x_disconnect before jumping
to the error cleanup label it's inconsistent compared to all the other cleanup
actions and prone to introduce bugs if any more resources are added.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
 drivers/usb/typec/tipd/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index c35501a92b4d..22ff212e05e6 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -850,16 +850,16 @@ static int tps6598x_probe(struct i2c_client *client)
 					irq_handler,
 					IRQF_SHARED | IRQF_ONESHOT,
 					dev_name(&client->dev), tps);
-	if (ret) {
-		tps6598x_disconnect(tps, 0);
-		goto err_unregister_port;
-	}
+	if (ret)
+		goto err_disconnect;
 
 	i2c_set_clientdata(client, tps);
 	fwnode_handle_put(fwnode);
 
 	return 0;
 
+err_disconnect:
+	tps6598x_disconnect(tps, 0);
 err_unregister_port:
 	typec_unregister_port(tps->port);
 err_role_put:
-- 
2.25.1


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

* Re: [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails
  2022-11-14 17:44 [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails Sven Peter
                   ` (2 preceding siblings ...)
  2022-11-14 17:44 ` [PATCH 4/4] usb: typec: tipd: Move tps6598x_disconnect error path to its own label Sven Peter
@ 2022-11-16 12:13 ` Heikki Krogerus
  3 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2022-11-16 12:13 UTC (permalink / raw)
  To: Sven Peter; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Nov 14, 2022 at 06:44:46PM +0100, Sven Peter wrote:
> We can't just return if devm_tps6598_psy_register fails since previous
> resources are not devres managed and have yet to be cleaned up.
> 
> Fixes: 10eb0b6ac63a ("usb: typec: tps6598x: Export some power supply properties")
> Signed-off-by: Sven Peter <sven@svenpeter.dev>

I think this should also automatically go to the stable tree.

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

> ---
>  drivers/usb/typec/tipd/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 748ff4f6b5f6..ebc786d728e2 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -827,7 +827,7 @@ static int tps6598x_probe(struct i2c_client *client)
>  
>  	ret = devm_tps6598_psy_register(tps);
>  	if (ret)
> -		return ret;
> +		goto err_role_put;
>  
>  	tps->port = typec_register_port(&client->dev, &typec_cap);
>  	if (IS_ERR(tps->port)) {

thanks,

-- 
heikki

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

* Re: [PATCH 2/4] usb: typec: tipd: Fix spurious fwnode_handle_put in error path
  2022-11-14 17:44 ` [PATCH 2/4] usb: typec: tipd: Fix spurious fwnode_handle_put in error path Sven Peter
@ 2022-11-16 12:16   ` Heikki Krogerus
  0 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2022-11-16 12:16 UTC (permalink / raw)
  To: Sven Peter; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Nov 14, 2022 at 06:44:47PM +0100, Sven Peter wrote:
> The err_role_put error path always calls fwnode_handle_put to release
> the fwnode. This path can be reached after probe itself has already
> released that fwnode though. Fix that by moving fwnode_handle_put in the
> happy path to the very end.
> 
> Fixes: 18a6c866bb19 ("usb: typec: tps6598x: Add USB role switching logic")
> Signed-off-by: Sven Peter <sven@svenpeter.dev>

This looks like stable material as well.

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

> ---
>  drivers/usb/typec/tipd/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index ebc786d728e2..824e573af570 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -834,7 +834,6 @@ static int tps6598x_probe(struct i2c_client *client)
>  		ret = PTR_ERR(tps->port);
>  		goto err_role_put;
>  	}
> -	fwnode_handle_put(fwnode);
>  
>  	if (tps->status & TPS_STATUS_PLUG_PRESENT) {
>  		ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
> @@ -858,6 +857,7 @@ static int tps6598x_probe(struct i2c_client *client)
>  	}
>  
>  	i2c_set_clientdata(client, tps);
> +	fwnode_handle_put(fwnode);
>  
>  	return 0;
>  

thanks,

-- 
heikki

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

* Re: [PATCH 3/4] usb: typec: tipd: Fix typec_unregister_port error paths
  2022-11-14 17:44 ` [PATCH 3/4] usb: typec: tipd: Fix typec_unregister_port error paths Sven Peter
@ 2022-11-16 12:20   ` Heikki Krogerus
  0 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2022-11-16 12:20 UTC (permalink / raw)
  To: Sven Peter; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Nov 14, 2022 at 06:44:48PM +0100, Sven Peter wrote:
> typec_unregister_port is only called for some error paths after
> typec_register_port was successful. Ensure it's called in all
> cases.
> 
> Fixes: 92440202a880 ("usb: typec: tipd: Only update power status on IRQ")
> Signed-off-by: Sven Peter <sven@svenpeter.dev>

Also direct stable material.

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

> ---
>  drivers/usb/typec/tipd/core.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 824e573af570..c35501a92b4d 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -839,7 +839,7 @@ static int tps6598x_probe(struct i2c_client *client)
>  		ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
>  		if (ret < 0) {
>  			dev_err(tps->dev, "failed to read power status: %d\n", ret);
> -			goto err_role_put;
> +			goto err_unregister_port;
>  		}
>  		ret = tps6598x_connect(tps);
>  		if (ret)
> @@ -852,8 +852,7 @@ static int tps6598x_probe(struct i2c_client *client)
>  					dev_name(&client->dev), tps);
>  	if (ret) {
>  		tps6598x_disconnect(tps, 0);
> -		typec_unregister_port(tps->port);
> -		goto err_role_put;
> +		goto err_unregister_port;
>  	}
>  
>  	i2c_set_clientdata(client, tps);
> @@ -861,6 +860,8 @@ static int tps6598x_probe(struct i2c_client *client)
>  
>  	return 0;
>  
> +err_unregister_port:
> +	typec_unregister_port(tps->port);
>  err_role_put:
>  	usb_role_switch_put(tps->role_sw);
>  err_fwnode_put:

thanks,

-- 
heikki

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

* Re: [PATCH 4/4] usb: typec: tipd: Move tps6598x_disconnect error path to its own label
  2022-11-14 17:44 ` [PATCH 4/4] usb: typec: tipd: Move tps6598x_disconnect error path to its own label Sven Peter
@ 2022-11-16 12:30   ` Heikki Krogerus
  0 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2022-11-16 12:30 UTC (permalink / raw)
  To: Sven Peter; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Mon, Nov 14, 2022 at 06:44:49PM +0100, Sven Peter wrote:
> While the code currently correctly calls tps6598x_disconnect before jumping
> to the error cleanup label it's inconsistent compared to all the other cleanup
> actions and prone to introduce bugs if any more resources are added.
> 
> Signed-off-by: Sven Peter <sven@svenpeter.dev>

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

> ---
>  drivers/usb/typec/tipd/core.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index c35501a92b4d..22ff212e05e6 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -850,16 +850,16 @@ static int tps6598x_probe(struct i2c_client *client)
>  					irq_handler,
>  					IRQF_SHARED | IRQF_ONESHOT,
>  					dev_name(&client->dev), tps);
> -	if (ret) {
> -		tps6598x_disconnect(tps, 0);
> -		goto err_unregister_port;
> -	}
> +	if (ret)
> +		goto err_disconnect;
>  
>  	i2c_set_clientdata(client, tps);
>  	fwnode_handle_put(fwnode);
>  
>  	return 0;
>  
> +err_disconnect:
> +	tps6598x_disconnect(tps, 0);
>  err_unregister_port:
>  	typec_unregister_port(tps->port);
>  err_role_put:

thanks,

-- 
heikki

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

end of thread, other threads:[~2022-11-16 12:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-14 17:44 [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails Sven Peter
2022-11-14 17:44 ` [PATCH 2/4] usb: typec: tipd: Fix spurious fwnode_handle_put in error path Sven Peter
2022-11-16 12:16   ` Heikki Krogerus
2022-11-14 17:44 ` [PATCH 3/4] usb: typec: tipd: Fix typec_unregister_port error paths Sven Peter
2022-11-16 12:20   ` Heikki Krogerus
2022-11-14 17:44 ` [PATCH 4/4] usb: typec: tipd: Move tps6598x_disconnect error path to its own label Sven Peter
2022-11-16 12:30   ` Heikki Krogerus
2022-11-16 12:13 ` [PATCH 1/4] usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails Heikki Krogerus

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