lib/test_firmware.c
Source file repositories/reference/linux-study-clean/lib/test_firmware.c
File Facts
- System
- Linux kernel
- Corpus path
lib/test_firmware.c- Extension
.c- Size
- 38391 bytes
- Lines
- 1573
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/init.hlinux/module.hlinux/printk.hlinux/completion.hlinux/firmware.hlinux/device.hlinux/fs.hlinux/miscdevice.hlinux/sizes.hlinux/slab.hlinux/uaccess.hlinux/delay.hlinux/kstrtox.hlinux/kthread.hlinux/vmalloc.hlinux/efi_embedded_fw.hlinux/string_choices.h
Detected Declarations
struct test_batched_reqstruct test_configstruct upload_inject_errstruct test_firmware_uploadfunction test_fw_misc_readfunction __test_release_all_firmwarefunction test_release_all_firmwarefunction __test_firmware_config_freefunction kfree_constfunction __test_firmware_config_initfunction reset_storefunction config_showfunction config_name_storefunction sysfs_kf_seq_showfunction __test_dev_config_update_boolfunction test_dev_config_update_boolfunction test_dev_config_show_boolfunction __test_dev_config_update_size_tfunction test_dev_config_show_size_tfunction test_dev_config_show_intfunction __test_dev_config_update_u8function test_dev_config_update_u8function test_dev_config_show_u8function config_name_showfunction config_upload_name_storefunction config_upload_name_showfunction config_num_requests_storefunction config_num_requests_showfunction config_into_buf_storefunction config_into_buf_showfunction config_buf_size_storefunction config_buf_size_showfunction config_file_offset_storefunction config_file_offset_showfunction config_partial_storefunction config_partial_showfunction config_sync_direct_storefunction config_sync_direct_showfunction config_send_uevent_storefunction config_send_uevent_showfunction config_read_fw_idx_storefunction config_read_fw_idx_showfunction trigger_request_storefunction trigger_request_platform_storefunction memcmpfunction trigger_async_request_cbfunction trigger_async_request_storefunction trigger_custom_fallback_store
Annotated Snippet
static const struct file_operations test_fw_fops = {
.owner = THIS_MODULE,
.read = test_fw_misc_read,
};
static void __test_release_all_firmware(void)
{
struct test_batched_req *req;
u8 i;
if (!test_fw_config->reqs)
return;
for (i = 0; i < test_fw_config->num_requests; i++) {
req = &test_fw_config->reqs[i];
if (req->fw) {
if (req->fw_buf) {
kfree_const(req->fw_buf);
req->fw_buf = NULL;
}
release_firmware(req->fw);
req->fw = NULL;
}
}
vfree(test_fw_config->reqs);
test_fw_config->reqs = NULL;
}
static void test_release_all_firmware(void)
{
mutex_lock(&test_fw_mutex);
__test_release_all_firmware();
mutex_unlock(&test_fw_mutex);
}
static void __test_firmware_config_free(void)
{
__test_release_all_firmware();
kfree_const(test_fw_config->name);
test_fw_config->name = NULL;
}
/*
* XXX: move to kstrncpy() once merged.
*
* Users should use kfree_const() when freeing these.
*/
static int __kstrncpy(char **dst, const char *name, size_t count, gfp_t gfp)
{
*dst = kstrndup(name, count, gfp);
if (!*dst)
return -ENOMEM;
return count;
}
static int __test_firmware_config_init(void)
{
int ret;
ret = __kstrncpy(&test_fw_config->name, TEST_FIRMWARE_NAME,
strlen(TEST_FIRMWARE_NAME), GFP_KERNEL);
if (ret < 0)
goto out;
test_fw_config->num_requests = TEST_FIRMWARE_NUM_REQS;
test_fw_config->send_uevent = true;
test_fw_config->into_buf = false;
test_fw_config->buf_size = TEST_FIRMWARE_BUF_SIZE;
test_fw_config->file_offset = 0;
test_fw_config->partial = false;
test_fw_config->sync_direct = false;
test_fw_config->req_firmware = request_firmware;
test_fw_config->test_result = 0;
test_fw_config->reqs = NULL;
test_fw_config->upload_name = NULL;
return 0;
out:
__test_firmware_config_free();
return ret;
}
static ssize_t reset_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
int ret;
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/printk.h`, `linux/completion.h`, `linux/firmware.h`, `linux/device.h`, `linux/fs.h`, `linux/miscdevice.h`.
- Detected declarations: `struct test_batched_req`, `struct test_config`, `struct upload_inject_err`, `struct test_firmware_upload`, `function test_fw_misc_read`, `function __test_release_all_firmware`, `function test_release_all_firmware`, `function __test_firmware_config_free`, `function kfree_const`, `function __test_firmware_config_init`.
- Atlas domain: Kernel Services / lib.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.