tree 65f6b03238819d4706325923fe8aa3c4c2aa1f15
parent 711c11b78d00c0652d38893c558a2bcca55d96d4
author Joern Engel <[EMAIL PROTECTED]> Mon, 07 Mar 2005 21:43:42 +0000
committer Thomas Gleixner <[EMAIL PROTECTED]> Mon, 23 May 2005 12:51:00 +0200

[MTD] phram: Allow short reads.

Jffs2 apparently needs this.
Accept newline at the end of input.

Signed-off-by: Joern Engel <[EMAIL PROTECTED]>
Signed-off-by: Thomas Gleixner <[EMAIL PROTECTED]>

 drivers/mtd/devices/phram.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -1,5 +1,5 @@
 /**
- * $Id: phram.c,v 1.12 2005/02/23 19:37:07 joern Exp $
+ * $Id: phram.c,v 1.14 2005/03/07 21:43:38 joern Exp $
  *
  * Copyright (c) ????          Jochen Sch�uble <[EMAIL PROTECTED]>
  * Copyright (c) 2003-2004     J�rn Engel <[EMAIL PROTECTED]>
@@ -15,9 +15,7 @@
  *
  * Example:
  *     phram=swap,64Mi,128Mi phram=test,900Mi,1Mi
- *
  */
-
 #include <asm/io.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -36,7 +34,6 @@ struct phram_mtd_list {
 static LIST_HEAD(phram_list);
 
 
-
 static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
        u_char *start = mtd->priv;
@@ -71,7 +68,8 @@ static int phram_point(struct mtd_info *
        return 0;
 }
 
-static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from, 
size_t len)
+static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from,
+               size_t len)
 {
 }
 
@@ -80,8 +78,11 @@ static int phram_read(struct mtd_info *m
 {
        u_char *start = mtd->priv;
 
-       if (from + len > mtd->size)
+       if (from >= mtd->size)
                return -EINVAL;
+
+       if (len > mtd->size - from)
+               len = mtd->size - from;
        
        memcpy(buf, start + from, len);
 
@@ -94,8 +95,11 @@ static int phram_write(struct mtd_info *
 {
        u_char *start = mtd->priv;
 
-       if (to + len > mtd->size)
+       if (to >= mtd->size)
                return -EINVAL;
+
+       if (len > mtd->size - to)
+               len = mtd->size - to;
        
        memcpy(start + to, buf, len);
 
@@ -145,7 +149,7 @@ static int register_device(char *name, u
        new->mtd.write = phram_write;
        new->mtd.owner = THIS_MODULE;
        new->mtd.type = MTD_RAM;
-       new->mtd.erasesize = 0;
+       new->mtd.erasesize = PAGE_SIZE;
 
        ret = -EAGAIN;
        if (add_mtd_device(&new->mtd)) {
@@ -214,6 +218,15 @@ static int parse_name(char **pname, cons
        return 0;
 }
 
+
+static inline void kill_final_newline(char *str)
+{
+       char *newline = strrchr(str, '\n');
+       if (newline && !newline[1])
+               *newline = 0;
+}
+
+
 #define parse_err(fmt, args...) do {   \
        ERROR(fmt , ## args);   \
        return 0;               \
@@ -232,6 +245,7 @@ static int phram_setup(const char *val, 
                parse_err("parameter too long\n");
 
        strcpy(str, val);
+       kill_final_newline(str);
 
        for (i=0; i<3; i++)
                token[i] = strsep(&str, ",");
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to