kernel/irq/devres.c

Source file repositories/reference/linux-study-clean/kernel/irq/devres.c

File Facts

System
Linux kernel
Corpus path
kernel/irq/devres.c
Extension
.c
Size
10815 bytes
Lines
372
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct irq_devres {
	unsigned int irq;
	void *dev_id;
};

static void devm_irq_release(struct device *dev, void *res)
{
	struct irq_devres *this = res;

	free_irq(this->irq, this->dev_id);
}

static int devm_irq_match(struct device *dev, void *res, void *data)
{
	struct irq_devres *this = res, *match = data;

	return this->irq == match->irq && this->dev_id == match->dev_id;
}

static int devm_request_result(struct device *dev, int rc, unsigned int irq,
			       irq_handler_t handler, irq_handler_t thread_fn,
			       const char *devname)
{
	if (rc >= 0)
		return rc;

	return dev_err_probe(dev, rc, "request_irq(%u) %ps %ps %s\n",
			     irq, handler, thread_fn, devname ? : "");
}

static int __devm_request_threaded_irq(struct device *dev, unsigned int irq,
				       irq_handler_t handler,
				       irq_handler_t thread_fn,
				       unsigned long irqflags,
				       const char *devname, void *dev_id)
{
	struct irq_devres *dr;
	int rc;

	dr = devres_alloc(devm_irq_release, sizeof(struct irq_devres),
			  GFP_KERNEL);
	if (!dr)
		return -ENOMEM;

	if (!devname)
		devname = dev_name(dev);

	rc = request_threaded_irq(irq, handler, thread_fn, irqflags, devname,
				  dev_id);
	if (rc) {
		devres_free(dr);
		return rc;
	}

	dr->irq = irq;
	dr->dev_id = dev_id;
	devres_add(dev, dr);

	return 0;
}

/**
 * devm_request_threaded_irq - allocate an interrupt line for a managed device with error logging
 * @dev:	Device to request interrupt for
 * @irq:	Interrupt line to allocate
 * @handler:	Function to be called when the interrupt occurs
 * @thread_fn:	Function to be called in a threaded interrupt context. NULL
 *		for devices which handle everything in @handler
 * @irqflags:	Interrupt type flags
 * @devname:	An ascii name for the claiming device, dev_name(dev) if NULL
 * @dev_id:	A cookie passed back to the handler function
 *
 * Except for the extra @dev argument, this function takes the same
 * arguments and performs the same function as request_threaded_irq().
 * Interrupts requested with this function will be automatically freed on
 * driver detach.
 *
 * If an interrupt allocated with this function needs to be freed
 * separately, devm_free_irq() must be used.
 *
 * When the request fails, an error message is printed with contextual
 * information (device name, interrupt number, handler functions and
 * error code). Don't add extra error messages at the call sites.
 *
 * Return: 0 on success or a negative error number.
 */
int devm_request_threaded_irq(struct device *dev, unsigned int irq,
			      irq_handler_t handler, irq_handler_t thread_fn,
			      unsigned long irqflags, const char *devname,
			      void *dev_id)

Annotation

Implementation Notes