Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92ad8f37 authored by Artem Bityutskiy's avatar Artem Bityutskiy
Browse files

UBI: use vmalloc for large buffers



UBI allocates temporary buffers of PEB size, which may be 256KiB.
Use vmalloc instead of kmalloc for such big temporary buffers.

Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 79b510c0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -650,7 +650,7 @@ static void detach_mtd_dev(struct ubi_device *ubi)
	uif_close(ubi);
	ubi_eba_close(ubi);
	ubi_wl_close(ubi);
	kfree(ubi->vtbl);
	vfree(ubi->vtbl);
	put_mtd_device(ubi->mtd);
	kfree(ubi_devices[ubi_num]);
	ubi_devices[ubi_num] = NULL;
+5 −5
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file)
		ubi_warn("update of volume %d not finished, volume is damaged",
			 vol->vol_id);
		vol->updating = 0;
		kfree(vol->upd_buf);
		vfree(vol->upd_buf);
	}

	ubi_close_volume(desc);
@@ -232,7 +232,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 = kmalloc(tbuf_size, GFP_KERNEL);
	tbuf = vmalloc(tbuf_size);
	if (!tbuf)
		return -ENOMEM;

@@ -271,7 +271,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);

	kfree(tbuf);
	vfree(tbuf);
	return err ? err : count_save - count;
}

@@ -320,7 +320,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 = kmalloc(tbuf_size, GFP_KERNEL);
	tbuf = vmalloc(tbuf_size);
	if (!tbuf)
		return -ENOMEM;

@@ -355,7 +355,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
		len = count > tbuf_size ? tbuf_size : count;
	}

	kfree(tbuf);
	vfree(tbuf);
	return err ? err : count_save - count;
}

+11 −11
Original line number Diff line number Diff line
@@ -524,7 +524,7 @@ static int recover_peb(struct ubi_device *ubi, int pnum, int vol_id, int lnum,
		goto write_error;

	data_size = offset + len;
	new_buf = kmalloc(data_size, GFP_KERNEL);
	new_buf = vmalloc(data_size);
	if (!new_buf) {
		err = -ENOMEM;
		goto out_put;
@@ -535,7 +535,7 @@ static int recover_peb(struct ubi_device *ubi, int pnum, int vol_id, int lnum,
	if (offset > 0) {
		err = ubi_io_read_data(ubi, new_buf, pnum, 0, offset);
		if (err && err != UBI_IO_BITFLIPS) {
			kfree(new_buf);
			vfree(new_buf);
			goto out_put;
		}
	}
@@ -544,11 +544,11 @@ static int recover_peb(struct ubi_device *ubi, int pnum, int vol_id, int lnum,

	err = ubi_io_write_data(ubi, new_buf, new_pnum, 0, data_size);
	if (err) {
		kfree(new_buf);
		vfree(new_buf);
		goto write_error;
	}

	kfree(new_buf);
	vfree(new_buf);
	ubi_free_vid_hdr(ubi, vid_hdr);

	vol->eba_tbl[lnum] = new_pnum;
@@ -977,7 +977,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
		data_size = aldata_size =
			    ubi->leb_size - ubi32_to_cpu(vid_hdr->data_pad);

	buf = kmalloc(aldata_size, GFP_KERNEL);
	buf = vmalloc(aldata_size);
	if (!buf)
		return -ENOMEM;

@@ -987,7 +987,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
	 */
	err = leb_write_lock(ubi, vol_id, lnum);
	if (err) {
		kfree(buf);
		vfree(buf);
		return err;
	}

@@ -1082,7 +1082,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
		 * We've written the data and are going to read it back to make
		 * sure it was written correctly.
		 */
		buf1 = kmalloc(aldata_size, GFP_KERNEL);
		buf1 = vmalloc(aldata_size);
		if (!buf1) {
			err = -ENOMEM;
			goto out_unlock;
@@ -1111,15 +1111,15 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
	vol->eba_tbl[lnum] = to;

	leb_write_unlock(ubi, vol_id, lnum);
	kfree(buf);
	kfree(buf1);
	vfree(buf);
	vfree(buf1);

	return 0;

out_unlock:
	leb_write_unlock(ubi, vol_id, lnum);
	kfree(buf);
	kfree(buf1);
	vfree(buf);
	vfree(buf1);
	return err;
}

+6 −5
Original line number Diff line number Diff line
@@ -382,7 +382,7 @@ static int torture_peb(const struct ubi_device *ubi, int pnum)
	void *buf;
	int err, i, patt_count;

	buf = kmalloc(ubi->peb_size, GFP_KERNEL);
	buf = vmalloc(ubi->peb_size);
	if (!buf)
		return -ENOMEM;

@@ -437,7 +437,7 @@ static int torture_peb(const struct ubi_device *ubi, int pnum)
		 * physical eraseblock which means something is wrong with it.
		 */
		err = -EIO;
	kfree(buf);
	vfree(buf);
	return err;
}

@@ -1224,9 +1224,10 @@ static int paranoid_check_all_ff(const struct ubi_device *ubi, int pnum,
	void *buf;
	loff_t addr = (loff_t)pnum * ubi->peb_size + offset;

	buf = kzalloc(len, GFP_KERNEL);
	buf = vmalloc(len);
	if (!buf)
		return -ENOMEM;
	memset(buf, 0, len);

	err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
	if (err && err != -EUCLEAN) {
@@ -1242,7 +1243,7 @@ static int paranoid_check_all_ff(const struct ubi_device *ubi, int pnum,
		goto fail;
	}

	kfree(buf);
	vfree(buf);
	return 0;

fail:
@@ -1252,7 +1253,7 @@ static int paranoid_check_all_ff(const struct ubi_device *ubi, int pnum,
	err = 1;
error:
	ubi_dbg_dump_stack();
	kfree(buf);
	vfree(buf);
	return err;
}

+2 −2
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ int ubi_check_volume(struct ubi_device *ubi, int vol_id)
	if (vol->vol_type != UBI_STATIC_VOLUME)
		return 0;

	buf = kmalloc(vol->usable_leb_size, GFP_KERNEL);
	buf = vmalloc(vol->usable_leb_size);
	if (!buf)
		return -ENOMEM;

@@ -87,7 +87,7 @@ int ubi_check_volume(struct ubi_device *ubi, int vol_id)
		}
	}

	kfree(buf);
	vfree(buf);
	return err;
}

Loading