Commit 78184f6e authored by Jinjie Ruan's avatar Jinjie Ruan Committed by Thierry Reding
Browse files

gpu: host1x: Use for_each_available_child_of_node_scoped()



Avoids the need for manual cleanup of_node_put() in early exits
from the loop.

Signed-off-by: default avatarJinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
Link: https://lore.kernel.org/r/20240830073824.3539690-1-ruanjinjie@huawei.com
parent 780351a5
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ static int host1x_subdev_add(struct host1x_device *device,
			     struct device_node *np)
{
	struct host1x_subdev *subdev;
	struct device_node *child;
	int err;

	subdev = kzalloc(sizeof(*subdev), GFP_KERNEL);
@@ -56,13 +55,12 @@ static int host1x_subdev_add(struct host1x_device *device,
	mutex_unlock(&device->subdevs_lock);

	/* recursively add children */
	for_each_child_of_node(np, child) {
	for_each_child_of_node_scoped(np, child) {
		if (of_match_node(driver->subdevs, child) &&
		    of_device_is_available(child)) {
			err = host1x_subdev_add(device, driver, child);
			if (err < 0) {
				/* XXX cleanup? */
				of_node_put(child);
				return err;
			}
		}
@@ -90,19 +88,16 @@ static void host1x_subdev_del(struct host1x_subdev *subdev)
static int host1x_device_parse_dt(struct host1x_device *device,
				  struct host1x_driver *driver)
{
	struct device_node *np;
	int err;

	for_each_child_of_node(device->dev.parent->of_node, np) {
	for_each_child_of_node_scoped(device->dev.parent->of_node, np) {
		if (of_match_node(driver->subdevs, np) &&
		    of_device_is_available(np)) {
			err = host1x_subdev_add(device, driver, np);
			if (err < 0) {
				of_node_put(np);
			if (err < 0)
				return err;
		}
	}
	}

	return 0;
}