[adm5120] swap I/O space if running in big-endian mode
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.23 / 060-block2mtd_init.patch
1 --- a/drivers/mtd/devices/block2mtd.c
2 +++ b/drivers/mtd/devices/block2mtd.c
3 @@ -16,6 +16,7 @@
4 #include <linux/list.h>
5 #include <linux/init.h>
6 #include <linux/mtd/mtd.h>
7 +#include <linux/mtd/partitions.h>
8 #include <linux/buffer_head.h>
9 #include <linux/mutex.h>
10 #include <linux/mount.h>
11 @@ -237,10 +238,11 @@
12
13
14 /* FIXME: ensure that mtd->size % erase_size == 0 */
15 -static struct block2mtd_dev *add_device(char *devname, int erase_size)
16 +static struct block2mtd_dev *add_device(char *devname, int erase_size, char *mtdname)
17 {
18 struct block_device *bdev;
19 struct block2mtd_dev *dev;
20 + struct mtd_partition *part;
21
22 if (!devname)
23 return NULL;
24 @@ -279,14 +281,18 @@
25
26 /* Setup the MTD structure */
27 /* make the name contain the block device in */
28 - dev->mtd.name = kmalloc(sizeof("block2mtd: ") + strlen(devname),
29 - GFP_KERNEL);
30 +
31 + if (!mtdname)
32 + mtdname = devname;
33 +
34 + dev->mtd.name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
35 +
36 if (!dev->mtd.name)
37 goto devinit_err;
38 +
39 + strcpy(dev->mtd.name, mtdname);
40
41 - sprintf(dev->mtd.name, "block2mtd: %s", devname);
42 -
43 - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
44 + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
45 dev->mtd.erasesize = erase_size;
46 dev->mtd.writesize = 1;
47 dev->mtd.type = MTD_RAM;
48 @@ -298,15 +304,18 @@
49 dev->mtd.read = block2mtd_read;
50 dev->mtd.priv = dev;
51 dev->mtd.owner = THIS_MODULE;
52 -
53 - if (add_mtd_device(&dev->mtd)) {
54 +
55 + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
56 + part->name = dev->mtd.name;
57 + part->offset = 0;
58 + part->size = dev->mtd.size;
59 + if (add_mtd_partitions(&dev->mtd, part, 1)) {
60 /* Device didnt get added, so free the entry */
61 goto devinit_err;
62 }
63 list_add(&dev->list, &blkmtd_device_list);
64 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
65 - dev->mtd.name + strlen("blkmtd: "),
66 - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
67 + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
68 return dev;
69
70 devinit_err:
71 @@ -379,9 +388,9 @@
72
73 static int block2mtd_setup2(const char *val)
74 {
75 - char buf[80 + 12]; /* 80 for device, 12 for erase size */
76 + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
77 char *str = buf;
78 - char *token[2];
79 + char *token[3];
80 char *name;
81 size_t erase_size = PAGE_SIZE;
82 int i, ret;
83 @@ -392,7 +401,7 @@
84 strcpy(str, val);
85 kill_final_newline(str);
86
87 - for (i = 0; i < 2; i++)
88 + for (i = 0; i < 3; i++)
89 token[i] = strsep(&str, ",");
90
91 if (str)
92 @@ -412,8 +421,10 @@
93 parse_err("illegal erase size");
94 }
95 }
96 + if (token[2] && (strlen(token[2]) + 1 > 80))
97 + parse_err("mtd device name too long");
98
99 - add_device(name, erase_size);
100 + add_device(name, erase_size, token[2]);
101
102 return 0;
103 }
104 @@ -447,7 +458,7 @@
105
106
107 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
108 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
109 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
110
111 static int __init block2mtd_init(void)
112 {
This page took 0.047495 seconds and 5 git commands to generate.