drivers/pnp/card.c
Source file repositories/reference/linux-study-clean/drivers/pnp/card.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pnp/card.c- Extension
.c- Size
- 9455 bytes
- Lines
- 426
- Domain
- Driver Families
- Bucket
- drivers/pnp
- 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/mutex.hlinux/ctype.hlinux/slab.hlinux/pnp.hlinux/dma-mapping.hbase.h
Detected Declarations
function card_for_each_devfunction card_removefunction card_remove_firstfunction card_probefunction pnp_free_card_idsfunction pnp_release_cardfunction name_showfunction card_id_showfunction pnp_interface_attach_cardfunction pnp_add_cardfunction pnp_add_card_devicefunction pnp_release_card_devicefunction card_suspendfunction card_resumefunction pnp_register_card_driverfunction list_for_each_safefunction pnp_unregister_card_driverexport pnp_request_card_deviceexport pnp_release_card_deviceexport pnp_register_card_driverexport pnp_unregister_card_driver
Annotated Snippet
if (compare_pnp_id(card->id, drv_id->id)) {
int i = 0;
for (;;) {
int found;
struct pnp_dev *dev;
if (i == PNP_MAX_DEVICES ||
!*drv_id->devs[i].id)
return drv_id;
found = 0;
card_for_each_dev(card, dev) {
if (compare_pnp_id(dev->id,
drv_id->devs[i].id)) {
found = 1;
break;
}
}
if (!found)
break;
i++;
}
}
drv_id++;
}
return NULL;
}
static void card_remove(struct pnp_dev *dev)
{
dev->card_link = NULL;
}
static void card_remove_first(struct pnp_dev *dev)
{
struct pnp_card_driver *drv = to_pnp_card_driver(dev->driver);
if (!dev->card || !drv)
return;
if (drv->remove)
drv->remove(dev->card_link);
drv->link.remove = &card_remove;
kfree(dev->card_link);
card_remove(dev);
}
static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv)
{
const struct pnp_card_device_id *id;
struct pnp_card_link *clink;
struct pnp_dev *dev;
if (!drv->probe)
return 0;
id = match_card(drv, card);
if (!id)
return 0;
clink = kzalloc_obj(*clink);
if (!clink)
return 0;
clink->card = card;
clink->driver = drv;
clink->pm_state = PMSG_ON;
if (drv->probe(clink, id) >= 0)
return 1;
/* Recovery */
card_for_each_dev(card, dev) {
if (dev->card_link == clink)
pnp_release_card_device(dev);
}
kfree(clink);
return 0;
}
/**
* pnp_add_card_id - adds an EISA id to the specified card
* @id: pointer to a pnp_id structure
* @card: pointer to the desired card
*/
static struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id)
{
struct pnp_id *dev_id, *ptr;
dev_id = kzalloc_obj(struct pnp_id);
if (!dev_id)
return NULL;
Annotation
- Immediate include surface: `linux/module.h`, `linux/mutex.h`, `linux/ctype.h`, `linux/slab.h`, `linux/pnp.h`, `linux/dma-mapping.h`, `base.h`.
- Detected declarations: `function card_for_each_dev`, `function card_remove`, `function card_remove_first`, `function card_probe`, `function pnp_free_card_ids`, `function pnp_release_card`, `function name_show`, `function card_id_show`, `function pnp_interface_attach_card`, `function pnp_add_card`.
- Atlas domain: Driver Families / drivers/pnp.
- 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.