linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: unittest: Fix compile in the non-dynamic case
@ 2024-01-29 19:25 Christian A. Ehrhardt
  2024-01-31 20:29 ` Rob Herring
  0 siblings, 1 reply; 2+ messages in thread
From: Christian A. Ehrhardt @ 2024-01-29 19:25 UTC (permalink / raw)
  To: devicetree
  Cc: Christian A. Ehrhardt, kernel test robot, Rob Herring,
	Frank Rowand, linux-kernel

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: 4dde83569832 ("of: Fix double free in of_parse_phandle_with_args_map")
Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
---
 drivers/of/unittest.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index cfd60e35a899..d7593bde2d02 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -50,6 +50,12 @@ static struct unittest_results {
 	failed; \
 })
 
+#ifdef CONFIG_OF_KOBJ
+#define OF_KREF_READ(NODE) kref_read(&(NODE)->kobj.kref)
+#else
+#define OF_KREF_READ(NODE) 1
+#endif
+
 /*
  * Expected message may have a message level other than KERN_INFO.
  * Print the expected message only if the current loglevel will allow
@@ -570,7 +576,7 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
 			pr_err("missing testcase data\n");
 			return;
 		}
-		prefs[i] = kref_read(&p[i]->kobj.kref);
+		prefs[i] = OF_KREF_READ(p[i]);
 	}
 
 	rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
@@ -693,9 +699,9 @@ static void __init of_unittest_parse_phandle_with_args_map(void)
 	unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
 
 	for (i = 0; i < ARRAY_SIZE(p); ++i) {
-		unittest(prefs[i] == kref_read(&p[i]->kobj.kref),
+		unittest(prefs[i] == OF_KREF_READ(p[i]),
 			 "provider%d: expected:%d got:%d\n",
-			 i, prefs[i], kref_read(&p[i]->kobj.kref));
+			 i, prefs[i], OF_KREF_READ(p[i]));
 		of_node_put(p[i]);
 	}
 }
-- 
2.40.1


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

* Re: [PATCH] of: unittest: Fix compile in the non-dynamic case
  2024-01-29 19:25 [PATCH] of: unittest: Fix compile in the non-dynamic case Christian A. Ehrhardt
@ 2024-01-31 20:29 ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2024-01-31 20:29 UTC (permalink / raw)
  To: Christian A. Ehrhardt
  Cc: Rob Herring, kernel test robot, Frank Rowand, devicetree, linux-kernel


On Mon, 29 Jan 2024 20:25:56 +0100, Christian A. Ehrhardt wrote:
> 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: 4dde83569832 ("of: Fix double free in of_parse_phandle_with_args_map")
> Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
> ---
>  drivers/of/unittest.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 

Applied, thanks!


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

end of thread, other threads:[~2024-01-31 20:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 19:25 [PATCH] of: unittest: Fix compile in the non-dynamic case Christian A. Ehrhardt
2024-01-31 20:29 ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).