drivers/base/core.c
Source file repositories/reference/linux-study-clean/drivers/base/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/core.c- Extension
.c- Size
- 151293 bytes
- Lines
- 5435
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- 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/acpi.hlinux/blkdev.hlinux/cleanup.hlinux/cpufreq.hlinux/device.hlinux/dma-map-ops.hlinux/err.hlinux/fwnode.hlinux/init.hlinux/kdev_t.hlinux/kstrtox.hlinux/module.hlinux/mutex.hlinux/netdevice.hlinux/notifier.hlinux/of.hlinux/of_device.hlinux/pm_runtime.hlinux/sched/mm.hlinux/sched/signal.hlinux/slab.hlinux/string_helpers.hlinux/swiotlb.hlinux/sysfs.hbase.hphysical_location.hpower/power.h
Detected Declarations
struct class_dirstruct root_devicefunction __fwnode_link_addfunction list_for_each_entryfunction fwnode_link_addfunction __fwnode_link_delfunction __fwnode_link_cyclefunction fwnode_links_purge_suppliersfunction fwnode_links_purge_consumersfunction fwnode_links_purgefunction fw_devlink_purge_absent_suppliersfunction __fwnode_links_move_consumersfunction list_for_each_entry_safefunction probingfunction fw_devlink_pickup_dangling_consumersfunction fw_devlink_refresh_fwnodefunction device_links_write_lockfunction device_links_write_unlockfunction device_links_read_lockfunction device_links_read_unlockfunction device_links_read_lock_heldfunction device_link_synchronize_removalfunction device_link_remove_from_listsfunction device_is_ancestorfunction device_link_flag_is_sync_state_onlyfunction device_is_dependentfunction list_for_each_entryfunction device_link_init_statusfunction device_reorder_to_tailfunction device_reorder_to_tailfunction status_showfunction auto_remove_on_showfunction runtime_pm_showfunction sync_state_only_showfunction device_link_release_fnfunction devlink_dev_releasefunction device_link_wait_removalfunction devlink_add_symlinksfunction devlink_remove_symlinksfunction devlink_class_initfunction device_link_delfunction reversefunction list_for_each_entryfunction __device_link_delfunction device_link_put_kreffunction device_link_delfunction device_link_removefunction list_for_each_entry
Annotated Snippet
struct device_driver *drv;
/* dev->driver can change to NULL underneath us because of unbinding,
* so be careful about accessing it. dev->bus and dev->class should
* never change once they are set, so they don't need special care.
*/
drv = READ_ONCE(dev->driver);
return drv ? drv->name : dev_bus_name(dev);
}
EXPORT_SYMBOL(dev_driver_string);
#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
char *buf)
{
struct device_attribute *dev_attr = to_dev_attr(attr);
struct device *dev = kobj_to_dev(kobj);
ssize_t ret = -EIO;
if (dev_attr->show)
ret = dev_attr->show(dev, dev_attr, buf);
else if (dev_attr->show_const)
ret = dev_attr->show_const(dev, dev_attr, buf);
if (ret >= (ssize_t)PAGE_SIZE) {
printk("dev_attr_show: %pS/%pS returned bad count\n",
dev_attr->show, dev_attr->show_const);
}
return ret;
}
static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t count)
{
struct device_attribute *dev_attr = to_dev_attr(attr);
struct device *dev = kobj_to_dev(kobj);
ssize_t ret = -EIO;
if (dev_attr->store)
ret = dev_attr->store(dev, dev_attr, buf, count);
else if (dev_attr->store_const)
ret = dev_attr->store_const(dev, dev_attr, buf, count);
return ret;
}
static const struct sysfs_ops dev_sysfs_ops = {
.show = dev_attr_show,
.store = dev_attr_store,
};
#define to_ext_attr(x) container_of(x, struct dev_ext_attribute, attr)
ssize_t device_store_ulong(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
struct dev_ext_attribute *ea = to_ext_attr(attr);
int ret;
unsigned long new;
ret = kstrtoul(buf, 0, &new);
if (ret)
return ret;
*(unsigned long *)(ea->var) = new;
/* Always return full write size even if we didn't consume all */
return size;
}
EXPORT_SYMBOL_GPL(device_store_ulong);
ssize_t device_show_ulong(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct dev_ext_attribute *ea = to_ext_attr(attr);
return sysfs_emit(buf, "%lx\n", *(unsigned long *)(ea->var));
}
EXPORT_SYMBOL_GPL(device_show_ulong);
ssize_t device_store_int(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
struct dev_ext_attribute *ea = to_ext_attr(attr);
int ret;
long new;
ret = kstrtol(buf, 0, &new);
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/blkdev.h`, `linux/cleanup.h`, `linux/cpufreq.h`, `linux/device.h`, `linux/dma-map-ops.h`, `linux/err.h`, `linux/fwnode.h`.
- Detected declarations: `struct class_dir`, `struct root_device`, `function __fwnode_link_add`, `function list_for_each_entry`, `function fwnode_link_add`, `function __fwnode_link_del`, `function __fwnode_link_cycle`, `function fwnode_links_purge_suppliers`, `function fwnode_links_purge_consumers`, `function fwnode_links_purge`.
- Atlas domain: Driver Families / drivers/base.
- 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.