All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: akpm@osdl.org, linux-kernel@vger.kernel.org
Subject: [PATCH] lcd: Push the BKL down into the driver ioctl handler
Date: Thu, 22 May 2008 23:00:34 +0100	[thread overview]
Message-ID: <20080522230034.2e6ca40a@core> (raw)

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,
 };
 

             reply	other threads:[~2008-05-22 22:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-22 22:00 Alan Cox [this message]
  -- strict thread matches above, loose matches on Subject: below --
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080522230034.2e6ca40a@core \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.