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.

Dependency Surface

Detected Declarations

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

Implementation Notes