MIPS: Yosemite, Emma: Fix off-by-two in arcs_cmdline buffer size check
[linux-2.6/linux-mips.git] / drivers / mtd / chips / map_absent.c
blobf2b87294687182abedba8ef30379fcd089e2827b
1 /*
2 * Common code to handle absent "placeholder" devices
3 * Copyright 2001 Resilience Corporation <ebrower@resilience.com>
5 * This map driver is used to allocate "placeholder" MTD
6 * devices on systems that have socketed/removable media.
7 * Use of this driver as a fallback preserves the expected
8 * registration of MTD device nodes regardless of probe outcome.
9 * A usage example is as follows:
11 * my_dev[i] = do_map_probe("cfi", &my_map[i]);
12 * if(NULL == my_dev[i]) {
13 * my_dev[i] = do_map_probe("map_absent", &my_map[i]);
14 * }
16 * Any device 'probed' with this driver will return -ENODEV
17 * upon open.
20 #include <linux/module.h>
21 #include <linux/types.h>
22 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/slab.h>
25 #include <linux/init.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/map.h>
29 static int map_absent_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
30 static int map_absent_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
31 static int map_absent_erase (struct mtd_info *, struct erase_info *);
32 static void map_absent_sync (struct mtd_info *);
33 static struct mtd_info *map_absent_probe(struct map_info *map);
34 static void map_absent_destroy (struct mtd_info *);
37 static struct mtd_chip_driver map_absent_chipdrv = {
38 .probe = map_absent_probe,
39 .destroy = map_absent_destroy,
40 .name = "map_absent",
41 .module = THIS_MODULE
44 static struct mtd_info *map_absent_probe(struct map_info *map)
46 struct mtd_info *mtd;
48 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
49 if (!mtd) {
50 return NULL;
53 map->fldrv = &map_absent_chipdrv;
54 mtd->priv = map;
55 mtd->name = map->name;
56 mtd->type = MTD_ABSENT;
57 mtd->size = map->size;
58 mtd->erase = map_absent_erase;
59 mtd->read = map_absent_read;
60 mtd->write = map_absent_write;
61 mtd->sync = map_absent_sync;
62 mtd->flags = 0;
63 mtd->erasesize = PAGE_SIZE;
64 mtd->writesize = 1;
66 __module_get(THIS_MODULE);
67 return mtd;
71 static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
73 *retlen = 0;
74 return -ENODEV;
77 static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
79 *retlen = 0;
80 return -ENODEV;
83 static int map_absent_erase(struct mtd_info *mtd, struct erase_info *instr)
85 return -ENODEV;
88 static void map_absent_sync(struct mtd_info *mtd)
90 /* nop */
93 static void map_absent_destroy(struct mtd_info *mtd)
95 /* nop */
98 static int __init map_absent_init(void)
100 register_mtd_chip_driver(&map_absent_chipdrv);
101 return 0;
104 static void __exit map_absent_exit(void)
106 unregister_mtd_chip_driver(&map_absent_chipdrv);
109 module_init(map_absent_init);
110 module_exit(map_absent_exit);
112 MODULE_LICENSE("GPL");
113 MODULE_AUTHOR("Resilience Corporation - Eric Brower <ebrower@resilience.com>");
114 MODULE_DESCRIPTION("Placeholder MTD chip driver for 'absent' chips");