public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lcd: Push the BKL down into the driver ioctl handler
@ 2008-05-22 22:00 Alan Cox
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Cox @ 2008-05-22 22:00 UTC (permalink / raw)
  To: akpm, linux-kernel

Signed-off-by: Alan Cox <alan@redhat.com>

diff --git a/drivers/char/lcd.c b/drivers/char/lcd.c
index 4fe9206..1690cfb 100644
--- a/drivers/char/lcd.c
+++ b/drivers/char/lcd.c
@@ -21,15 +21,15 @@
 #include <linux/netdevice.h>
 #include <linux/sched.h>
 #include <linux/delay.h>
+#include <linux/smp_lock.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
 
-#include <asm/io.h>
-#include <asm/uaccess.h>
 #include <asm/system.h>
 
 #include "lcd.h"
 
-static int lcd_ioctl(struct inode *inode, struct file *file,
-		     unsigned int cmd, unsigned long arg);
+static long lcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
 
 static unsigned int lcd_present = 1;
 
@@ -54,11 +54,13 @@ int lcd_register_linkcheck_func(int iface_num, void *func, void *cookie)
 }
 #endif
 
-static int lcd_ioctl(struct inode *inode, struct file *file,
-		     unsigned int cmd, unsigned long arg)
+static long lcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	struct lcd_display button_display;
 	unsigned long address, a;
+	long ret = 0;
+
+	lock_kernel();
 
 	switch (cmd) {
 	case LCD_On:
@@ -135,7 +137,7 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_to_user
 			    ((struct lcd_display *) arg, &display,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
+				ret = -EFAULT;
 
 			break;
 		}
@@ -147,14 +149,13 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_from_user
 			    (&display, (struct lcd_display *) arg,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
-
-			a = (display.cursor_address | kLCD_Addr);
-
-			udelay(150);
-			BusyCheck();
-			LCDWriteInst(a);
-
+				ret = -EFAULT;
+			else {
+				a = (display.cursor_address | kLCD_Addr);
+				udelay(150);
+				BusyCheck();
+				LCDWriteInst(a);
+			}
 			break;
 		}
 
@@ -168,11 +169,12 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_to_user
 			    ((struct lcd_display *) arg, &display,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
-			udelay(150);
-			BusyCheck();
-			LCDWriteInst(0x10);
-
+				ret = -EFAULT;
+			else {
+				udelay(150);
+				BusyCheck();
+				LCDWriteInst(0x10);
+			}
 			break;
 		}
 
@@ -182,15 +184,15 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_from_user
 			    (&display, (struct lcd_display *) arg,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
-
-			udelay(150);
-			BusyCheck();
-			LCDWriteData(display.character);
-			udelay(150);
-			BusyCheck();
-			LCDWriteInst(0x10);
-
+				ret = -EFAULT;
+			else {
+				udelay(150);
+				BusyCheck();
+				LCDWriteData(display.character);
+				udelay(150);
+				BusyCheck();
+				LCDWriteInst(0x10);
+			}
 			break;
 		}
 
@@ -220,8 +222,10 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 
 			if (copy_from_user
 			    (&display, (struct lcd_display *) arg,
-			     sizeof(struct lcd_display)))
-				return -EFAULT;
+			     sizeof(struct lcd_display))) {
+				ret = -EFAULT;
+				break;
+			}
 
 			udelay(150);
 			BusyCheck();
@@ -287,7 +291,7 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_to_user
 			    ((struct lcd_display *) arg, &display,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
+				ret = -EFAULT;
 			break;
 		}
 
@@ -300,10 +304,11 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_from_user
 			    (&led_display, (struct lcd_display *) arg,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
-
-			led_state = led_display.leds;
-			LEDSet(led_state);
+				ret = -EFAULT;
+			else {
+				led_state = led_display.leds;
+				LEDSet(led_state);
+			}
 
 			break;
 		}
