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