lib/kunit/platform.c
Source file repositories/reference/linux-study-clean/lib/kunit/platform.c
File Facts
- System
- Linux kernel
- Corpus path
lib/kunit/platform.c- Extension
.c- Size
- 10362 bytes
- Lines
- 367
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- 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/completion.hlinux/device/bus.hlinux/device/driver.hlinux/err.hlinux/platform_device.hkunit/platform_device.hkunit/resource.h
Detected Declarations
struct kunit_platform_device_alloc_paramsstruct kunit_platform_device_probe_nbfunction kunit_platform_device_alloc_initfunction kunit_platform_device_alloc_exitfunction kunit_platform_device_allocfunction kunit_platform_device_add_exitfunction kunit_platform_device_alloc_matchfunction kunit_platform_device_addfunction kunit_platform_device_register_fullfunction kunit_platform_device_add_matchfunction kunit_platform_device_unregisterfunction kunit_platform_device_probe_notifyfunction kunit_platform_device_probe_nb_removefunction kunit_platform_device_prepare_wait_for_probefunction kunit_platform_driver_registerexport kunit_platform_device_allocexport kunit_platform_device_addexport kunit_platform_device_register_fullexport kunit_platform_device_unregisterexport kunit_platform_device_prepare_wait_for_probeexport kunit_platform_driver_register
Annotated Snippet
struct kunit_platform_device_alloc_params {
const char *name;
int id;
};
static int kunit_platform_device_alloc_init(struct kunit_resource *res, void *context)
{
struct kunit_platform_device_alloc_params *params = context;
struct platform_device *pdev;
pdev = platform_device_alloc(params->name, params->id);
if (!pdev)
return -ENOMEM;
res->data = pdev;
return 0;
}
static void kunit_platform_device_alloc_exit(struct kunit_resource *res)
{
struct platform_device *pdev = res->data;
platform_device_put(pdev);
}
/**
* kunit_platform_device_alloc() - Allocate a KUnit test managed platform device
* @test: test context
* @name: device name of platform device to alloc
* @id: identifier of platform device to alloc.
*
* Allocate a test managed platform device. The device is put when the test completes.
*
* Return: Allocated platform device on success, NULL on failure.
*/
struct platform_device *
kunit_platform_device_alloc(struct kunit *test, const char *name, int id)
{
struct kunit_platform_device_alloc_params params = {
.name = name,
.id = id,
};
return kunit_alloc_resource(test,
kunit_platform_device_alloc_init,
kunit_platform_device_alloc_exit,
GFP_KERNEL, ¶ms);
}
EXPORT_SYMBOL_GPL(kunit_platform_device_alloc);
static void kunit_platform_device_add_exit(struct kunit_resource *res)
{
struct platform_device *pdev = res->data;
platform_device_unregister(pdev);
}
static bool
kunit_platform_device_alloc_match(struct kunit *test,
struct kunit_resource *res, void *match_data)
{
struct platform_device *pdev = match_data;
return res->data == pdev && res->free == kunit_platform_device_alloc_exit;
}
KUNIT_DEFINE_ACTION_WRAPPER(platform_device_unregister_wrapper,
platform_device_unregister, struct platform_device *);
/**
* kunit_platform_device_add() - Register a KUnit test managed platform device
* @test: test context
* @pdev: platform device to add
*
* Register a test managed platform device. The device is unregistered when the
* test completes.
*
* Return: 0 on success, negative errno on failure.
*/
int kunit_platform_device_add(struct kunit *test, struct platform_device *pdev)
{
struct kunit_resource *res;
int ret;
ret = platform_device_add(pdev);
if (ret)
return ret;
res = kunit_find_resource(test, kunit_platform_device_alloc_match, pdev);
if (res) {
Annotation
- Immediate include surface: `linux/completion.h`, `linux/device/bus.h`, `linux/device/driver.h`, `linux/err.h`, `linux/platform_device.h`, `kunit/platform_device.h`, `kunit/resource.h`.
- Detected declarations: `struct kunit_platform_device_alloc_params`, `struct kunit_platform_device_probe_nb`, `function kunit_platform_device_alloc_init`, `function kunit_platform_device_alloc_exit`, `function kunit_platform_device_alloc`, `function kunit_platform_device_add_exit`, `function kunit_platform_device_alloc_match`, `function kunit_platform_device_add`, `function kunit_platform_device_register_full`, `function kunit_platform_device_add_match`.
- Atlas domain: Kernel Services / lib.
- 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.