mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] of: unittest: fix possible null-pointer dereferences in of_unittest_property_copy()
@ 2026-01-05  7:14 Tuo Li
  2026-01-05 22:11 ` Rob Herring (Arm)
  0 siblings, 1 reply; 2+ messages in thread
From: Tuo Li @ 2026-01-05  7:14 UTC (permalink / raw)
  To: robh, saravanak; +Cc: devicetree, linux-kernel, Tuo Li

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>
---
 drivers/of/unittest.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 388e9ec2cccf..ea650a9ca2d9 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -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
 }
 
-- 
2.43.0


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

* Re: [PATCH] of: unittest: fix possible null-pointer dereferences in of_unittest_property_copy()
  2026-01-05  7:14 [PATCH] of: unittest: fix possible null-pointer dereferences in of_unittest_property_copy() Tuo Li
@ 2026-01-05 22:11 ` Rob Herring (Arm)
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring (Arm) @ 2026-01-05 22:11 UTC (permalink / raw)
  To: Tuo Li; +Cc: devicetree, linux-kernel, saravanak


On Mon, 05 Jan 2026 15:14:38 +0800, Tuo Li wrote:
> 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>
> ---
>  drivers/of/unittest.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 

Applied, thanks!


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

end of thread, other threads:[~2026-01-05 22:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05  7:14 [PATCH] of: unittest: fix possible null-pointer dereferences in of_unittest_property_copy() Tuo Li
2026-01-05 22:11 ` Rob Herring (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®