[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20080522230034.2e6ca40a@core>
Date: Thu, 22 May 2008 23:00:34 +0100
From: Alan Cox <alan@...rguk.ukuu.org.uk>
To: akpm@...l.org, linux-kernel@...r.kernel.org
Subject: [PATCH] lcd: Push the BKL down into the driver ioctl handler
Signed-off-by: Alan Cox <alan@...hat.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,
};
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists