Merge tag 'v3.10.77' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / mtd / ubi / cdev.c
index 4f02848bb2bc5d843900d6762b10edec23e3dd84..e27779cfe95f0c1a98e8c7da6bab56a915b6ee1a 100644 (file)
@@ -138,13 +138,13 @@ static int vol_cdev_release(struct inode *inode, struct file *file)
                         vol->vol_id);
                ubi_assert(!vol->changing_leb);
                vol->updating = 0;
-               vfree(vol->upd_buf);
+               kfree(vol->upd_buf);
        } else if (vol->changing_leb) {
                dbg_gen("only %lld of %lld bytes received for atomic LEB change for volume %d:%d, cancel",
                        vol->upd_received, vol->upd_bytes, vol->ubi->ubi_num,
                        vol->vol_id);
                vol->changing_leb = 0;
-               vfree(vol->upd_buf);
+               kfree(vol->upd_buf);
        }
 
        ubi_close_volume(desc);
@@ -236,7 +236,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
        tbuf_size = vol->usable_leb_size;
        if (count < tbuf_size)
                tbuf_size = ALIGN(count, ubi->min_io_size);
-       tbuf = vmalloc(tbuf_size);
+       tbuf = kmalloc(tbuf_size, GFP_KERNEL);
        if (!tbuf)
                return -ENOMEM;
 
@@ -272,7 +272,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
                len = count > tbuf_size ? tbuf_size : count;
        } while (count);
 
-       vfree(tbuf);
+       kfree(tbuf);
        return err ? err : count_save - count;
 }
 
@@ -317,7 +317,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
        tbuf_size = vol->usable_leb_size;
        if (count < tbuf_size)
                tbuf_size = ALIGN(count, ubi->min_io_size);
-       tbuf = vmalloc(tbuf_size);
+       tbuf = kmalloc(tbuf_size, GFP_KERNEL);
        if (!tbuf)
                return -ENOMEM;
 
@@ -351,7 +351,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
                len = count > tbuf_size ? tbuf_size : count;
        }
 
-       vfree(tbuf);
+       kfree(tbuf);
        return err ? err : count_save - count;
 }
 
@@ -413,6 +413,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
        struct ubi_volume_desc *desc = file->private_data;
        struct ubi_volume *vol = desc->vol;
        struct ubi_device *ubi = vol->ubi;
+
        void __user *argp = (void __user *)arg;
 
        switch (cmd) {
@@ -420,7 +421,9 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
        case UBI_IOCVOLUP:
        {
                int64_t bytes, rsvd_bytes;
-
+        #if CONFIG_BLB
+        struct ubi_volume *backup_vol = ubi->volumes[vol_id2idx(ubi, UBI_BACKUP_VOLUME_ID)];
+        #endif
                if (!capable(CAP_SYS_RESOURCE)) {
                        err = -EPERM;
                        break;
@@ -451,6 +454,10 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
                err = ubi_start_update(ubi, vol, bytes);
                if (bytes == 0)
                        revoke_exclusive(desc, UBI_READWRITE);
+               #if CONFIG_BLB
+        ubi_eba_unmap_leb(ubi, backup_vol, 0);
+        ubi_eba_unmap_leb(ubi, backup_vol, 1);
+               #endif
                break;
        }
 
@@ -475,7 +482,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
                /* Validate the request */
                err = -EINVAL;
                if (req.lnum < 0 || req.lnum >= vol->reserved_pebs ||
-                   req.bytes < 0 || req.lnum >= vol->usable_leb_size)
+                   req.bytes < 0 || req.bytes > vol->usable_leb_size)
                        break;
 
                err = get_exclusive(desc);
@@ -543,7 +550,13 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
                        err = -EFAULT;
                        break;
                }
+#ifdef MTK_IPOH_SUPPORT
+               ubi->ipoh_ops = 1;
+#endif
                err = ubi_leb_unmap(desc, lnum);
+#ifdef MTK_IPOH_SUPPORT
+               ubi->ipoh_ops = 0;
+#endif
                break;
        }
 
@@ -584,7 +597,22 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
                }
                break;
        }
-
+       case UBI_IOCLBMAP:
+       {
+               int LEB[2];
+               err = copy_from_user(LEB, argp, sizeof(int)*2);
+                if (err) {
+                        err = -EFAULT;
+                        break;
+                }
+               LEB[1] = desc->vol->eba_tbl[LEB[0]];
+               err = copy_to_user(argp, LEB, sizeof(int)*2);
+                if (err) {
+                        err = -EFAULT;
+                        break;
+               }
+               break;
+       }
        default:
                err = -ENOTTY;
                break;