Re: [PATCH 1/2] Video: fb, add true ref_count atomicity

2007-02-08 Thread Denis Oliver Kropp

Jiri Slaby wrote:

video/fb, add true ref_count atomicity

Some of fb drivers uses atomic_t in bad manner, since there are still some
race-prone gaps. Use mutexes to protect open/close code sections with
ref_count testing and finally use simple uint.

Signed-off-by: Jiri Slaby <[EMAIL PROTECTED]>


Acked-by: Denis Oliver Kropp <[EMAIL PROTECTED]>

--
Best regards,
  Denis Oliver Kropp

.--.
| DirectFB - Hardware accelerated graphics |
| http://www.directfb.org/ |
'--'
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] Video: fb, add true ref_count atomicity

2007-02-08 Thread Denis Oliver Kropp

Jiri Slaby wrote:

video/fb, add true ref_count atomicity

Some of fb drivers uses atomic_t in bad manner, since there are still some
race-prone gaps. Use mutexes to protect open/close code sections with
ref_count testing and finally use simple uint.

Signed-off-by: Jiri Slaby [EMAIL PROTECTED]


Acked-by: Denis Oliver Kropp [EMAIL PROTECTED]

--
Best regards,
  Denis Oliver Kropp

.--.
| DirectFB - Hardware accelerated graphics |
| http://www.directfb.org/ |
'--'
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] Video: fb, add true ref_count atomicity

2007-02-07 Thread Jiri Slaby
video/fb, add true ref_count atomicity

Some of fb drivers uses atomic_t in bad manner, since there are still some
race-prone gaps. Use mutexes to protect open/close code sections with
ref_count testing and finally use simple uint.

Signed-off-by: Jiri Slaby <[EMAIL PROTECTED]>

---
commit fd6de4a65b2d83db766a9ad3c137c44e361d6e0d
tree a4573d343d20988b931313c5fa35d9c370f36a05
parent e8d5617886087b5c8eee9df2c73381495672e23c
author Jiri Slaby <[EMAIL PROTECTED]> Thu, 08 Feb 2007 01:39:50 +0100
committer Jiri Slaby <[EMAIL PROTECTED]> Thu, 08 Feb 2007 01:39:50 +0100

 drivers/video/i810/i810.h  |3 ++-
 drivers/video/i810/i810_main.c |   25 +++--
 drivers/video/neofb.c  |   21 ++---
 drivers/video/riva/fbdev.c |   19 ---
 drivers/video/riva/rivafb.h|3 ++-
 drivers/video/vga16fb.c|   23 +++
 include/video/neomagic.h   |3 ++-
 7 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/drivers/video/i810/i810.h b/drivers/video/i810/i810.h
