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

Configure Feed

Select the types of activity you want to include in your feed.

of: unittest: Add a case to test if API of_irq_parse_one() leaks refcount

To test if of_irq_parse_one(@int_gen_dev, i, ...) will leak refcount of
@i_th_phandle.

int_gen_dev {
...
interrupts-extended = ..., <&i_th_phandle ...>, ...;
...
};

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://lore.kernel.org/r/20250209-of_irq_fix-v2-1-93e3a2659aa7@quicinc.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

authored by

Zijun Hu and committed by
Rob Herring (Arm)
65f4be07 6c10926f

+45
+45
drivers/of/unittest.c
··· 1654 1654 of_node_put(np); 1655 1655 } 1656 1656 1657 + #if IS_ENABLED(CONFIG_OF_DYNAMIC) 1658 + static void __init of_unittest_irq_refcount(void) 1659 + { 1660 + struct of_phandle_args args; 1661 + struct device_node *intc0, *int_ext0; 1662 + unsigned int ref_c0, ref_c1, ref_c2; 1663 + int rc; 1664 + bool passed; 1665 + 1666 + if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC) 1667 + return; 1668 + 1669 + intc0 = of_find_node_by_path("/testcase-data/interrupts/intc0"); 1670 + int_ext0 = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0"); 1671 + if (!intc0 || !int_ext0) { 1672 + pr_err("missing testcase data\n"); 1673 + goto out; 1674 + } 1675 + 1676 + /* Test refcount for API of_irq_parse_one() */ 1677 + passed = true; 1678 + ref_c0 = OF_KREF_READ(intc0); 1679 + ref_c1 = ref_c0 + 1; 1680 + memset(&args, 0, sizeof(args)); 1681 + rc = of_irq_parse_one(int_ext0, 0, &args); 1682 + ref_c2 = OF_KREF_READ(intc0); 1683 + of_node_put(args.np); 1684 + 1685 + passed &= !rc; 1686 + passed &= (args.np == intc0); 1687 + passed &= (args.args_count == 1); 1688 + passed &= (args.args[0] == 1); 1689 + passed &= (ref_c1 == ref_c2); 1690 + unittest(passed, "IRQ refcount case #1 failed, original(%u) expected(%u) got(%u)\n", 1691 + ref_c0, ref_c1, ref_c2); 1692 + 1693 + out: 1694 + of_node_put(int_ext0); 1695 + of_node_put(intc0); 1696 + } 1697 + #else 1698 + static inline void __init of_unittest_irq_refcount(void) { } 1699 + #endif 1700 + 1657 1701 static const struct of_device_id match_node_table[] = { 1658 1702 { .data = "A", .name = "name0", }, /* Name alone is lowest priority */ 1659 1703 { .data = "B", .type = "type1", }, /* followed by type alone */ ··· 4368 4324 of_unittest_changeset_prop(); 4369 4325 of_unittest_parse_interrupts(); 4370 4326 of_unittest_parse_interrupts_extended(); 4327 + of_unittest_irq_refcount(); 4371 4328 of_unittest_dma_get_max_cpu_address(); 4372 4329 of_unittest_parse_dma_ranges(); 4373 4330 of_unittest_pci_dma_ranges();