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

Commit 3e680aae authored by Krzysztof Helt's avatar Krzysztof Helt Committed by Linus Torvalds
Browse files

fb: convert lock/unlock_kernel() into local fb mutex



Change lock_kernel()/unlock_kernel() to local fb mutex.  Each frame buffer
instance has its own mutex.

The one line try_to_load() function is unrolled to request_module() in two
places for readability.

[righi.andrea@gmail.com: fb: fix NULL pointer BUG dereference in fb_open()]
Signed-off-by: default avatarKrzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: default avatarAndrea Righi <righi.andrea@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e5367711
Loading
Loading
Loading
Loading
+20 −19
Original line number Original line Diff line number Diff line
@@ -1018,12 +1018,12 @@ fb_ioctl(struct file *file, unsigned int cmd,
	void __user *argp = (void __user *)arg;
	void __user *argp = (void __user *)arg;
	long ret = 0;
	long ret = 0;


	lock_kernel();
	info = registered_fb[fbidx];
	info = registered_fb[fbidx];
	mutex_lock(&info->lock);
	fb = info->fbops;
	fb = info->fbops;


	if (!fb) {
	if (!fb) {
		unlock_kernel();
		mutex_unlock(&info->lock);
		return -ENODEV;
		return -ENODEV;
	}
	}
	switch (cmd) {
	switch (cmd) {
@@ -1126,7 +1126,7 @@ fb_ioctl(struct file *file, unsigned int cmd,
		else
		else
			ret = fb->fb_ioctl(info, cmd, arg);
			ret = fb->fb_ioctl(info, cmd, arg);
	}
	}
	unlock_kernel();
	mutex_unlock(&info->lock);
	return ret;
	return ret;
}
}


@@ -1253,7 +1253,7 @@ fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
	struct fb_ops *fb = info->fbops;
	struct fb_ops *fb = info->fbops;
	long ret = -ENOIOCTLCMD;
	long ret = -ENOIOCTLCMD;


	lock_kernel();
	mutex_lock(&info->lock);
	switch(cmd) {
	switch(cmd) {
	case FBIOGET_VSCREENINFO:
	case FBIOGET_VSCREENINFO:
	case FBIOPUT_VSCREENINFO:
	case FBIOPUT_VSCREENINFO:
@@ -1279,7 +1279,7 @@ fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
			ret = fb->fb_compat_ioctl(info, cmd, arg);
			ret = fb->fb_compat_ioctl(info, cmd, arg);
		break;
		break;
	}
	}
	unlock_kernel();
	mutex_unlock(&info->lock);
	return ret;
	return ret;
}
}
#endif
#endif
@@ -1301,13 +1301,13 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
		return -ENODEV;
		return -ENODEV;
	if (fb->fb_mmap) {
	if (fb->fb_mmap) {
		int res;
		int res;
		lock_kernel();
		mutex_lock(&info->lock);
		res = fb->fb_mmap(info, vma);
		res = fb->fb_mmap(info, vma);
		unlock_kernel();
		mutex_unlock(&info->lock);
		return res;
		return res;
	}
	}


	lock_kernel();
	mutex_lock(&info->lock);


	/* frame buffer memory */
	/* frame buffer memory */
	start = info->fix.smem_start;
	start = info->fix.smem_start;
@@ -1316,13 +1316,13 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
		/* memory mapped io */
		/* memory mapped io */
		off -= len;
		off -= len;
		if (info->var.accel_flags) {
		if (info->var.accel_flags) {
			unlock_kernel();
			mutex_unlock(&info->lock);
			return -EINVAL;
			return -EINVAL;
		}
		}
		start = info->fix.mmio_start;
		start = info->fix.mmio_start;
		len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
		len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
	}
	}
	unlock_kernel();
	mutex_unlock(&info->lock);
	start &= PAGE_MASK;
	start &= PAGE_MASK;
	if ((vma->vm_end - vma->vm_start + off) > len)
	if ((vma->vm_end - vma->vm_start + off) > len)
		return -EINVAL;
		return -EINVAL;
@@ -1346,13 +1346,13 @@ fb_open(struct inode *inode, struct file *file)


	if (fbidx >= FB_MAX)
	if (fbidx >= FB_MAX)
		return -ENODEV;
		return -ENODEV;
	lock_kernel();
	info = registered_fb[fbidx];
	if (!(info = registered_fb[fbidx]))
	if (!info)
		request_module("fb%d", fbidx);
		request_module("fb%d", fbidx);
	if (!(info = registered_fb[fbidx])) {
	info = registered_fb[fbidx];
		res = -ENODEV;
	if (!info)
		goto out;
		return -ENODEV;
	}
	mutex_lock(&info->lock);
	if (!try_module_get(info->fbops->owner)) {
	if (!try_module_get(info->fbops->owner)) {
		res = -ENODEV;
		res = -ENODEV;
		goto out;
		goto out;
@@ -1368,7 +1368,7 @@ fb_open(struct inode *inode, struct file *file)
		fb_deferred_io_open(info, inode, file);
		fb_deferred_io_open(info, inode, file);
#endif
#endif
out:
out:
	unlock_kernel();
	mutex_unlock(&info->lock);
	return res;
	return res;
}
}


@@ -1377,11 +1377,11 @@ fb_release(struct inode *inode, struct file *file)
{
{
	struct fb_info * const info = file->private_data;
	struct fb_info * const info = file->private_data;


	lock_kernel();
	mutex_lock(&info->lock);
	if (info->fbops->fb_release)
	if (info->fbops->fb_release)
		info->fbops->fb_release(info,1);
		info->fbops->fb_release(info,1);
	module_put(info->fbops->owner);
	module_put(info->fbops->owner);
	unlock_kernel();
	mutex_unlock(&info->lock);
	return 0;
	return 0;
}
}


@@ -1460,6 +1460,7 @@ register_framebuffer(struct fb_info *fb_info)
		if (!registered_fb[i])
		if (!registered_fb[i])
			break;
			break;
	fb_info->node = i;
	fb_info->node = i;
	mutex_init(&fb_info->lock);


	fb_info->dev = device_create(fb_class, fb_info->device,
	fb_info->dev = device_create(fb_class, fb_info->device,
				     MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
				     MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
+1 −0
Original line number Original line Diff line number Diff line
@@ -808,6 +808,7 @@ struct fb_tile_ops {
struct fb_info {
struct fb_info {
	int node;
	int node;
	int flags;
	int flags;
	struct mutex lock;		/* Lock for open/release/ioctl funcs */
	struct fb_var_screeninfo var;	/* Current var */
	struct fb_var_screeninfo var;	/* Current var */
	struct fb_fix_screeninfo fix;	/* Current fix */
	struct fb_fix_screeninfo fix;	/* Current fix */
	struct fb_monspecs monspecs;	/* Current Monitor specs */
	struct fb_monspecs monspecs;	/* Current Monitor specs */