All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] node: fix error handling in node_init_node_access
@ 2022-06-21 17:16 Zhi Song
  2022-06-27 13:26 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Zhi Song @ 2022-06-21 17:16 UTC (permalink / raw)
  To: gregkh, rafael, Jonathan.Cameron, kbusch; +Cc: linux-kernel, Zhi Song

dev_set_name() allocates new space to dev->name if it allocates
successfully. But if we failed to allocate space, there won't be any
new space for dev->name. Therefore, there's no need for calling
kfree_const(dev->kobj.name) in dev_set_name()'s error handling.

If we failed to calling device_register(dev), we just need to call
put_device(dev) which will do access_node freeing, kobj.name freeing
and other cleanup.

Fixes: 08d9dbe72b1f ("node: Link memory nodes to their compute nodes")
Signed-off-by: Zhi Song <zhi.song@bytedance.com>
---
V1 -> V2: Fix up the changelog text correct.
V2 -> V3: Add a fixes tag line specifying the commit where this bug was
introduced.
V3 -> V4: Fix the error handling for dev_set_name() and
device_register() to perform cleanup correctly.
---
 drivers/base/node.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index 0ac6376ef7a1..0946931f113d 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -144,20 +144,19 @@ static struct node_access_nodes *node_init_node_access(struct node *node,
 	dev->parent = &node->dev;
 	dev->release = node_access_release;
 	dev->groups = node_access_node_groups;
-	if (dev_set_name(dev, "access%u", access))
-		goto free;
+	if (dev_set_name(dev, "access%u", access)) {
+		kfree(access_node);
+		return NULL;
+	}
 
-	if (device_register(dev))
-		goto free_name;
+	if (device_register(dev)) {
+		put_device(dev);
+		return NULL;
+	}
 
 	pm_runtime_no_callbacks(dev);
 	list_add_tail(&access_node->list_node, &node->access_list);
 	return access_node;
-free_name:
-	kfree_const(dev->kobj.name);
-free:
-	kfree(access_node);
-	return NULL;
 }
 
 #ifdef CONFIG_HMEM_REPORTING
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-27 13:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21 17:16 [PATCH v4] node: fix error handling in node_init_node_access Zhi Song
2022-06-27 13:26 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.