drivers/mtd/ubi/build.c
Source file repositories/reference/linux-study-clean/drivers/mtd/ubi/build.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/ubi/build.c- Extension
.c- Size
- 47264 bytes
- Lines
- 1603
- Domain
- Driver Families
- Bucket
- drivers/mtd
- 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.
- 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/err.hlinux/module.hlinux/moduleparam.hlinux/stringify.hlinux/namei.hlinux/stat.hlinux/miscdevice.hlinux/mtd/partitions.hlinux/log2.hlinux/kthread.hlinux/kernel.hlinux/of.hlinux/slab.hlinux/major.hubi.h
Detected Declarations
struct mtd_dev_paramfunction version_showfunction eventfunction ubi_notify_allfunction ubi_enumerate_volumesfunction ubi_put_devicefunction ubi_major2numfunction dev_attribute_showfunction dev_releasefunction kill_volumesfunction uif_initfunction wellfunction ubi_free_volumes_fromfunction ubi_free_all_volumesfunction ubi_free_internal_volumesfunction get_bad_peb_limitfunction io_initfunction autoresizefunction ubi_attach_mtd_devfunction attachingfunction ubi_detach_mtd_devfunction open_mtd_by_chdevfunction open_mtd_devicefunction ubi_notify_addfunction ubi_notify_removefunction ubi_init_attachfunction ubi_initfunction ubi_exitfunction bytes_str_to_intfunction ubi_mtd_param_parsemodule init ubi_init
Annotated Snippet
device_initcall(ubi_init);
static void __exit ubi_exit(void)
{
int i;
ubiblock_exit();
unregister_mtd_user(&ubi_mtd_notifier);
for (i = 0; i < UBI_MAX_DEVICES; i++)
if (ubi_devices[i]) {
mutex_lock(&ubi_devices_mutex);
ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1);
mutex_unlock(&ubi_devices_mutex);
}
ubi_debugfs_exit();
kmem_cache_destroy(ubi_wl_entry_slab);
misc_deregister(&ubi_ctrl_cdev);
class_unregister(&ubi_class);
}
module_exit(ubi_exit);
/**
* bytes_str_to_int - convert a number of bytes string into an integer.
* @str: the string to convert
*
* This function returns positive resulting integer in case of success and a
* negative error code in case of failure.
*/
static int bytes_str_to_int(const char *str)
{
char *endp;
unsigned long result;
result = simple_strtoul(str, &endp, 0);
if (str == endp || result >= INT_MAX) {
pr_err("UBI error: incorrect bytes count: \"%s\"\n", str);
return -EINVAL;
}
switch (*endp) {
case 'G':
result *= 1024;
fallthrough;
case 'M':
result *= 1024;
fallthrough;
case 'K':
result *= 1024;
break;
case '\0':
break;
default:
pr_err("UBI error: incorrect bytes count: \"%s\"\n", str);
return -EINVAL;
}
return result;
}
/**
* ubi_mtd_param_parse - parse the 'mtd=' UBI parameter.
* @val: the parameter value to parse
* @kp: not used
*
* This function returns zero in case of success and a negative error code in
* case of error.
*/
static int ubi_mtd_param_parse(const char *val, const struct kernel_param *kp)
{
int i, len;
struct mtd_dev_param *p;
char buf[MTD_PARAM_LEN_MAX];
char *pbuf = &buf[0];
char *tokens[MTD_PARAM_MAX_COUNT], *token;
if (!val)
return -EINVAL;
if (mtd_devs == UBI_MAX_DEVICES) {
pr_err("UBI error: too many parameters, max. is %d\n",
UBI_MAX_DEVICES);
return -EINVAL;
}
len = strnlen(val, MTD_PARAM_LEN_MAX);
if (len == MTD_PARAM_LEN_MAX) {
pr_err("UBI error: parameter \"%s\" is too long, max. is %d\n",
val, MTD_PARAM_LEN_MAX);
Annotation
- Immediate include surface: `linux/err.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/stringify.h`, `linux/namei.h`, `linux/stat.h`, `linux/miscdevice.h`, `linux/mtd/partitions.h`.
- Detected declarations: `struct mtd_dev_param`, `function version_show`, `function event`, `function ubi_notify_all`, `function ubi_enumerate_volumes`, `function ubi_put_device`, `function ubi_major2num`, `function dev_attribute_show`, `function dev_release`, `function kill_volumes`.
- Atlas domain: Driver Families / drivers/mtd.
- 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.