Branch data Line data Source code
1 : : /*
2 : : * Registration for chip drivers
3 : : *
4 : : */
5 : :
6 : : #include <linux/kernel.h>
7 : : #include <linux/module.h>
8 : : #include <linux/kmod.h>
9 : : #include <linux/spinlock.h>
10 : : #include <linux/slab.h>
11 : : #include <linux/mtd/map.h>
12 : : #include <linux/mtd/mtd.h>
13 : :
14 : : static DEFINE_SPINLOCK(chip_drvs_lock);
15 : : static LIST_HEAD(chip_drvs_list);
16 : :
17 : 0 : void register_mtd_chip_driver(struct mtd_chip_driver *drv)
18 : : {
19 : : spin_lock(&chip_drvs_lock);
20 : 0 : list_add(&drv->list, &chip_drvs_list);
21 : : spin_unlock(&chip_drvs_lock);
22 : 0 : }
23 : :
24 : 0 : void unregister_mtd_chip_driver(struct mtd_chip_driver *drv)
25 : : {
26 : : spin_lock(&chip_drvs_lock);
27 : : list_del(&drv->list);
28 : : spin_unlock(&chip_drvs_lock);
29 : 0 : }
30 : :
31 : 0 : static struct mtd_chip_driver *get_mtd_chip_driver (const char *name)
32 : : {
33 : : struct list_head *pos;
34 : : struct mtd_chip_driver *ret = NULL, *this;
35 : :
36 : : spin_lock(&chip_drvs_lock);
37 : :
38 [ # # ]: 0 : list_for_each(pos, &chip_drvs_list) {
39 : 0 : this = list_entry(pos, typeof(*this), list);
40 : :
41 [ # # ]: 0 : if (!strcmp(this->name, name)) {
42 : : ret = this;
43 : : break;
44 : : }
45 : : }
46 [ # # ][ # # ]: 0 : if (ret && !try_module_get(ret->module))
47 : : ret = NULL;
48 : :
49 : : spin_unlock(&chip_drvs_lock);
50 : :
51 : 0 : return ret;
52 : : }
53 : :
54 : : /* Hide all the horrid details, like some silly person taking
55 : : get_module_symbol() away from us, from the caller. */
56 : :
57 : 0 : struct mtd_info *do_map_probe(const char *name, struct map_info *map)
58 : : {
59 : : struct mtd_chip_driver *drv;
60 : : struct mtd_info *ret;
61 : :
62 : 0 : drv = get_mtd_chip_driver(name);
63 : :
64 [ # # ][ # # ]: 0 : if (!drv && !request_module("%s", name))
65 : 0 : drv = get_mtd_chip_driver(name);
66 : :
67 [ # # ]: 0 : if (!drv)
68 : : return NULL;
69 : :
70 : 0 : ret = drv->probe(map);
71 : :
72 : : /* We decrease the use count here. It may have been a
73 : : probe-only module, which is no longer required from this
74 : : point, having given us a handle on (and increased the use
75 : : count of) the actual driver code.
76 : : */
77 : 0 : module_put(drv->module);
78 : :
79 : 0 : return ret;
80 : : }
81 : : /*
82 : : * Destroy an MTD device which was created for a map device.
83 : : * Make sure the MTD device is already unregistered before calling this
84 : : */
85 : 0 : void map_destroy(struct mtd_info *mtd)
86 : : {
87 : 0 : struct map_info *map = mtd->priv;
88 : :
89 [ # # ]: 0 : if (map->fldrv->destroy)
90 : 0 : map->fldrv->destroy(mtd);
91 : :
92 : 0 : module_put(map->fldrv->module);
93 : :
94 : 0 : kfree(mtd);
95 : 0 : }
96 : :
97 : : EXPORT_SYMBOL(register_mtd_chip_driver);
98 : : EXPORT_SYMBOL(unregister_mtd_chip_driver);
99 : : EXPORT_SYMBOL(do_map_probe);
100 : : EXPORT_SYMBOL(map_destroy);
101 : :
102 : : MODULE_LICENSE("GPL");
103 : : MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
104 : : MODULE_DESCRIPTION("Core routines for registering and invoking MTD chip drivers");
|