Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 4dde83569832 ("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>

authored by

Christian A. Ehrhardt and committed by
Rob Herring
607aad1e 8f7e9179

+9 -3
+9 -3
drivers/of/unittest.c
··· 50 50 failed; \ 51 51 }) 52 52 53 + #ifdef CONFIG_OF_KOBJ 54 + #define OF_KREF_READ(NODE) kref_read(&(NODE)->kobj.kref) 55 + #else 56 + #define OF_KREF_READ(NODE) 1 57 + #endif 58 + 53 59 /* 54 60 * Expected message may have a message level other than KERN_INFO. 55 61 * Print the expected message only if the current loglevel will allow ··· 576 570 pr_err("missing testcase data\n"); 577 571 return; 578 572 } 579 - prefs[i] = kref_read(&p[i]->kobj.kref); 573 + prefs[i] = OF_KREF_READ(p[i]); 580 574 } 581 575 582 576 rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); ··· 699 693 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 700 694 701 695 for (i = 0; i < ARRAY_SIZE(p); ++i) { 702 - unittest(prefs[i] == kref_read(&p[i]->kobj.kref), 696 + unittest(prefs[i] == OF_KREF_READ(p[i]), 703 697 "provider%d: expected:%d got:%d\n", 704 - i, prefs[i], kref_read(&p[i]->kobj.kref)); 698 + i, prefs[i], OF_KREF_READ(p[i])); 705 699 of_node_put(p[i]); 706 700 } 707 701 }