drivers/memstick/core/memstick.c
Source file repositories/reference/linux-study-clean/drivers/memstick/core/memstick.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/memstick/core/memstick.c- Extension
.c- Size
- 16776 bytes
- Lines
- 672
- Domain
- Driver Families
- Bucket
- drivers/memstick
- 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/memstick.hlinux/idr.hlinux/fs.hlinux/delay.hlinux/slab.hlinux/module.hlinux/pm_runtime.h
Detected Declarations
function memstick_dev_matchfunction memstick_bus_matchfunction memstick_ueventfunction memstick_device_probefunction memstick_device_removefunction memstick_device_suspendfunction memstick_device_resumefunction memstick_freefunction memstick_free_cardfunction memstick_dummy_checkfunction memstick_detect_changefunction statefunction memstick_new_reqfunction memstick_init_req_sgfunction functionfunction finishedfunction h_memstick_set_rw_addrfunction memstick_set_rw_addrfunction memstick_power_onfunction memstick_checkfunction memstick_add_hostfunction memstick_remove_hostfunction memstick_free_hostfunction memstick_suspend_hostfunction memstick_resume_hostfunction memstick_register_driverfunction memstick_unregister_driverfunction memstick_initfunction memstick_exitmodule init memstick_initexport memstick_detect_changeexport memstick_next_reqexport memstick_new_reqexport memstick_init_req_sgexport memstick_init_reqexport memstick_set_rw_addrexport memstick_alloc_hostexport memstick_add_hostexport memstick_remove_hostexport memstick_free_hostexport memstick_suspend_hostexport memstick_resume_hostexport memstick_register_driverexport memstick_unregister_driver
Annotated Snippet
static int memstick_bus_match(struct device *dev, const struct device_driver *drv)
{
struct memstick_dev *card = container_of(dev, struct memstick_dev,
dev);
const struct memstick_driver *ms_drv = container_of_const(drv, struct memstick_driver,
driver);
const struct memstick_device_id *ids = ms_drv->id_table;
if (ids) {
while (ids->match_flags) {
if (memstick_dev_match(card, ids))
return 1;
++ids;
}
}
return 0;
}
static int memstick_uevent(const struct device *dev, struct kobj_uevent_env *env)
{
const struct memstick_dev *card = container_of_const(dev, struct memstick_dev,
dev);
if (add_uevent_var(env, "MEMSTICK_TYPE=%02X", card->id.type))
return -ENOMEM;
if (add_uevent_var(env, "MEMSTICK_CATEGORY=%02X", card->id.category))
return -ENOMEM;
if (add_uevent_var(env, "MEMSTICK_CLASS=%02X", card->id.class))
return -ENOMEM;
return 0;
}
static int memstick_device_probe(struct device *dev)
{
struct memstick_dev *card = container_of(dev, struct memstick_dev,
dev);
struct memstick_driver *drv = container_of(dev->driver,
struct memstick_driver,
driver);
int rc = -ENODEV;
if (dev->driver && drv->probe) {
rc = drv->probe(card);
if (!rc)
get_device(dev);
}
return rc;
}
static void memstick_device_remove(struct device *dev)
{
struct memstick_dev *card = container_of(dev, struct memstick_dev,
dev);
struct memstick_driver *drv = container_of(dev->driver,
struct memstick_driver,
driver);
if (dev->driver && drv->remove) {
drv->remove(card);
card->dev.driver = NULL;
}
put_device(dev);
}
#ifdef CONFIG_PM
static int memstick_device_suspend(struct device *dev, pm_message_t state)
{
struct memstick_dev *card = container_of(dev, struct memstick_dev,
dev);
struct memstick_driver *drv = container_of(dev->driver,
struct memstick_driver,
driver);
if (dev->driver && drv->suspend)
return drv->suspend(card, state);
return 0;
}
static int memstick_device_resume(struct device *dev)
{
struct memstick_dev *card = container_of(dev, struct memstick_dev,
dev);
struct memstick_driver *drv = container_of(dev->driver,
struct memstick_driver,
driver);
Annotation
- Immediate include surface: `linux/memstick.h`, `linux/idr.h`, `linux/fs.h`, `linux/delay.h`, `linux/slab.h`, `linux/module.h`, `linux/pm_runtime.h`.
- Detected declarations: `function memstick_dev_match`, `function memstick_bus_match`, `function memstick_uevent`, `function memstick_device_probe`, `function memstick_device_remove`, `function memstick_device_suspend`, `function memstick_device_resume`, `function memstick_free`, `function memstick_free_card`, `function memstick_dummy_check`.
- Atlas domain: Driver Families / drivers/memstick.
- 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.