index 579195c..aa65ffc 100644
--- a/drivers/video/i810/i810.h
+++ b/drivers/video/i810/i810.h
@@ -264,7 +264,8 @@ struct i810fb_par {
struct heap_data cursor_heap;
struct vgastate  state;
struct i810fb_i2c_chan   chan[3];
-   atomic_t use_count;
+   struct mutex open_lock;
+   unsigned int use_count;
u32 pseudo_palette[17];
unsigned long mmio_start_phys;
u8 __iomem *mmio_start_virtual;
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index b55a12d..e343c0d 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1235,9 +1235,9 @@ static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, 
u8 *blue,
 static int i810fb_open(struct fb_info *info, int user)
 {
struct i810fb_par *par = info->par;
-   u32 count = atomic_read(>use_count);
-   
-   if (count == 0) {
+
+   mutex_lock(>open_lock);
+   if (par->use_count == 0) {
memset(>state, 0, sizeof(struct vgastate));
par->state.flags = VGA_SAVE_CMAP;
par->state.vgabase = par->mmio_start_virtual;
@@ -1246,7 +1246,8 @@ static int i810fb_open(struct fb_info *info, int user)
i810_save_vga_state(par);
}
 
-   atomic_inc(>use_count);
+   par->use_count++;
+   mutex_unlock(>open_lock);

return 0;
 }
@@ -1254,18 +1255,20 @@ static int i810fb_open(struct fb_info *info, int user)
 static int i810fb_release(struct fb_info *info, int user)
 {
struct i810fb_par *par = info->par;
-   u32 count;
-   
-   count = atomic_read(>use_count);
-   if (count == 0)
+
+   mutex_lock(>open_lock);
+   if (par->use_count == 0) {
+   mutex_unlock(>open_lock);
return -EINVAL;
+   }
 
-   if (count == 1) {
+   if (par->use_count == 1) {
i810_restore_vga_state(par);
restore_vga(>state);
}
 
-   atomic_dec(>use_count);
+   par->use_count--;
+   mutex_unlock(>open_lock);

return 0;
 }
@@ -1752,6 +1755,8 @@ static void __devinit i810_init_monspecs(struct fb_info 
*info)
 static void __devinit i810_init_defaults(struct i810fb_par *par, 
  struct fb_info *info)
 {
+   mutex_init(>open_lock);
+
if (voffset) 
v_offset_default = voffset;
else if (par->aperture.size > 32 * 1024 * 1024)
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 459ca55..395cced 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -556,14 +556,16 @@ static int
 neofb_open(struct fb_info *info, int user)
 {
struct neofb_par *par = info->par;
-   int cnt = atomic_read(>ref_count);
 
-   if (!cnt) {
+   mutex_lock(>open_lock);
+   if (!par->ref_count) {
memset(>state, 0, sizeof(struct vgastate));
par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
save_vga(>state);
}
-   atomic_inc(>ref_count);
+   par->ref_count++;
+   mutex_unlock(>open_lock);
+
return 0;
 }
 
@@ -571,14 +573,18 @@ static int
 neofb_release(struct fb_info *info, int user)
 {
struct neofb_par *par = info->par;
-   int cnt = atomic_read(>ref_count);
 
-   if (!cnt)
+   mutex_lock(>open_lock);
+   if (!par->ref_count) {
+   mutex_unlock(>open_lock);
return -EINVAL;
-   if (cnt == 1) {
+   }
+   if (par->ref_count == 1) {
restore_vga(>state);
}
-   atomic_dec(>ref_count);
+   par->ref_count--;
+   mutex_unlock(>open_lock);
+
return 0;
 }
 
@@ -2047,6 +2053,7 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct 
pci_dev *dev, const st
 
info->fix.accel = id->driver_data;
 
+ 

[PATCH 1/2] Video: fb, add true ref_count atomicity

2007-02-07 Thread Jiri Slaby
video/fb, add true ref_count atomicity

Some of fb drivers uses atomic_t in bad manner, since there are still some
race-prone gaps. Use mutexes to protect open/close code sections with
ref_count testing and finally use simple uint.

Signed-off-by: Jiri Slaby [EMAIL PROTECTED]

---
commit fd6de4a65b2d83db766a9ad3c137c44e361d6e0d
tree a4573d343d20988b931313c5fa35d9c370f36a05
parent e8d5617886087b5c8eee9df2c73381495672e23c
author Jiri Slaby [EMAIL PROTECTED] Thu, 08 Feb 2007 01:39:50 +0100
committer Jiri Slaby [EMAIL PROTECTED] Thu, 08 Feb 2007 01:39:50 +0100

 drivers/video/i810/i810.h  |3 ++-
 drivers/video/i810/i810_main.c |   25 +++--
 drivers/video/neofb.c  |   21 ++---
 drivers/video/riva/fbdev.c |   19 ---
 drivers/video/riva/rivafb.h|3 ++-
 drivers/video/vga16fb.c|   23 +++
 include/video/neomagic.h   |3 ++-
 7 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/drivers/video/i810/i810.h b/drivers/video/i810/i810.h
index 579195c..aa65ffc 100644
--- a/drivers/video/i810/i810.h
+++ b/drivers/video/i810/i810.h
@@ -264,7 +264,8 @@ struct i810fb_par {
struct heap_data cursor_heap;
struct vgastate  state;
struct i810fb_i2c_chan   chan[3];
-   atomic_t use_count;
+   struct mutex open_lock;
+   unsigned int use_count;
u32 pseudo_palette[17];
unsigned long mmio_start_phys;
u8 __iomem *mmio_start_virtual;
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index b55a12d..e343c0d 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1235,9 +1235,9 @@ static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, 
u8 *blue,
 static int i810fb_open(struct fb_info *info, int user)
 {
struct i810fb_par *par = info-par;
-   u32 count = atomic_read(par-use_count);
-   
-   if (count == 0) {
+
+   mutex_lock(par-open_lock);
+   if (par-use_count == 0) {
memset(par-state, 0, sizeof(struct vgastate));
par-state.flags = VGA_SAVE_CMAP;
par-state.vgabase = par-mmio_start_virtual;
@@ -1246,7 +1246,8 @@ static int i810fb_open(struct fb_info *info, int user)
i810_save_vga_state(par);
}
 
-   atomic_inc(par-use_count);
+   par-use_count++;
+   mutex_unlock(par-open_lock);

return 0;
 }
@@ -1254,18 +1255,20 @@ static int i810fb_open(struct fb_info *info, int user)
 static int i810fb_release(struct fb_info *info, int user)
 {
struct i810fb_par *par = info-par;
-   u32 count;
-   
-   count = atomic_read(par-use_count);
-   if (count == 0)
+
+   mutex_lock(par-open_lock);
+   if (par-use_count == 0) {
+   mutex_unlock(par-open_lock);
return -EINVAL;
+   }
 
-   if (count == 1) {
+   if (par-use_count == 1) {
i810_restore_vga_state(par);
restore_vga(par-state);
}
 
-   atomic_dec(par-use_count);
+   par-use_count--;
+   mutex_unlock(par-open_lock);

return 0;
 }
@@ -1752,6 +1755,8 @@ static void __devinit i810_init_monspecs(struct fb_info 
*info)
 static void __devinit i810_init_defaults(struct i810fb_par *par, 
  struct fb_info *info)
 {
+   mutex_init(par-open_lock);
+
if (voffset) 
v_offset_default = voffset;
else if (par-aperture.size  32 * 1024 * 1024)
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 459ca55..395cced 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -556,14 +556,16 @@ static int
 neofb_open(struct fb_info *info, int user)
 {
struct neofb_par *par = info-par;
-   int cnt = atomic_read(par-ref_count);
 
-   if (!cnt) {
+   mutex_lock(par-open_lock);
+   if (!par-ref_count) {
memset(par-state, 0, sizeof(struct vgastate));
par-state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
save_vga(par-state);
}
-   atomic_inc(par-ref_count);
+   par-ref_count++;
+   mutex_unlock(par-open_lock);
+
return 0;
 }
 
@@ -571,14 +573,18 @@ static int
 neofb_release(struct fb_info *info, int user)
 {
struct neofb_par *par = info-par;
-   int cnt = atomic_read(par-ref_count);
 
-   if (!cnt)
+   mutex_lock(par-open_lock);
+   if (!par-ref_count) {
+   mutex_unlock(par-open_lock);
return -EINVAL;
-   if (cnt == 1) {
+   }
+   if (par-ref_count == 1) {
restore_vga(par-state);
}
-   atomic_dec(par-ref_count);
+   par-ref_count--;
+   mutex_unlock(par-open_lock);
+
return 0;
 }
 
@@ -2047,6 +2053,7 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct 
pci_dev *dev, const st