usb: typec: ucsi: glink: use device_for_each_child_node_scoped()
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Wed, 25 Sep 2024 15:49:46 +0000 (17:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 13:11:59 +0000 (15:11 +0200)
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.

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20240925-ucsi_glink-scoped-v2-1-a661585fff35@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/ucsi/ucsi_glink.c

index 03c0fa8edc8db5061ba718d77cba2fc7605a6b49..3e4d88ab338e50d4265df15fc960907c36675282 100644 (file)
@@ -322,7 +322,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);
@@ -354,14 +353,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;
                }
 
@@ -376,11 +374,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;
        }