diff options
author | Josh Boyer <jdub@us.ibm.com> | 2005-01-06 16:16:45 -0500 |
---|---|---|
committer | Thomas Gleixner <tglx@mtd.linutronix.de> | 2005-05-23 05:16:56 -0400 |
commit | 14f8351a313f364afbc565f1ddcd43f8cfdccf52 (patch) | |
tree | d7c9833120901274c32a85d58b32d0f4f11aa5d2 /drivers/mtd/devices/slram.c | |
parent | 49a43876b935c811cfd29d8fe998a6912a1cc5c4 (diff) |
[MTD] slram driver cleanup
Add error checks to read/write functions and add an eraseblock size.
Makes slram a suitable device for JFFS2.
Signed-off-by: Josh Boyer <jdub@us.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/mtd/devices/slram.c')
-rw-r--r-- | drivers/mtd/devices/slram.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c index 5ab15e643be7..84fa91392a8c 100644 --- a/drivers/mtd/devices/slram.c +++ b/drivers/mtd/devices/slram.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /*====================================================================== | 1 | /*====================================================================== |
2 | 2 | ||
3 | $Id: slram.c,v 1.33 2005/01/05 18:05:13 dwmw2 Exp $ | 3 | $Id: slram.c,v 1.34 2005/01/06 21:16:42 jwboyer Exp $ |
4 | 4 | ||
5 | This driver provides a method to access memory not used by the kernel | 5 | This driver provides a method to access memory not used by the kernel |
6 | itself (i.e. if the kernel commandline mem=xxx is used). To actually | 6 | itself (i.e. if the kernel commandline mem=xxx is used). To actually |
@@ -50,6 +50,7 @@ | |||
50 | #include <linux/mtd/mtd.h> | 50 | #include <linux/mtd/mtd.h> |
51 | 51 | ||
52 | #define SLRAM_MAX_DEVICES_PARAMS 6 /* 3 parameters / device */ | 52 | #define SLRAM_MAX_DEVICES_PARAMS 6 /* 3 parameters / device */ |
53 | #define SLRAM_BLK_SZ 0x4000 | ||
53 | 54 | ||
54 | #define T(fmt, args...) printk(KERN_DEBUG fmt, ## args) | 55 | #define T(fmt, args...) printk(KERN_DEBUG fmt, ## args) |
55 | #define E(fmt, args...) printk(KERN_NOTICE fmt, ## args) | 56 | #define E(fmt, args...) printk(KERN_NOTICE fmt, ## args) |
@@ -108,6 +109,9 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len, | |||
108 | { | 109 | { |
109 | slram_priv_t *priv = mtd->priv; | 110 | slram_priv_t *priv = mtd->priv; |
110 | 111 | ||
112 | if (from + len > mtd->size) | ||
113 | return -EINVAL; | ||
114 | |||
111 | *mtdbuf = priv->start + from; | 115 | *mtdbuf = priv->start + from; |
112 | *retlen = len; | 116 | *retlen = len; |
113 | return(0); | 117 | return(0); |
@@ -121,7 +125,13 @@ static int slram_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
121 | size_t *retlen, u_char *buf) | 125 | size_t *retlen, u_char *buf) |
122 | { | 126 | { |
123 | slram_priv_t *priv = mtd->priv; | 127 | slram_priv_t *priv = mtd->priv; |
124 | 128 | ||
129 | if (from > mtd->size) | ||
130 | return -EINVAL; | ||
131 | |||
132 | if (from + len > mtd->size) | ||
133 | len = mtd->size - from; | ||
134 | |||
125 | memcpy(buf, priv->start + from, len); | 135 | memcpy(buf, priv->start + from, len); |
126 | 136 | ||
127 | *retlen = len; | 137 | *retlen = len; |
@@ -133,6 +143,9 @@ static int slram_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
133 | { | 143 | { |
134 | slram_priv_t *priv = mtd->priv; | 144 | slram_priv_t *priv = mtd->priv; |
135 | 145 | ||
146 | if (to + len > mtd->size) | ||
147 | return -EINVAL; | ||
148 | |||
136 | memcpy(priv->start + to, buf, len); | 149 | memcpy(priv->start + to, buf, len); |
137 | 150 | ||
138 | *retlen = len; | 151 | *retlen = len; |
@@ -188,7 +201,7 @@ static int register_device(char *name, unsigned long start, unsigned long length | |||
188 | (*curmtd)->mtdinfo->name = name; | 201 | (*curmtd)->mtdinfo->name = name; |
189 | (*curmtd)->mtdinfo->size = length; | 202 | (*curmtd)->mtdinfo->size = length; |
190 | (*curmtd)->mtdinfo->flags = MTD_CLEAR_BITS | MTD_SET_BITS | | 203 | (*curmtd)->mtdinfo->flags = MTD_CLEAR_BITS | MTD_SET_BITS | |
191 | MTD_WRITEB_WRITEABLE | MTD_VOLATILE; | 204 | MTD_WRITEB_WRITEABLE | MTD_VOLATILE | MTD_CAP_RAM; |
192 | (*curmtd)->mtdinfo->erase = slram_erase; | 205 | (*curmtd)->mtdinfo->erase = slram_erase; |
193 | (*curmtd)->mtdinfo->point = slram_point; | 206 | (*curmtd)->mtdinfo->point = slram_point; |
194 | (*curmtd)->mtdinfo->unpoint = slram_unpoint; | 207 | (*curmtd)->mtdinfo->unpoint = slram_unpoint; |
@@ -196,7 +209,7 @@ static int register_device(char *name, unsigned long start, unsigned long length | |||
196 | (*curmtd)->mtdinfo->write = slram_write; | 209 | (*curmtd)->mtdinfo->write = slram_write; |
197 | (*curmtd)->mtdinfo->owner = THIS_MODULE; | 210 | (*curmtd)->mtdinfo->owner = THIS_MODULE; |
198 | (*curmtd)->mtdinfo->type = MTD_RAM; | 211 | (*curmtd)->mtdinfo->type = MTD_RAM; |
199 | (*curmtd)->mtdinfo->erasesize = 0x0; | 212 | (*curmtd)->mtdinfo->erasesize = SLRAM_BLK_SZ; |
200 | 213 | ||
201 | if (add_mtd_device((*curmtd)->mtdinfo)) { | 214 | if (add_mtd_device((*curmtd)->mtdinfo)) { |
202 | E("slram: Failed to register new device\n"); | 215 | E("slram: Failed to register new device\n"); |
@@ -261,7 +274,7 @@ static int parse_cmdline(char *devname, char *szstart, char *szlength) | |||
261 | } | 274 | } |
262 | T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n", | 275 | T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n", |
263 | devname, devstart, devlength); | 276 | devname, devstart, devlength); |
264 | if ((devstart < 0) || (devlength < 0)) { | 277 | if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) { |
265 | E("slram: Illegal start / length parameter.\n"); | 278 | E("slram: Illegal start / length parameter.\n"); |
266 | return(-EINVAL); | 279 | return(-EINVAL); |
267 | } | 280 | } |