]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/mtd/mtdchar.c
Merge tag 'kvmarm-for-v4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm...
[linux.git] / drivers / mtd / mtdchar.c
index cd67c85cc87de460b63c2f912f515aca1dc3e14e..02389528f622d819431fe24b0277031b214dd702 100644 (file)
@@ -160,8 +160,12 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count,
 
        pr_debug("MTD_read\n");
 
-       if (*ppos + count > mtd->size)
-               count = mtd->size - *ppos;
+       if (*ppos + count > mtd->size) {
+               if (*ppos < mtd->size)
+                       count = mtd->size - *ppos;
+               else
+                       count = 0;
+       }
 
        if (!count)
                return 0;
@@ -246,7 +250,7 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c
 
        pr_debug("MTD_write\n");
 
-       if (*ppos == mtd->size)
+       if (*ppos >= mtd->size)
                return -ENOSPC;
 
        if (*ppos + count > mtd->size)