]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
of: unittest: fix possible null-pointer dereferences in of_unittest_property_copy()
authorTuo Li <islituo@gmail.com>
Mon, 5 Jan 2026 07:14:38 +0000 (15:14 +0800)
committerRob Herring (Arm) <robh@kernel.org>
Wed, 4 Feb 2026 02:58:10 +0000 (20:58 -0600)
This function first duplicates p1 and p2 into new, and then checks whether
the duplication succeeds. However, if the duplication fails (e.g.,
kzalloc() returns NULL in __of_prop_dup()), new will be NULL but is still
dereferenced in __of_prop_free(). To ensure that the unit test continues to
run even when duplication fails, add a NULL check before calling
__of_prop_free().

Fixes: 1c5e3d9bf33b ("of: Add a helper to free property struct")
Signed-off-by: Tuo Li <islituo@gmail.com>
Link: https://patch.msgid.link/20260105071438.156186-1-islituo@gmail.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
drivers/of/unittest.c

index 388e9ec2cccf8309ef77d832d453a0cc77e97523..ea650a9ca2d95401fc6e7cfeb3f7919fd161f1c7 100644 (file)
@@ -804,11 +804,13 @@ static void __init of_unittest_property_copy(void)
 
        new = __of_prop_dup(&p1, GFP_KERNEL);
        unittest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
-       __of_prop_free(new);
+       if (new)
+               __of_prop_free(new);
 
        new = __of_prop_dup(&p2, GFP_KERNEL);
        unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
-       __of_prop_free(new);
+       if (new)
+               __of_prop_free(new);
 #endif
 }