usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails
Subsystems (2)
PATCH 1/4 usb: typec: tipd: Cleanup resources if devm_tps6598_psy_register fails
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.
--- drivers/usb/typec/tipd/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/tipd/core.c +1 -1
@@ -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)) {
Signature · 1 line
2.25.1
PATCH 2/4 usb: typec: tipd: Fix spurious fwnode_handle_put in error path
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.
--- drivers/usb/typec/tipd/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/tipd/core.c +1 -1
@@ -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 ;
Signature · 1 line
2.25.1
Re: [PATCH 2/4] usb: typec: tipd: Fix spurious fwnode_handle_put in error path
Quoted 7 lines · Sven Peter
The
err_role_puterror path always callsfwnode_handle_putto release the fwnode. This path can be reached after probe itself has already released that fwnode though. Fix that by movingfwnode_handle_putin the happy path to the very end.Fixes 18a6c866bb19 ("usb: typec: tps6598x: Add USB role switching logic")Signed-off-by Sven Peter <[email protected]>
This looks like stable material as well.
Quoted 17 lines
--- drivers/usb/typec/tipd/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/typec/tipd/core.c +0
-1@@ -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);
drivers/usb/typec/tipd/core.c static int tps6598x_probe(struct i2c_client *client) · line 863
Quoted 7 lines
drivers/usb/typec/tipd/core.c +1
-0@@ -858,6 +857,7 @@ static int tps6598x_probe(struct i2c_client *client) }i2c_set_clientdata (client, tps); +fwnode_handle_put (fwnode);return 0 ;
thanks,
Signature · 1 line
heikki
PATCH 3/4 usb: typec: tipd: Fix typec_unregister_port error paths
In reply to Sven Petertypec_unregister_port is only called for some error paths after typec_register_port was successful. Ensure it's called in all cases.
--- drivers/usb/typec/tipd/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/typec/tipd/core.c +4 -3
@@ -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:
Signature · 1 line
2.25.1
Re: [PATCH 3/4] usb: typec: tipd: Fix typec_unregister_port error paths
Quoted 6 lines · Sven Peter
typec_unregister_portis only called for some error paths aftertypec_register_portwas successful. Ensure it's called in all cases.Fixes 92440202a880 ("usb: typec: tipd: Only update power status on IRQ")Signed-off-by Sven Peter <[email protected]>
Also direct stable material.
Quoted 28 lines
--- drivers/usb/typec/tipd/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/usb/typec/tipd/core.c +2
-3@@ -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);
drivers/usb/typec/tipd/core.c static int tps6598x_probe(struct i2c_client *client) · line 867
Quoted 8 lines
drivers/usb/typec/tipd/core.c +2
-0@@ -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,
Signature · 1 line
heikki
PATCH 4/4 usb: typec: tipd: Move tps6598x_disconnect error path to its own label
In reply to Sven PeterWhile 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.
--- drivers/usb/typec/tipd/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/typec/tipd/core.c +4 -4
@@ -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:
Signature · 1 line
2.25.1
Re: [PATCH 4/4] usb: typec: tipd: Move tps6598x_disconnect error path to its own label
Quoted 5 lines · Sven Peter
While the code currently correctly calls
tps6598x_disconnectbefore 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 <[email protected]>
Quoted 19 lines
--- drivers/usb/typec/tipd/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/usb/typec/tipd/core.c +2
-4@@ -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;
drivers/usb/typec/tipd/core.c static int tps6598x_probe(struct i2c_client *client) · line 865
Quoted 10 lines
drivers/usb/typec/tipd/core.c +2
-0i2c_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,
Signature · 1 line
heikki
Quoted 5 lines · Sven Peter
We can't just return if
devm_tps6598_psy_registerfails 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 <[email protected]>
I think this should also automatically go to the stable tree.
Quoted 9 lines
--- drivers/usb/typec/tipd/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/typec/tipd/core.c +0
-0
drivers/usb/typec/tipd/core.c static int tps6598x_probe(struct i2c_client *client) · line 833
Quoted 8 lines
drivers/usb/typec/tipd/core.c +1
-1@@ -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,
Signature · 1 line
heikki