Skip to content

Commit cbdef31

Browse files
committed
of: unittest: Fix compile in the non-dynamic case
JIRA: https://issues.redhat.com/browse/RHEL-37072 CVE: CVE-2023-52679 commit 607aad1 Author: Christian A. Ehrhardt <lk@c--e.de> Date: Mon Jan 29 20:25:56 2024 +0100 of: unittest: Fix compile in the non-dynamic case If CONFIG_OF_KOBJ is not set, a device_node does not contain a kobj and attempts to access the embedded kobj via kref_read break the compile. Replace affected kref_read calls with a macro that reads the refcount if it exists and returns 1 if there is no embedded kobj. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202401291740.VP219WIz-lkp@intel.com/ Fixes: 4dde835 ("of: Fix double free in of_parse_phandle_with_args_map") Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> Link: https://lore.kernel.org/r/20240129192556.403271-1-lk@c--e.de Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: Steve Best <sbest@redhat.com>
1 parent de737bb commit cbdef31

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/of/unittest.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ static struct unittest_results {
4949
failed; \
5050
})
5151

52+
#ifdef CONFIG_OF_KOBJ
53+
#define OF_KREF_READ(NODE) kref_read(&(NODE)->kobj.kref)
54+
#else
55+
#define OF_KREF_READ(NODE) 1
56+
#endif
57+
5258
/*
5359
* Expected message may have a message level other than KERN_INFO.
5460
* Print the expected message only if the current loglevel will allow
@@ -562,7 +568,7 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
562568
pr_err("missing testcase data\n");
563569
return;
564570
}
565-
prefs[i] = kref_read(&p[i]->kobj.kref);
571+
prefs[i] = OF_KREF_READ(p[i]);
566572
}
567573

568574
rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
@@ -685,9 +691,9 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
685691
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
686692

687693
for (i = 0; i < ARRAY_SIZE(p); ++i) {
688-
unittest(prefs[i] == kref_read(&p[i]->kobj.kref),
694+
unittest(prefs[i] == OF_KREF_READ(p[i]),
689695
"provider%d: expected:%d got:%d\n",
690-
i, prefs[i], kref_read(&p[i]->kobj.kref));
696+
i, prefs[i], OF_KREF_READ(p[i]));
691697
of_node_put(p[i]);
692698
}
693699
}

0 commit comments

Comments
 (0)