kernel/params.c
Source file repositories/reference/linux-study-clean/kernel/params.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/params.c- Extension
.c- Size
- 24296 bytes
- Lines
- 997
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/ctype.hlinux/device.hlinux/err.hlinux/errno.hlinux/kernel.hlinux/kstrtox.hlinux/module.hlinux/moduleparam.hlinux/overflow.hlinux/security.hlinux/slab.hlinux/string.h
Detected Declarations
struct kmalloced_paramstruct param_attributestruct module_param_attrsfunction check_kparam_lockedfunction check_kparam_lockedfunction maybe_kfree_parameterfunction dash2underscorefunction parameqnfunction parameqfunction param_check_unsafefunction parse_onefunction param_set_uint_minmaxfunction param_set_charpfunction param_get_charpfunction param_free_charpfunction param_set_boolfunction param_get_boolfunction param_set_bool_enable_onlyfunction param_set_invboolfunction param_get_invboolfunction param_set_bintfunction param_arrayfunction param_array_setfunction param_array_getfunction param_array_freefunction param_set_copystringfunction param_get_stringfunction param_attr_showfunction param_attr_storefunction kernel_param_lockfunction kernel_param_unlockfunction afunction free_module_param_attrsfunction module_param_sysfs_setupfunction module_param_sysfs_removefunction lookup_or_create_module_kobjectfunction kernel_add_sysfs_paramfunction param_sysfs_builtinfunction __modver_version_showfunction version_sysfs_builtinfunction module_attr_showfunction module_attr_storefunction uevent_filterfunction module_kobj_releasefunction param_sysfs_initfunction param_sysfs_builtin_initfunction module_destroy_paramsexport param_set_uint_minmax
Annotated Snippet
struct kmalloced_param {
struct list_head list;
char val[];
};
static LIST_HEAD(kmalloced_params);
static DEFINE_SPINLOCK(kmalloced_params_lock);
static void *kmalloc_parameter(unsigned int size)
{
struct kmalloced_param *p;
p = kmalloc(size_add(sizeof(*p), size), GFP_KERNEL);
if (!p)
return NULL;
spin_lock(&kmalloced_params_lock);
list_add(&p->list, &kmalloced_params);
spin_unlock(&kmalloced_params_lock);
return p->val;
}
/* Does nothing if parameter wasn't kmalloced above. */
static void maybe_kfree_parameter(void *param)
{
struct kmalloced_param *p;
spin_lock(&kmalloced_params_lock);
list_for_each_entry(p, &kmalloced_params, list) {
if (p->val == param) {
list_del(&p->list);
kfree(p);
break;
}
}
spin_unlock(&kmalloced_params_lock);
}
static char dash2underscore(char c)
{
if (c == '-')
return '_';
return c;
}
bool parameqn(const char *a, const char *b, size_t n)
{
size_t i;
for (i = 0; i < n; i++) {
if (dash2underscore(a[i]) != dash2underscore(b[i]))
return false;
}
return true;
}
bool parameq(const char *a, const char *b)
{
return parameqn(a, b, strlen(a)+1);
}
static bool param_check_unsafe(const struct kernel_param *kp)
{
if (kp->flags & KERNEL_PARAM_FL_HWPARAM &&
security_locked_down(LOCKDOWN_MODULE_PARAMETERS))
return false;
if (kp->flags & KERNEL_PARAM_FL_UNSAFE) {
pr_notice("Setting dangerous option %s - tainting kernel\n",
kp->name);
add_taint(TAINT_USER, LOCKDEP_STILL_OK);
}
return true;
}
static int parse_one(char *param,
char *val,
const char *doing,
const struct kernel_param *params,
unsigned num_params,
s16 min_level,
s16 max_level,
void *arg, parse_unknown_fn handle_unknown)
{
unsigned int i;
int err;
/* Find parameter */
for (i = 0; i < num_params; i++) {
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/device.h`, `linux/err.h`, `linux/errno.h`, `linux/kernel.h`, `linux/kstrtox.h`, `linux/module.h`, `linux/moduleparam.h`.
- Detected declarations: `struct kmalloced_param`, `struct param_attribute`, `struct module_param_attrs`, `function check_kparam_locked`, `function check_kparam_locked`, `function maybe_kfree_parameter`, `function dash2underscore`, `function parameqn`, `function parameq`, `function param_check_unsafe`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.