All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fb: move mutex_init to framebuffer_alloc()
@ 2009-07-01 16:26 Daniel Mack
  2009-07-08  9:42 ` Wu Zhangjin
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Mack @ 2009-07-01 16:26 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: linux-kernel, Daniel Mack, Peter Zijlstra, Rafael J. Wysocki,
	stable, Andrew Morton

In 537a1bf05, a per-fbinfo mutex was added and framebuffer drivers were
adopted accordingly. This new lock is currently initialized in
register_framebuffer().

The mx3fb driver takes this lock in mx3fb_map_video_memory() _before_
register_framebuffer() is called and hence crashes the system very
early.

Moving this mutex_init() to framebuffer_alloc() solves this and also
seems a lot more straight forward.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc:: Krzysztof Helt <krzysztof.h1@wp.pl>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: <stable@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 drivers/video/fbmem.c   |    3 ---
 drivers/video/fbsysfs.c |    3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 53ea056..1d8d098 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -1513,9 +1513,6 @@ register_framebuffer(struct fb_info *fb_info)
 		if (!registered_fb[i])
 			break;
 	fb_info->node = i;
-	mutex_init(&fb_info->lock);
-	mutex_init(&fb_info->mm_lock);
-
 	fb_info->dev = device_create(fb_class, fb_info->device,
 				     MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
 	if (IS_ERR(fb_info->dev)) {
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index d4a2c11..60ddd1d 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -58,6 +58,9 @@ struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
 
 	info->device = dev;
 
+	mutex_init(&info->lock);
+	mutex_init(&info->mm_lock);
+
 #ifdef CONFIG_FB_BACKLIGHT
 	mutex_init(&info->bl_curve_mutex);
 #endif
-- 
1.6.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fb: move mutex_init to framebuffer_alloc()
  2009-07-01 16:26 [PATCH] fb: move mutex_init to framebuffer_alloc() Daniel Mack
@ 2009-07-08  9:42 ` Wu Zhangjin
  2009-07-08  9:52   ` Paul Mundt
  0 siblings, 1 reply; 3+ messages in thread
From: Wu Zhangjin @ 2009-07-08  9:42 UTC (permalink / raw)
  To: Daniel Mack
  Cc: linux-arm-kernel, linux-kernel, Peter Zijlstra, Rafael J. Wysocki,
	stable, Andrew Morton

On Wed, 2009-07-01 at 18:26 +0200, Daniel Mack wrote:
> In 537a1bf05, a per-fbinfo mutex was added and framebuffer drivers were
> adopted accordingly. This new lock is currently initialized in
> register_framebuffer().
> 
> The mx3fb driver takes this lock in mx3fb_map_video_memory() _before_
> register_framebuffer() is called and hence crashes the system very
> early.
> 
> Moving this mutex_init() to framebuffer_alloc() solves this and also
> seems a lot more straight forward.
> 

but this may introduce deadlock to some _old_ drivers which have not
used framebuffer_alloc to allocate fb_info structure.

to avoid deadlock, these drivers need to change kmalloc to
framebuffer_alloc, otherwise, they need to add their own mutexes
initialization source code:
		mutex_init(&info->lock);	mutex_init(&info->mm_lock);

here is only a record for the _old_ drivers' maintainers. hope they can
get this info from google or find this commit: 

commit 4148df9b0f38bdd362dd91d52076926c11cbe5a9
Author: Paul Mundt <lethal@linux-sh.org>
Date:   Mon Jul 6 00:25:57 2009 +0900

    fb: Initialize fb_info mutexes in framebuffer_alloc()
    
    This way they'll be properly initialized early enough for users that
may
    touch them before the framebuffer has been registered.
    
    Drivers that allocate their fb_info structure some other way (like
    matrocfb's broken static allocation) need to be fixed up
appropriately.
    
    Signed-off-by: Paul Mundt <lethal@linux-sh.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Regards,
Wu Zhangjin

> Signed-off-by: Daniel Mack <daniel@caiaq.de>
> Cc:: Krzysztof Helt <krzysztof.h1@wp.pl>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Rafael J. Wysocki <rjw@sisk.pl>
> Cc: <stable@kernel.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
>  drivers/video/fbmem.c   |    3 ---
>  drivers/video/fbsysfs.c |    3 +++
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
> index 53ea056..1d8d098 100644
> --- a/drivers/video/fbmem.c
> +++ b/drivers/video/fbmem.c
> @@ -1513,9 +1513,6 @@ register_framebuffer(struct fb_info *fb_info)
>  		if (!registered_fb[i])
>  			break;
>  	fb_info->node = i;
> -	mutex_init(&fb_info->lock);
> -	mutex_init(&fb_info->mm_lock);
> -
>  	fb_info->dev = device_create(fb_class, fb_info->device,
>  				     MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
>  	if (IS_ERR(fb_info->dev)) {
> diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
> index d4a2c11..60ddd1d 100644
> --- a/drivers/video/fbsysfs.c
> +++ b/drivers/video/fbsysfs.c
> @@ -58,6 +58,9 @@ struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
>  
>  	info->device = dev;
>  
> +	mutex_init(&info->lock);
> +	mutex_init(&info->mm_lock);
> +
>  #ifdef CONFIG_FB_BACKLIGHT
>  	mutex_init(&info->bl_curve_mutex);
>  #endif


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fb: move mutex_init to framebuffer_alloc()
  2009-07-08  9:42 ` Wu Zhangjin
@ 2009-07-08  9:52   ` Paul Mundt
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Mundt @ 2009-07-08  9:52 UTC (permalink / raw)
  To: Wu Zhangjin
  Cc: Daniel Mack, linux-arm-kernel, linux-kernel, Peter Zijlstra,
	Rafael J. Wysocki, stable, Andrew Morton

On Wed, Jul 08, 2009 at 05:42:25PM +0800, Wu Zhangjin wrote:
> On Wed, 2009-07-01 at 18:26 +0200, Daniel Mack wrote:
> > In 537a1bf05, a per-fbinfo mutex was added and framebuffer drivers were
> > adopted accordingly. This new lock is currently initialized in
> > register_framebuffer().
> > 
> > The mx3fb driver takes this lock in mx3fb_map_video_memory() _before_
> > register_framebuffer() is called and hence crashes the system very
> > early.
> > 
> > Moving this mutex_init() to framebuffer_alloc() solves this and also
> > seems a lot more straight forward.
> > 
> 
> but this may introduce deadlock to some _old_ drivers which have not
> used framebuffer_alloc to allocate fb_info structure.
> 
> to avoid deadlock, these drivers need to change kmalloc to
> framebuffer_alloc, otherwise, they need to add their own mutexes
> initialization source code:
> 		mutex_init(&info->lock);	mutex_init(&info->mm_lock);
> 
> here is only a record for the _old_ drivers' maintainers. hope they can
> get this info from google or find this commit: 
> 
Yes, I'm going through and gradually converting all of the outstanding
drivers (both old and new) over to framebuffer_alloc(). The old ones are
a bit more tedious given all of the casting games they play. I should
have the outstanding ones finished tomorrow.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-08  9:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-01 16:26 [PATCH] fb: move mutex_init to framebuffer_alloc() Daniel Mack
2009-07-08  9:42 ` Wu Zhangjin
2009-07-08  9:52   ` Paul Mundt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.