@@ -23,15 +23,17 @@
static int pSeries_reconfig_add_node(const char *path, struct property *proplist)
{
struct device_node *np;
- int err = -ENOMEM;
+ int err;
np = kzalloc(sizeof(*np), GFP_KERNEL);
if (!np)
- goto out_err;
+ return -ENOMEM;
np->full_name = kstrdup(kbasename(path), GFP_KERNEL);
- if (!np->full_name)
- goto out_err;
+ if (!np->full_name) {
+ err = -ENOMEM;
+ goto free_device_node;
+ }
np->properties = proplist;
of_node_set_flag(np, OF_DYNAMIC);
@@ -46,20 +48,19 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist
err = of_attach_node(np);
if (err) {
printk(KERN_ERR "Failed to add device node %s\n", path);
- goto out_err;
+ goto put_node;
}
of_node_put(np->parent);
return 0;
-out_err:
- if (np) {
- of_node_put(np->parent);
+put_node:
+ of_node_put(np->parent);
free_name:
- kfree(np->full_name);
- kfree(np);
- }
+ kfree(np->full_name);
+free_device_node:
+ kfree(np);
return err;
}
Date: Tue, 21 Mar 2023 10:50:08 +0100 The label “out_err” was used to jump to another pointer check despite of the detail in the implementation of the function “pSeries_reconfig_add_node” that it was determined already that the corresponding variable contained a null pointer (because of a failed function call in two cases). 1. Thus return directly after a call of the function “kzalloc” failed. 2. Use more appropriate labels instead. 3. Delete a redundant check. 4. Omit an explicit initialisation for the local variable “err”. This issue was detected by using the Coccinelle software. Fixes: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 ("Linux-2.6.12-rc2") Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- V2: This update step was based on a previous change. arch/powerpc/platforms/pseries/reconfig.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) -- 2.40.0