drivers/mtd/ubi/kapi.c
Source file repositories/reference/linux-study-clean/drivers/mtd/ubi/kapi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/ubi/kapi.c- Extension
.c- Size
- 24643 bytes
- Lines
- 849
- 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/module.hlinux/err.hlinux/slab.hlinux/namei.hlinux/fs.hasm/div64.hubi.h
Detected Declarations
function Copyrightfunction ubi_get_device_infofunction ubi_do_get_volume_infofunction ubi_get_volume_infofunction ubi_get_num_by_pathfunction ubi_close_volumefunction ubi_leb_readfunction ubi_leb_readfunction ubi_leb_read_sgfunction ubi_leb_writefunction ubi_leb_changefunction ubi_leb_erasefunction ubi_leb_unmapfunction ubi_leb_mapfunction ubi_is_mappedfunction ubi_syncfunction ubi_register_volume_notifierfunction ubi_unregister_volume_notifierexport ubi_do_get_device_infoexport ubi_get_device_infoexport ubi_get_volume_infoexport ubi_open_volumeexport ubi_open_volume_nmexport ubi_open_volume_pathexport ubi_close_volumeexport ubi_leb_readexport ubi_leb_read_sgexport ubi_leb_writeexport ubi_leb_changeexport ubi_leb_eraseexport ubi_leb_unmapexport ubi_leb_mapexport ubi_is_mappedexport ubi_syncexport ubi_register_volume_notifierexport ubi_unregister_volume_notifier
Annotated Snippet
if (err < 0) {
mutex_unlock(&ubi->ckvol_mutex);
ubi_close_volume(desc);
return ERR_PTR(err);
}
if (err == 1) {
ubi_warn(ubi, "volume %d on UBI device %d is corrupted",
vol_id, ubi->ubi_num);
vol->corrupted = 1;
}
vol->checked = 1;
}
mutex_unlock(&ubi->ckvol_mutex);
return desc;
out_unlock:
spin_unlock(&ubi->volumes_lock);
module_put(THIS_MODULE);
out_free:
kfree(desc);
out_put_ubi:
ubi_err(ubi, "cannot open device %d, volume %d, error %d",
ubi_num, vol_id, err);
ubi_put_device(ubi);
return ERR_PTR(err);
}
EXPORT_SYMBOL_GPL(ubi_open_volume);
/**
* ubi_open_volume_nm - open UBI volume by name.
* @ubi_num: UBI device number
* @name: volume name
* @mode: open mode
*
* This function is similar to 'ubi_open_volume()', but opens a volume by name.
*/
struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
int mode)
{
int i, vol_id = -1, len;
struct ubi_device *ubi;
struct ubi_volume_desc *ret;
dbg_gen("open device %d, volume %s, mode %d", ubi_num, name, mode);
if (!name)
return ERR_PTR(-EINVAL);
len = strnlen(name, UBI_VOL_NAME_MAX + 1);
if (len > UBI_VOL_NAME_MAX)
return ERR_PTR(-EINVAL);
if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
return ERR_PTR(-EINVAL);
ubi = ubi_get_device(ubi_num);
if (!ubi)
return ERR_PTR(-ENODEV);
spin_lock(&ubi->volumes_lock);
/* Walk all volumes of this UBI device */
for (i = 0; i < ubi->vtbl_slots; i++) {
struct ubi_volume *vol = ubi->volumes[i];
if (vol && len == vol->name_len && !strcmp(name, vol->name)) {
vol_id = i;
break;
}
}
spin_unlock(&ubi->volumes_lock);
if (vol_id >= 0)
ret = ubi_open_volume(ubi_num, vol_id, mode);
else
ret = ERR_PTR(-ENODEV);
/*
* We should put the UBI device even in case of success, because
* 'ubi_open_volume()' took a reference as well.
*/
ubi_put_device(ubi);
return ret;
}
EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
/**
* ubi_get_num_by_path - get UBI device and volume number from device path
* @pathname: volume character device node path
* @ubi_num: pointer to UBI device number to be set
Annotation
- Immediate include surface: `linux/module.h`, `linux/err.h`, `linux/slab.h`, `linux/namei.h`, `linux/fs.h`, `asm/div64.h`, `ubi.h`.
- Detected declarations: `function Copyright`, `function ubi_get_device_info`, `function ubi_do_get_volume_info`, `function ubi_get_volume_info`, `function ubi_get_num_by_path`, `function ubi_close_volume`, `function ubi_leb_read`, `function ubi_leb_read`, `function ubi_leb_read_sg`, `function ubi_leb_write`.
- 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.