aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/devices/phram.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/devices/phram.c')
-rw-r--r--drivers/mtd/devices/phram.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 5f8e164ddb71..a423a382095a 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * $Id: phram.c,v 1.11 2005/01/05 18:05:13 dwmw2 Exp $ 2 * $Id: phram.c,v 1.14 2005/03/07 21:43:38 joern Exp $
3 * 3 *
4 * Copyright (c) ???? Jochen Schäuble <psionic@psionic.de> 4 * Copyright (c) ???? Jochen Schäuble <psionic@psionic.de>
5 * Copyright (c) 2003-2004 Jörn Engel <joern@wh.fh-wedel.de> 5 * Copyright (c) 2003-2004 Jörn Engel <joern@wh.fh-wedel.de>
@@ -15,9 +15,7 @@
15 * 15 *
16 * Example: 16 * Example:
17 * phram=swap,64Mi,128Mi phram=test,900Mi,1Mi 17 * phram=swap,64Mi,128Mi phram=test,900Mi,1Mi
18 *
19 */ 18 */
20
21#include <asm/io.h> 19#include <asm/io.h>
22#include <linux/init.h> 20#include <linux/init.h>
23#include <linux/kernel.h> 21#include <linux/kernel.h>
@@ -36,7 +34,6 @@ struct phram_mtd_list {
36static LIST_HEAD(phram_list); 34static LIST_HEAD(phram_list);
37 35
38 36
39
40static int phram_erase(struct mtd_info *mtd, struct erase_info *instr) 37static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
41{ 38{
42 u_char *start = mtd->priv; 39 u_char *start = mtd->priv;
@@ -71,7 +68,8 @@ static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
71 return 0; 68 return 0;
72} 69}
73 70
74static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from, size_t len) 71static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from,
72 size_t len)
75{ 73{
76} 74}
77 75
@@ -80,8 +78,11 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len,
80{ 78{
81 u_char *start = mtd->priv; 79 u_char *start = mtd->priv;
82 80
83 if (from + len > mtd->size) 81 if (from >= mtd->size)
84 return -EINVAL; 82 return -EINVAL;
83
84 if (len > mtd->size - from)
85 len = mtd->size - from;
85 86
86 memcpy(buf, start + from, len); 87 memcpy(buf, start + from, len);
87 88
@@ -94,8 +95,11 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
94{ 95{
95 u_char *start = mtd->priv; 96 u_char *start = mtd->priv;
96 97
97 if (to + len > mtd->size) 98 if (to >= mtd->size)
98 return -EINVAL; 99 return -EINVAL;
100
101 if (len > mtd->size - to)
102 len = mtd->size - to;
99 103
100 memcpy(start + to, buf, len); 104 memcpy(start + to, buf, len);
101 105
@@ -107,9 +111,9 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
107 111
108static void unregister_devices(void) 112static void unregister_devices(void)
109{ 113{
110 struct phram_mtd_list *this; 114 struct phram_mtd_list *this, *safe;
111 115
112 list_for_each_entry(this, &phram_list, list) { 116 list_for_each_entry_safe(this, safe, &phram_list, list) {
113 del_mtd_device(&this->mtd); 117 del_mtd_device(&this->mtd);
114 iounmap(this->mtd.priv); 118 iounmap(this->mtd.priv);
115 kfree(this); 119 kfree(this);
@@ -145,7 +149,7 @@ static int register_device(char *name, unsigned long start, unsigned long len)
145 new->mtd.write = phram_write; 149 new->mtd.write = phram_write;
146 new->mtd.owner = THIS_MODULE; 150 new->mtd.owner = THIS_MODULE;
147 new->mtd.type = MTD_RAM; 151 new->mtd.type = MTD_RAM;
148 new->mtd.erasesize = 0; 152 new->mtd.erasesize = PAGE_SIZE;
149 153
150 ret = -EAGAIN; 154 ret = -EAGAIN;
151 if (add_mtd_device(&new->mtd)) { 155 if (add_mtd_device(&new->mtd)) {
@@ -214,6 +218,15 @@ static int parse_name(char **pname, const char *token)
214 return 0; 218 return 0;
215} 219}
216 220
221
222static inline void kill_final_newline(char *str)
223{
224 char *newline = strrchr(str, '\n');
225 if (newline && !newline[1])
226 *newline = 0;
227}
228
229
217#define parse_err(fmt, args...) do { \ 230#define parse_err(fmt, args...) do { \
218 ERROR(fmt , ## args); \ 231 ERROR(fmt , ## args); \
219 return 0; \ 232 return 0; \
@@ -232,6 +245,7 @@ static int phram_setup(const char *val, struct kernel_param *kp)
232 parse_err("parameter too long\n"); 245 parse_err("parameter too long\n");
233 246
234 strcpy(str, val); 247 strcpy(str, val);
248 kill_final_newline(str);
235 249
236 for (i=0; i<3; i++) 250 for (i=0; i<3; i++)
237 token[i] = strsep(&str, ","); 251 token[i] = strsep(&str, ",");