node: fix device cleanups in error handling code
[ Upstream commit 4ce535ec0084f0d712317cb99d383cad3288e713 ]
We can't use kfree() to free device managed resources so the kfree(dev)
is against the rules.
It's easier to write this code if we open code the device_register() as
a device_initialize() and device_add(). That way if dev_set_name() set
name fails we can call put_device() and it will clean up correctly.
Fixes: acc02a109b
("node: Add memory-side caching attributes")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/YHA0JUra+F64+NpB@mwanda
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
3f605558a4
commit
d3b6b252ba
@ -262,21 +262,20 @@ static void node_init_cache_dev(struct node *node)
|
||||
if (!dev)
|
||||
return;
|
||||
|
||||
device_initialize(dev);
|
||||
dev->parent = &node->dev;
|
||||
dev->release = node_cache_release;
|
||||
if (dev_set_name(dev, "memory_side_cache"))
|
||||
goto free_dev;
|
||||
goto put_device;
|
||||
|
||||
if (device_register(dev))
|
||||
goto free_name;
|
||||
if (device_add(dev))
|
||||
goto put_device;
|
||||
|
||||
pm_runtime_no_callbacks(dev);
|
||||
node->cache_dev = dev;
|
||||
return;
|
||||
free_name:
|
||||
kfree_const(dev->kobj.name);
|
||||
free_dev:
|
||||
kfree(dev);
|
||||
put_device:
|
||||
put_device(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -313,25 +312,24 @@ void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs)
|
||||
return;
|
||||
|
||||
dev = &info->dev;
|
||||
device_initialize(dev);
|
||||
dev->parent = node->cache_dev;
|
||||
dev->release = node_cacheinfo_release;
|
||||
dev->groups = cache_groups;
|
||||
if (dev_set_name(dev, "index%d", cache_attrs->level))
|
||||
goto free_cache;
|
||||
goto put_device;
|
||||
|
||||
info->cache_attrs = *cache_attrs;
|
||||
if (device_register(dev)) {
|
||||
if (device_add(dev)) {
|
||||
dev_warn(&node->dev, "failed to add cache level:%d\n",
|
||||
cache_attrs->level);
|
||||
goto free_name;
|
||||
goto put_device;
|
||||
}
|
||||
pm_runtime_no_callbacks(dev);
|
||||
list_add_tail(&info->node, &node->cache_attrs);
|
||||
return;
|
||||
free_name:
|
||||
kfree_const(dev->kobj.name);
|
||||
free_cache:
|
||||
kfree(info);
|
||||
put_device:
|
||||
put_device(dev);
|
||||
}
|
||||
|
||||
static void node_remove_caches(struct node *node)
|
||||
|
Loading…
Reference in New Issue
Block a user