[PATCH] staging/msm: clearup read syscalls in kernel space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Description:
 1. use filp_open/vfs_read/filp_close instead of system calls
 2. fix double calling of sys_close when first sys_lseek fails
 3. reset segment fs when reading file into kernel space buffer


Signed-off-by: Xiaochen Wang <wangxiaochen0@xxxxxxxxx>
---
 drivers/staging/msm/logo.c |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/msm/logo.c b/drivers/staging/msm/logo.c
index 7272765..fe16e9f 100644
--- a/drivers/staging/msm/logo.c
+++ b/drivers/staging/msm/logo.c
@@ -19,7 +19,7 @@
 #include <linux/fb.h>
 #include <linux/vt_kern.h>
 #include <linux/unistd.h>
-#include <linux/syscalls.h>
+#include <linux/uaccess.h>
 
 #include <linux/irq.h>
 #include <asm/system.h>
@@ -40,9 +40,15 @@ static void memset16(void *_ptr, unsigned short val, unsigned count)
 int load_565rle_image(char *filename)
 {
 	struct fb_info *info;
-	int fd, err = 0;
+	struct file *filp;
+	int err = 0;
 	unsigned count, max;
 	unsigned short *data, *bits, *ptr;
+	mm_segment_t fs;
+	loff_t pos;
+
+	fs = get_fs();
+	set_fs(get_ds());
 
 	info = registered_fb[0];
 	if (!info) {
@@ -51,26 +57,26 @@ int load_565rle_image(char *filename)
 		return -ENODEV;
 	}
 
-	fd = sys_open(filename, O_RDONLY, 0);
-	if (fd < 0) {
+	filp = filp_open(filename, O_RDONLY, 0);
+	if (IS_ERR(filp)) {
 		printk(KERN_WARNING "%s: Can not open %s\n",
 			__func__, filename);
-		return -ENOENT;
+		err = PTR_ERR(filp);
+		goto err_logo_set_fs;
 	}
-	count = (unsigned)sys_lseek(fd, (off_t)0, 2);
+	count = (unsigned)i_size_read(filp->f_path.dentry->d_inode);
 	if (count == 0) {
-		sys_close(fd);
 		err = -EIO;
 		goto err_logo_close_file;
 	}
-	sys_lseek(fd, (off_t)0, 0);
 	data = kmalloc(count, GFP_KERNEL);
 	if (!data) {
 		printk(KERN_WARNING "%s: Can not alloc data\n", __func__);
 		err = -ENOMEM;
 		goto err_logo_close_file;
 	}
-	if ((unsigned)sys_read(fd, (char *)data, count) != count) {
+	pos = 0;
+	if (vfs_read(filp, (char __user *)data, count, &pos) != count) {
 		err = -EIO;
 		goto err_logo_free_data;
 	}
@@ -92,7 +98,9 @@ int load_565rle_image(char *filename)
 err_logo_free_data:
 	kfree(data);
 err_logo_close_file:
-	sys_close(fd);
+	filp_close(filp, current->files);
+err_logo_set_fs:
+	set_fs(fs);
 	return err;
 }
 EXPORT_SYMBOL(load_565rle_image);
-- 
1.7.2.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux