Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
devres.c
Go to the documentation of this file.
1 #include <linux/module.h>
2 #include <linux/interrupt.h>
3 #include <linux/device.h>
4 #include <linux/gfp.h>
5 
6 /*
7  * Device resource management aware IRQ request/free implementation.
8  */
9 struct irq_devres {
10  unsigned int irq;
11  void *dev_id;
12 };
13 
14 static void devm_irq_release(struct device *dev, void *res)
15 {
16  struct irq_devres *this = res;
17 
18  free_irq(this->irq, this->dev_id);
19 }
20 
21 static int devm_irq_match(struct device *dev, void *res, void *data)
22 {
23  struct irq_devres *this = res, *match = data;
24 
25  return this->irq == match->irq && this->dev_id == match->dev_id;
26 }
27 
47 int devm_request_threaded_irq(struct device *dev, unsigned int irq,
48  irq_handler_t handler, irq_handler_t thread_fn,
49  unsigned long irqflags, const char *devname,
50  void *dev_id)
51 {
52  struct irq_devres *dr;
53  int rc;
54 
55  dr = devres_alloc(devm_irq_release, sizeof(struct irq_devres),
56  GFP_KERNEL);
57  if (!dr)
58  return -ENOMEM;
59 
60  rc = request_threaded_irq(irq, handler, thread_fn, irqflags, devname,
61  dev_id);
62  if (rc) {
63  devres_free(dr);
64  return rc;
65  }
66 
67  dr->irq = irq;
68  dr->dev_id = dev_id;
69  devres_add(dev, dr);
70 
71  return 0;
72 }
74 
86 void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id)
87 {
88  struct irq_devres match_data = { irq, dev_id };
89 
90  WARN_ON(devres_destroy(dev, devm_irq_release, devm_irq_match,
91  &match_data));
92  free_irq(irq, dev_id);
93 }