of: overlay: fix memory leak related to duplicated property
authorLixin Wang <alan.1.wang@nokia-sbell.com>
Mon, 16 Oct 2017 09:54:32 +0000 (17:54 +0800)
committerRob Herring <robh@kernel.org>
Tue, 17 Oct 2017 13:55:54 +0000 (08:55 -0500)
Function of_changeset_add_property or of_changeset_update_property may
fails. In this case the property just allocated is never deallocated.

Signed-off-by: Lixin Wang <alan.1.wang@nokia-sbell.com>
Signed-off-by: Rob Herring <robh@kernel.org>
drivers/of/overlay.c

index 8ecfee31ab6d3874602f9346cf077f985c2d484f..af3b9a16df263ba21a83585d156cfd3cb852b1f8 100644 (file)
@@ -162,6 +162,7 @@ static int of_overlay_apply_single_property(struct of_overlay *ov,
                bool is_symbols_node)
 {
        struct property *propn = NULL, *tprop;
+       int ret = 0;
 
        /* NOTE: Multiple changes of single properties not supported */
        tprop = of_find_property(target, prop->name, NULL);
@@ -186,10 +187,16 @@ static int of_overlay_apply_single_property(struct of_overlay *ov,
 
        /* not found? add */
        if (tprop == NULL)
-               return of_changeset_add_property(&ov->cset, target, propn);
-
-       /* found? update */
-       return of_changeset_update_property(&ov->cset, target, propn);
+               ret = of_changeset_add_property(&ov->cset, target, propn);
+       else /* found? update */
+               ret = of_changeset_update_property(&ov->cset, target, propn);
+
+       if (ret) {
+               kfree(propn->name);
+               kfree(propn->value);
+               kfree(propn);
+       }
+       return ret;
 }
 
 static int of_overlay_apply_single_device_node(struct of_overlay *ov,