@@ -320,14 +325,15 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_from_user
 			    (&led_display, (struct lcd_display *) arg,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
-
-			for (i = 0; i < (int) led_display.leds; i++) {
-				bit = 2 * bit;
+				ret = -EFAULT;
+			else {
+				for (i = 0; i < (int) led_display.leds; i++) {
+					bit = 2 * bit;
+				}
+
+				led_state = led_state | bit;
+				LEDSet(led_state);
 			}
-
-			led_state = led_state | bit;
-			LEDSet(led_state);
 			break;
 		}
 
@@ -342,14 +348,15 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_from_user
 			    (&led_display, (struct lcd_display *) arg,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
-
-			for (i = 0; i < (int) led_display.leds; i++) {
-				bit = 2 * bit;
+				ret = -EFAULT;
+			else {
+				for (i = 0; i < (int) led_display.leds; i++) {
+					bit = 2 * bit;
+				}
+
+				led_state = led_state & ~bit;
+				LEDSet(led_state);
 			}
-
-			led_state = led_state & ~bit;
-			LEDSet(led_state);
 			break;
 		}
 
@@ -359,7 +366,7 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_to_user
 			    ((struct lcd_display *) arg, &button_display,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
+				ret = -EFAULT;
 			break;
 		}
 
@@ -369,7 +376,7 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (copy_to_user
 			    ((struct lcd_display *) arg, &button_display,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
+				ret = -EFAULT;
 			break;
 		}
 
@@ -382,8 +389,10 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			 */
 			if (copy_from_user
 			    (&button_display, (struct lcd_display *) arg,
-			     sizeof(button_display)))
-				return -EFAULT;
+			     sizeof(button_display))) {
+				ret = -EFAULT;
+				break;
+			}
 			iface_num = button_display.buttons;
 #if defined(CONFIG_TULIP) && 0
 			if (iface_num >= 0 &&
@@ -399,17 +408,15 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 			if (__copy_to_user
 			    ((struct lcd_display *) arg, &button_display,
 			     sizeof(struct lcd_display)))
-				return -EFAULT;
+				ret = -EFAULT;
 			break;
 		}
 
 	default:
-		return -EINVAL;
-
+		ret = -ENOTTY;
 	}
-
-	return 0;
-
+	lock_kernel();
+	return ret;
 }
 
 static int lcd_open(struct inode *inode, struct file *file)
@@ -462,7 +469,7 @@ static ssize_t lcd_read(struct file *file, char *buf,
 
 static const struct file_operations lcd_fops = {
 	.read = lcd_read,
-	.ioctl = lcd_ioctl,
+	.unlocked_ioctl = lcd_ioctl,
 	.open = lcd_open,
 };
 

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

* Re: [PATCH] lcd: Push the BKL down into the driver ioctl handler
@ 2008-05-23  9:06 Randolf Pohl
  2008-05-23 10:41 ` Alan Cox
  0 siblings, 1 reply; 3+ messages in thread
From: Randolf Pohl @ 2008-05-23  9:06 UTC (permalink / raw)
  To: linux-kernel


unlock_kernel() before return:

> Signed-off-by: Alan Cox <alan@redhat.com>
> 
> diff --git a/drivers/char/lcd.c b/drivers/char/lcd.c
> index 4fe9206..1690cfb 100644
> --- a/drivers/char/lcd.c
> +++ b/drivers/char/lcd.c

[...]

> @@ -399,17 +408,15 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
> 			if (__copy_to_user
> 			    ((struct lcd_display *) arg, &button_display,
> 			     sizeof(struct lcd_display)))
> -			      return -EFAULT;
> +			      ret = -EFAULT;
> 			break;
> 		}
>  
> 	default:
> -	      return -EINVAL;
> -
> +	      ret = -ENOTTY;
> 	}
> -
> -       return 0;
> -
> +       lock_kernel();

Shouldn't this be unlock_kernel();

> +       return ret;
>  }
>  
>  static int lcd_open(struct inode *inode, struct file *file)
> @@ -462,7 +469,7 @@ static ssize_t lcd_read(struct file *file, char *buf,
>  
>  static const struct file_operations lcd_fops = {
> 	.read = lcd_read,
> -       .ioctl = lcd_ioctl,
> +       .unlocked_ioctl = lcd_ioctl,
> 	.open = lcd_open,
>  };


Cheers,

R.
-- 
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx

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

* Re: [PATCH] lcd: Push the BKL down into the driver ioctl handler
  2008-05-23  9:06 [PATCH] lcd: Push the BKL down into the driver ioctl handler Randolf Pohl
@ 2008-05-23 10:41 ` Alan Cox
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Cox @ 2008-05-23 10:41 UTC (permalink / raw)
  To: Randolf Pohl; +Cc: linux-kernel

On Fri, 23 May 2008 11:06:16 +0200
"Randolf Pohl" <randolf.pohl@gmx.de> wrote:

> 
> unlock_kernel() before return:
> 
> > Signed-off-by: Alan Cox <alan@redhat.com>

Thanks and well spotted

Alan

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

end of thread, other threads:[~2008-05-23 10:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-23  9:06 [PATCH] lcd: Push the BKL down into the driver ioctl handler Randolf Pohl
2008-05-23 10:41 ` Alan Cox
  -- strict thread matches above, loose matches on Subject: below --
2008-05-22 22:00 Alan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox