From: Daniel Scally Date: Thu, 7 Jan 2021 13:28:24 +0000 (+0100) Subject: media: software_node: Fix refcounts in software_node_get_next_child() X-Git-Tag: v5.15~1736^2~176 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fb5ec981adf08b94e6ce27ca16b7765c94f4513c;p=platform%2Fkernel%2Flinux-starfive.git media: software_node: Fix refcounts in software_node_get_next_child() The software_node_get_next_child() function currently does not hold references to the child software_node that it finds or put the ref that is held against the old child - fix that. Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework") Reviewed-by: Andy Shevchenko Reviewed-by: Laurent Pinchart Signed-off-by: Daniel Scally Reviewed-by: Heikki Krogerus Acked-by: Greg Kroah-Hartman Acked-by: Rafael J. Wysocki Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 4a4b200..4fcc1a6 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -443,14 +443,18 @@ software_node_get_next_child(const struct fwnode_handle *fwnode, struct swnode *c = to_swnode(child); if (!p || list_empty(&p->children) || - (c && list_is_last(&c->entry, &p->children))) + (c && list_is_last(&c->entry, &p->children))) { + fwnode_handle_put(child); return NULL; + } if (c) c = list_next_entry(c, entry); else c = list_first_entry(&p->children, struct swnode, entry); - return &c->fwnode; + + fwnode_handle_put(child); + return fwnode_handle_get(&c->fwnode); } static struct fwnode_handle *