diff mbox series

usb: typec: ucsi: glink: use device_for_each_child_node_scoped()

Message ID 20240623-ucsi_glink-scoped-v1-1-f0fdcfec69bb@gmail.com (mailing list archive)
State Accepted
Commit 4904f9aa35b1b5f94cc388320f6835bc73f2ab87
Headers show
Series usb: typec: ucsi: glink: use device_for_each_child_node_scoped() | expand

Commit Message

Javier Carrasco June 23, 2024, 10:35 a.m. UTC
Use the scoped variant of `device_for_each_child_node()` to
automatically handle early exits.

This prevents memory leaks if new error paths are introduced,
as no explicit refcount decrement via `fwnode_handle_put()` is needed.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
This patch is a follow-up to the recently introduced commit c68942624e25
("usb: typec: ucsi: glink: fix child node release in probe function")
to account for a safer approach to iterating over child nodes.
---
 drivers/usb/typec/ucsi/ucsi_glink.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)


---
base-commit: f76698bd9a8ca01d3581236082d786e9a6b72bb7
change-id: 20240623-ucsi_glink-scoped-2d417fc9afd3

Best regards,

Comments

Heikki Krogerus June 25, 2024, 2:30 p.m. UTC | #1
On Sun, Jun 23, 2024 at 12:35:11PM +0200, Javier Carrasco wrote:
> Use the scoped variant of `device_for_each_child_node()` to
> automatically handle early exits.
> 
> This prevents memory leaks if new error paths are introduced,
> as no explicit refcount decrement via `fwnode_handle_put()` is needed.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

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

> ---
> This patch is a follow-up to the recently introduced commit c68942624e25
> ("usb: typec: ucsi: glink: fix child node release in probe function")
> to account for a safer approach to iterating over child nodes.
> ---
>  drivers/usb/typec/ucsi/ucsi_glink.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
> index 2fa973afe4e6..d41c9caa84e0 100644
> --- a/drivers/usb/typec/ucsi/ucsi_glink.c
> +++ b/drivers/usb/typec/ucsi/ucsi_glink.c
> @@ -333,7 +333,6 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
>  	struct pmic_glink_ucsi *ucsi;
>  	struct device *dev = &adev->dev;
>  	const struct of_device_id *match;
> -	struct fwnode_handle *fwnode;
>  	int ret;
>  
>  	ucsi = devm_kzalloc(dev, sizeof(*ucsi), GFP_KERNEL);
> @@ -365,14 +364,13 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
>  
>  	ucsi_set_drvdata(ucsi->ucsi, ucsi);
>  
> -	device_for_each_child_node(dev, fwnode) {
> +	device_for_each_child_node_scoped(dev, fwnode) {
>  		struct gpio_desc *desc;
>  		u32 port;
>  
>  		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;
>  		}
>  
> @@ -387,11 +385,10 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
>  		if (!desc)
>  			continue;
>  
> -		if (IS_ERR(desc)) {
> -			fwnode_handle_put(fwnode);
> +		if (IS_ERR(desc))
>  			return dev_err_probe(dev, PTR_ERR(desc),
>  					     "unable to acquire orientation gpio\n");
> -		}
> +
>  		ucsi->port_orientation[port] = desc;
>  	}
>  
> 
> ---
> base-commit: f76698bd9a8ca01d3581236082d786e9a6b72bb7
> change-id: 20240623-ucsi_glink-scoped-2d417fc9afd3
> 
> Best regards,
> -- 
> Javier Carrasco <javier.carrasco.cruz@gmail.com>
Greg KH June 27, 2024, 2:11 p.m. UTC | #2
On Sun, Jun 23, 2024 at 12:35:11PM +0200, Javier Carrasco wrote:
> Use the scoped variant of `device_for_each_child_node()` to
> automatically handle early exits.
> 
> This prevents memory leaks if new error paths are introduced,
> as no explicit refcount decrement via `fwnode_handle_put()` is needed.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
> This patch is a follow-up to the recently introduced commit c68942624e25
> ("usb: typec: ucsi: glink: fix child node release in probe function")
> to account for a safer approach to iterating over child nodes.

What branch/tree is this against?  It fails to apply to my usb-testing
branch at all :(

Can you rebase and resubmit?

thanks,

greg k-h
Javier Carrasco June 27, 2024, 2:43 p.m. UTC | #3
On 27/06/2024 16:11, Greg Kroah-Hartman wrote:
> On Sun, Jun 23, 2024 at 12:35:11PM +0200, Javier Carrasco wrote:
>> Use the scoped variant of `device_for_each_child_node()` to
>> automatically handle early exits.
>>
>> This prevents memory leaks if new error paths are introduced,
>> as no explicit refcount decrement via `fwnode_handle_put()` is needed.
>>
>> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
>> ---
>> This patch is a follow-up to the recently introduced commit c68942624e25
>> ("usb: typec: ucsi: glink: fix child node release in probe function")
>> to account for a safer approach to iterating over child nodes.
> 
> What branch/tree is this against?  It fails to apply to my usb-testing
> branch at all :(
> 
> Can you rebase and resubmit?
> 
> thanks,
> 
> greg k-h


Hi, for this to apply you need the commit c68942624e25 ("usb: typec:
ucsi: glink: fix child node release in probe function"), which still
uses a non-scoped macro to account for stable kernels. I mentioned it
under the --- separator, but maybe that is not the way to go.

This patch is a follow-up to use the scoped variant and avoid more bugs
when new early exits are added.

I thought the other patch had already been applied, but apparently not
to usb-testing (I used linux-next as basis, the base-commit can be found
below the patch).

Could you please apply the other patch first? If for whatever reason
that is not desired, I could resend both patches as a series to avoid
that one goes unnoticed, but as I said, the first one is already in
linux-next.

Best regards,
Javier Carrasco
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
index 2fa973afe4e6..d41c9caa84e0 100644
--- a/drivers/usb/typec/ucsi/ucsi_glink.c
+++ b/drivers/usb/typec/ucsi/ucsi_glink.c
@@ -333,7 +333,6 @@  static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
 	struct pmic_glink_ucsi *ucsi;
 	struct device *dev = &adev->dev;
 	const struct of_device_id *match;
-	struct fwnode_handle *fwnode;
 	int ret;
 
 	ucsi = devm_kzalloc(dev, sizeof(*ucsi), GFP_KERNEL);
@@ -365,14 +364,13 @@  static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
 
 	ucsi_set_drvdata(ucsi->ucsi, ucsi);
 
-	device_for_each_child_node(dev, fwnode) {
+	device_for_each_child_node_scoped(dev, fwnode) {
 		struct gpio_desc *desc;
 		u32 port;
 
 		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;
 		}
 
@@ -387,11 +385,10 @@  static int pmic_glink_ucsi_probe(struct auxiliary_device *adev,
 		if (!desc)
 			continue;
 
-		if (IS_ERR(desc)) {
-			fwnode_handle_put(fwnode);
+		if (IS_ERR(desc))
 			return dev_err_probe(dev, PTR_ERR(desc),
 					     "unable to acquire orientation gpio\n");
-		}
+
 		ucsi->port_orientation[port] = desc;
 	}