Skip to contentSkip to conversation

Char: n_r3964, fix lock imbalance

PATCH New Jiri Slaby 1 participant 3 messages Jun 19, 2009 Char and misc drivers

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/3 Char: n_r3964, fix lock imbalance

There is omitted BKunL in r3964_read.

Centralize the paths to one point with one unlock.

---
 drivers/char/n_r3964.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)
drivers/char/n_r3964.c +14 -12
index d2e93e3..2e99158 100644
@@ -1062,7 +1062,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
 	struct r3964_client_info *pClient;
 	struct r3964_message *pMsg;
 	struct r3964_client_message theMsg;
-	int count;
+	int ret;
 
 	TRACE_L("read()");
 
@@ -1074,8 +1074,8 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
 		if (pMsg == NULL) {
 			/* no messages available. */
 			if (file->f_flags & O_NONBLOCK) {
-				unlock_kernel();
-				return -EAGAIN;
+				ret = -EAGAIN;
+				goto unlock;
 			}
 			/* block until there is a message: */
 			wait_event_interruptible(pInfo->read_wait,
@@ -1085,29 +1085,31 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
 		/* If we still haven't got a message, we must have been signalled */
 
 		if (!pMsg) {
-			unlock_kernel();
-			return -EINTR;
+			ret = -EINTR;
+			goto unlock;
 		}
 
 		/* deliver msg to client process: */
 		theMsg.msg_id = pMsg->msg_id;
 		theMsg.arg = pMsg->arg;
 		theMsg.error_code = pMsg->error_code;
-		count = sizeof(struct r3964_client_message);
+		ret = sizeof(struct r3964_client_message);
 
 		kfree(pMsg);
 		TRACE_M("r3964_read - msg kfree %p", pMsg);
 
-		if (copy_to_user(buf, &theMsg, count)) {
-			unlock_kernel();
-			return -EFAULT;
+		if (copy_to_user(buf, &theMsg, ret)) {
+			ret = -EFAULT;
+			goto unlock;
 		}
 
-		TRACE_PS("read - return %d", count);
-		return count;
+		TRACE_PS("read - return %d", ret);
+		goto unlock;
 	}
+	ret = -EPERM;
+unlock:
 	unlock_kernel();
-	return -EPERM;
+	return ret;
 }
 
 static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
Signature · 1 line
1.6.3.2
author
#1 lore raw

PATCH 2/3 Char: pcmcia/cm4000, fix lock imbalance

Don't return from switch/case, break instead, so that we unlock BKL.

---
 drivers/char/pcmcia/cm4000_cs.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/char/pcmcia/cm4000_cs.c +2 -1
index dbb9125..881934c 100644
@@ -1575,7 +1575,8 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		clear_bit(LOCK_IO, &dev->flags);
 		wake_up_interruptible(&dev->ioq);
 
-		return 0;
+		rc = 0;
+		break;
 	case CM_IOCSPTS:
 		{
 			struct ptsreq krnptsreq;
Signature · 1 line
1.6.3.2
author
#2 lore raw

PATCH 3/3 Char: vt_ioctl, fix lock imbalance

In reply to Jiri Slaby

Don't return from switch/case directly in vt_ioctl. Set ret and break instead so that we unlock BKL.

---
 drivers/char/vt_ioctl.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/char/vt_ioctl.c +2 -1
index e6ce632..7539bed 100644
@@ -396,7 +396,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
 	kbd = kbd_table + console;
 	switch (cmd) {
 	case TIOCLINUX:
-		return tioclinux(tty, arg);
+		ret = tioclinux(tty, arg);
+		break;
 	case KIOCSOUND:
 		if (!perm)
 			goto eperm;
Signature · 1 line
1.6.3.2