diff options
| author | Tuo Li <islituo@gmail.com> | 2026-01-05 10:14:38 +0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-02-27 02:01:11 +0300 |
| commit | 9df290633cd0caa2160ec6a455c694ea6b4a0aff (patch) | |
| tree | 3df682d0c2eab840e6e4e9568f387293d153a30c /drivers/of | |
| parent | 0a6423a50ef274dad69cab7e2316283d080027ab (diff) | |
| download | linux-9df290633cd0caa2160ec6a455c694ea6b4a0aff.tar.xz | |
of: unittest: fix possible null-pointer dereferences in of_unittest_property_copy()
[ Upstream commit d289cb7fcefe41a54d8f9c6d0e0947f5f82b15c6 ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/of')
| -rw-r--r-- | drivers/of/unittest.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 3b773aaf9d05..9c184e93f50c 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 } |
