drivers/base/faux.c
Source file repositories/reference/linux-study-clean/drivers/base/faux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/faux.c- Extension
.c- Size
- 7640 bytes
- Lines
- 264
- 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.
- 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/init.hlinux/slab.hlinux/string.hlinux/container_of.hlinux/device/faux.hbase.h
Detected Declarations
struct faux_objectfunction faux_matchfunction faux_probefunction faux_removefunction faux_device_releasefunction callbackfunction devicefunction faux_device_createfunction faux_bus_initexport faux_device_create_with_groupsexport faux_device_createexport faux_device_destroy
Annotated Snippet
static int faux_match(struct device *dev, const struct device_driver *drv)
{
/* Match always succeeds, we only have one driver */
return 1;
}
static int faux_probe(struct device *dev)
{
struct faux_object *faux_obj = to_faux_object(dev);
struct faux_device *faux_dev = &faux_obj->faux_dev;
const struct faux_device_ops *faux_ops = faux_obj->faux_ops;
int ret;
if (faux_ops && faux_ops->probe) {
ret = faux_ops->probe(faux_dev);
if (ret)
return ret;
}
/*
* Add groups after the probe succeeds to ensure resources are
* initialized correctly
*/
ret = device_add_groups(dev, faux_obj->groups);
if (ret && faux_ops && faux_ops->remove)
faux_ops->remove(faux_dev);
return ret;
}
static void faux_remove(struct device *dev)
{
struct faux_object *faux_obj = to_faux_object(dev);
struct faux_device *faux_dev = &faux_obj->faux_dev;
const struct faux_device_ops *faux_ops = faux_obj->faux_ops;
device_remove_groups(dev, faux_obj->groups);
if (faux_ops && faux_ops->remove)
faux_ops->remove(faux_dev);
}
static const struct bus_type faux_bus_type = {
.name = "faux",
.match = faux_match,
.probe = faux_probe,
.remove = faux_remove,
};
static struct device_driver faux_driver = {
.name = "faux_driver",
.bus = &faux_bus_type,
.probe_type = PROBE_FORCE_SYNCHRONOUS,
.suppress_bind_attrs = true,
};
static void faux_device_release(struct device *dev)
{
struct faux_object *faux_obj = to_faux_object(dev);
kfree(faux_obj);
}
/**
* faux_device_create_with_groups - Create and register with the driver
* core a faux device and populate the device with an initial
* set of sysfs attributes.
* @name: The name of the device we are adding, must be unique for
* all faux devices.
* @parent: Pointer to a potential parent struct device. If set to
* NULL, the device will be created in the "root" of the faux
* device tree in sysfs.
* @faux_ops: struct faux_device_ops that the new device will call back
* into, can be NULL.
* @groups: The set of sysfs attributes that will be created for this
* device when it is registered with the driver core.
*
* Create a new faux device and register it in the driver core properly.
* If present, callbacks in @faux_ops will be called with the device that
* for the caller to do something with at the proper time given the
* device's lifecycle.
*
* Note, when this function is called, the functions specified in struct
* faux_ops can be called before the function returns, so be prepared for
* everything to be properly initialized before that point in time. If the
* probe callback (if one is present) does NOT succeed, the creation of the
* device will fail and NULL will be returned.
*
* Return:
* * NULL if an error happened with creating the device
Annotation
- Immediate include surface: `linux/err.h`, `linux/init.h`, `linux/slab.h`, `linux/string.h`, `linux/container_of.h`, `linux/device/faux.h`, `base.h`.
- Detected declarations: `struct faux_object`, `function faux_match`, `function faux_probe`, `function faux_remove`, `function faux_device_release`, `function callback`, `function device`, `function faux_device_create`, `function faux_bus_init`, `export faux_device_create_with_groups`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: pattern implementation candidate.
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.