drivers/of/of_kunit_helpers.c
Source file repositories/reference/linux-study-clean/drivers/of/of_kunit_helpers.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/of/of_kunit_helpers.c- Extension
.c- Size
- 2511 bytes
- Lines
- 94
- Domain
- Driver Families
- Bucket
- drivers/of
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/of.hlinux/of_fdt.hkunit/of.hkunit/test.hkunit/resource.hof_private.h
Detected Declarations
function of_root_kunit_skipfunction of_overlay_fdt_apply_kunit_exitfunction of_overlay_fdt_apply_kunitfunction of_node_put_kunitexport of_root_kunit_skipexport of_overlay_fdt_apply_kunitexport of_node_put_kunit
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Test managed DeviceTree APIs
*/
#include <linux/of.h>
#include <linux/of_fdt.h>
#include <kunit/of.h>
#include <kunit/test.h>
#include <kunit/resource.h>
#include "of_private.h"
/**
* of_root_kunit_skip() - Skip test if the root node isn't populated
* @test: test to skip if the root node isn't populated
*/
void of_root_kunit_skip(struct kunit *test)
{
if ((IS_ENABLED(CONFIG_ARM64) || IS_ENABLED(CONFIG_RISCV)) &&
IS_ENABLED(CONFIG_ACPI) && !of_root)
kunit_skip(test, "arm64/riscv+acpi doesn't populate a root node");
}
EXPORT_SYMBOL_GPL(of_root_kunit_skip);
#if defined(CONFIG_OF_OVERLAY) && defined(CONFIG_OF_EARLY_FLATTREE)
static void of_overlay_fdt_apply_kunit_exit(void *ovcs_id)
{
of_overlay_remove(ovcs_id);
}
/**
* of_overlay_fdt_apply_kunit() - Test managed of_overlay_fdt_apply()
* @test: test context
* @overlay_fdt: device tree overlay to apply
* @overlay_fdt_size: size in bytes of @overlay_fdt
* @ovcs_id: identifier of overlay, used to remove the overlay
*
* Just like of_overlay_fdt_apply(), except the overlay is managed by the test
* case and is automatically removed with of_overlay_remove() after the test
* case concludes.
*
* Return: 0 on success, negative errno on failure
*/
int of_overlay_fdt_apply_kunit(struct kunit *test, void *overlay_fdt,
u32 overlay_fdt_size, int *ovcs_id)
{
int ret;
int *copy_id;
of_root_kunit_skip(test);
copy_id = kunit_kmalloc(test, sizeof(*copy_id), GFP_KERNEL);
if (!copy_id)
return -ENOMEM;
ret = of_overlay_fdt_apply(overlay_fdt, overlay_fdt_size,
ovcs_id, NULL);
if (ret)
return ret;
*copy_id = *ovcs_id;
return kunit_add_action_or_reset(test, of_overlay_fdt_apply_kunit_exit,
copy_id);
}
EXPORT_SYMBOL_GPL(of_overlay_fdt_apply_kunit);
#endif
KUNIT_DEFINE_ACTION_WRAPPER(of_node_put_wrapper, of_node_put, struct device_node *);
/**
* of_node_put_kunit() - Test managed of_node_put()
* @test: test context
* @node: node to pass to `of_node_put()`
*
* Just like of_node_put(), except the node is managed by the test case and is
* automatically put with of_node_put() after the test case concludes.
*/
void of_node_put_kunit(struct kunit *test, struct device_node *node)
{
if (kunit_add_action(test, of_node_put_wrapper, node)) {
KUNIT_FAIL(test,
"Can't allocate a kunit resource to put of_node\n");
}
}
EXPORT_SYMBOL_GPL(of_node_put_kunit);
Annotation
- Immediate include surface: `linux/of.h`, `linux/of_fdt.h`, `kunit/of.h`, `kunit/test.h`, `kunit/resource.h`, `of_private.h`.
- Detected declarations: `function of_root_kunit_skip`, `function of_overlay_fdt_apply_kunit_exit`, `function of_overlay_fdt_apply_kunit`, `function of_node_put_kunit`, `export of_root_kunit_skip`, `export of_overlay_fdt_apply_kunit`, `export of_node_put_kunit`.
- Atlas domain: Driver Families / drivers/of.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.