Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.6.15 /drivers/mtd/mtdchar.c

Filename:/drivers/mtd/mtdchar.c
Lines Added:44
Lines Deleted:45
Also changed in: (Previous) 2.6.15-rc7  2.6.15-rc6  2.6.15-rc5  2.6.15-rc4  2.6.15-rc3  2.6.15-rc2 
(Following) 2.6.17-git2  2.6.17-git3  2.6.17-git4  2.6.17-git5  2.6.17-git6  2.6.17-git7 

Location
[  2.6.15
  [  drivers
    [  mtd
       o  mtdchar.c

Patch

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 1ed602a..6f04458 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1,21 +1,23 @@
 /*
- * $Id: mtdchar.c,v 1.73 2005/07/04 17:36:41 gleixner Exp $
+ * $Id: mtdchar.c,v 1.76 2005/11/07 11:14:20 gleixner Exp $
  *
  * Character-device access to raw MTD devices.
  *
  */
 
 #include <linux/config.h>
+#include <linux/device.h>
+#include <linux/fs.h>
+#include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/compatmac.h>
-#include <linux/slab.h>
-#include <linux/init.h>
-#include <linux/fs.h>
-#include <asm/uaccess.h>
 
-#include <linux/device.h>
+#include <asm/uaccess.h>
 
 static struct class *mtd_class;
 
@@ -24,10 +26,10 @@ static void mtd_notify_add(struct mtd_in
    if (!mtd)
       return;
 
-   class_device_create(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
+   class_device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
              NULL, "mtd%d", mtd->index);
-   
-   class_device_create(mtd_class, 
+
+   class_device_create(mtd_class, NULL,
              MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
              NULL, "mtd%dro", mtd->index);
 }
@@ -69,26 +71,23 @@ static loff_t mtd_lseek (struct file *fi
    switch (orig) {
    case 0:
       /* SEEK_SET */
-      file->f_pos = offset;
       break;
    case 1:
       /* SEEK_CUR */
-      file->f_pos += offset;
+      offset += file->f_pos;
       break;
    case 2:
       /* SEEK_END */
-      file->f_pos =mtd->size + offset;
+      offset += mtd->size;
       break;
    default:
       return -EINVAL;
    }
 
-   if (file->f_pos < 0)
-      file->f_pos = 0;
-   else if (file->f_pos >= mtd->size)
-      file->f_pos = mtd->size - 1;
+   if (offset >= 0 && offset < mtd->size)
+      return file->f_pos = offset;
 
-   return file->f_pos;
+   return -EINVAL;
 }
 
 
@@ -109,23 +108,23 @@ static int mtd_open(struct inode *inode,
       return -EACCES;
 
    mtd = get_mtd_device(NULL, devnum);
-   
+
    if (!mtd)
       return -ENODEV;
-   
+
    if (MTD_ABSENT == mtd->type) {
       put_mtd_device(mtd);
       return -ENODEV;
    }
 
    file->private_data = mtd;
-      
+
    /* You can't open it RW if it's not a writeable device */
    if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) {
       put_mtd_device(mtd);
       return -EACCES;
    }
-      
+
    return 0;
 } /* mtd_open */
 
@@ -138,10 +137,10 @@ static int mtd_close(struct inode *inode
    DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n");
 
    mtd = TO_MTD(file);
-   
+
    if (mtd->sync)
       mtd->sync(mtd);
-   
+
    put_mtd_device(mtd);
 
    return 0;
@@ -160,7 +159,7 @@ static ssize_t mtd_read(struct file *fil
    int ret=0;
    int len;
    char *kbuf;
-   
+
    DEBUG(MTD_DEBUG_LEVEL0,"MTD_read\n");
 
    if (*ppos + count > mtd->size)
@@ -168,11 +167,11 @@ static ssize_t mtd_read(struct file *fil
 
    if (!count)
       return 0;
-   
+
    /* FIXME: Use kiovec in 2.5 to lock down the user's buffers
       and pass them directly to the MTD functions */
    while (count) {
-      if (count > MAX_KMALLOC_SIZE) 
+      if (count > MAX_KMALLOC_SIZE)
          len = MAX_KMALLOC_SIZE;
       else
          len = count;
@@ -180,7 +179,7 @@ static ssize_t mtd_read(struct file *fil
       kbuf=kmalloc(len,GFP_KERNEL);
       if (!kbuf)
          return -ENOMEM;
-      
+
       switch (MTD_MODE(file)) {
       case MTD_MODE_OTP_FACT:
          ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf);
@@ -193,7 +192,7 @@ static ssize_t mtd_read(struct file *fil
       }
       /* Nand returns -EBADMSG on ecc errors, but it returns
        * the data. For our userspace tools it is important
-       * to dump areas with ecc errors ! 
+       * to dump areas with ecc errors !
        * Userspace software which accesses NAND this way
        * must be aware of the fact that it deals with NAND
        */
@@ -215,7 +214,7 @@ static ssize_t mtd_read(struct file *fil
          kfree(kbuf);
          return ret;
       }
-      
+
       kfree(kbuf);
    }
 
@@ -232,10 +231,10 @@ static ssize_t mtd_write(struct file *fi
    int len;
 
    DEBUG(MTD_DEBUG_LEVEL0,"MTD_write\n");
-   
+
    if (*ppos == mtd->size)
       return -ENOSPC;
-   
+
    if (*ppos + count > mtd->size)
       count = mtd->size - *ppos;
 
@@ -243,7 +242,7 @@ static ssize_t mtd_write(struct file *fi
       return 0;
 
    while (count) {
-      if (count > MAX_KMALLOC_SIZE) 
+      if (count > MAX_KMALLOC_SIZE)
          len = MAX_KMALLOC_SIZE;
       else
          len = count;
@@ -258,7 +257,7 @@ static ssize_t mtd_write(struct file *fi
          kfree(kbuf);
          return -EFAULT;
       }
-      
+
       switch (MTD_MODE(file)) {
       case MTD_MODE_OTP_FACT:
          ret = -EROFS;
@@ -283,7 +282,7 @@ static ssize_t mtd_write(struct file *fi
          kfree(kbuf);
          return ret;
       }
-      
+
       kfree(kbuf);
    }
 
@@ -307,7 +306,7 @@ static int mtd_ioctl(struct inode *inode
    void __user *argp = (void __user *)arg;
    int ret = 0;
    u_long size;
-   
+
    DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
 
    size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
@@ -319,7 +318,7 @@ static int mtd_ioctl(struct inode *inode
       if (!access_ok(VERIFY_WRITE, argp, size))
          return -EFAULT;
    }
-   
+
    switch (cmd) {
    case MEMGETREGIONCOUNT:
       if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int)))
@@ -371,11 +370,11 @@ static int mtd_ioctl(struct inode *inode
          erase->mtd = mtd;
          erase->callback = mtdchar_erase_callback;
          erase->priv = (unsigned long)&waitq;
-         
+
          /*
            FIXME: Allow INTERRUPTIBLE. Which means
            not having the wait_queue head on the stack.
-           
+
            If the wq_head is on the stack, and we
            leave because we got interrupted, then the
            wq_head is no longer there when the
@@ -403,13 +402,13 @@ static int mtd_ioctl(struct inode *inode
       struct mtd_oob_buf buf;
       void *databuf;
       ssize_t retlen;
-      
+
       if(!(file->f_mode & 2))
          return -EPERM;
 
       if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
          return -EFAULT;
-      
+
       if (buf.length > 0x4096)
          return -EINVAL;
 
@@ -425,7 +424,7 @@ static int mtd_ioctl(struct inode *inode
       databuf = kmalloc(buf.length, GFP_KERNEL);
       if (!databuf)
          return -ENOMEM;
-      
+
       if (copy_from_user(databuf, buf.ptr, buf.length)) {
          kfree(databuf);
          return -EFAULT;
@@ -449,7 +448,7 @@ static int mtd_ioctl(struct inode *inode
 
       if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
          return -EFAULT;
-      
+
       if (buf.length > 0x4096)
          return -EINVAL;
 
@@ -465,14 +464,14 @@ static int mtd_ioctl(struct inode *inode
       databuf = kmalloc(buf.length, GFP_KERNEL);
       if (!databuf)
          return -ENOMEM;
-      
+
       ret = (mtd->read_oob)(mtd, buf.start, buf.length, &retlen, databuf);
 
       if (put_user(retlen, (uint32_t __user *)argp))
          ret = -EFAULT;
       else if (retlen && copy_to_user(buf.ptr, databuf, retlen))
          ret = -EFAULT;
-      
+
       kfree(databuf);
       break;
    }
@@ -522,7 +521,7 @@ static int mtd_ioctl(struct inode *inode
    case MEMGETBADBLOCK:
    {
       loff_t offs;
-      
+
       if (copy_from_user(&offs, argp, sizeof(loff_t)))
          return -EFAULT;
       if (!mtd->block_isbad)


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.