Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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>

authored by

Javier Carrasco and committed by
Greg Kroah-Hartman
4904f9aa 5014f10c

+3 -6
+3 -6
drivers/usb/typec/ucsi/ucsi_glink.c
··· 322 322 struct pmic_glink_ucsi *ucsi; 323 323 struct device *dev = &adev->dev; 324 324 const struct of_device_id *match; 325 - struct fwnode_handle *fwnode; 326 325 int ret; 327 326 328 327 ucsi = devm_kzalloc(dev, sizeof(*ucsi), GFP_KERNEL); ··· 353 354 354 355 ucsi_set_drvdata(ucsi->ucsi, ucsi); 355 356 356 - device_for_each_child_node(dev, fwnode) { 357 + device_for_each_child_node_scoped(dev, fwnode) { 357 358 struct gpio_desc *desc; 358 359 u32 port; 359 360 360 361 ret = fwnode_property_read_u32(fwnode, "reg", &port); 361 362 if (ret < 0) { 362 363 dev_err(dev, "missing reg property of %pOFn\n", fwnode); 363 - fwnode_handle_put(fwnode); 364 364 return ret; 365 365 } 366 366 ··· 374 376 if (!desc) 375 377 continue; 376 378 377 - if (IS_ERR(desc)) { 378 - fwnode_handle_put(fwnode); 379 + if (IS_ERR(desc)) 379 380 return dev_err_probe(dev, PTR_ERR(desc), 380 381 "unable to acquire orientation gpio\n"); 381 - } 382 + 382 383 ucsi->port_orientation[port] = desc; 383 384 } 384 385