mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: <linux-kernel@vger.kernel.org>
Cc: Frank Seidel <fseidel@suse.de>
Subject: [RFC 9/13] Char: nozomi, lock cleanup
Date: Fri, 9 Nov 2007 18:48:53 -0500	[thread overview]
Message-ID: <25311158751454229887.slaby@pripojeni.net> (raw)
In-Reply-To: <10551261882075921134.slaby@pripojeni.net>

nozomi, lock cleanup

- semaphore is deprecated, use mutex instead
- don't return -ERESTARTSYS when signal might not be pending since it's not
  permitted (unknown retval mioght reach userspace)
- don't lock interruptible in close or the card might not be stopped on last
  close

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit 19a0196a97ed70efdc421b359e28684e058d7121
tree 1c65691920ac6efddc7d9e221ee302a0b32b2831
parent d0b01ce89a7b18ba37ea6192eea6a98cdc01d62e
author Jiri Slaby <jirislaby@gmail.com> Mon, 05 Nov 2007 13:53:39 +0100
committer Jiri Slaby <jirislaby@gmail.com> Sat, 10 Nov 2007 00:13:46 +0100

 drivers/char/nozomi.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index 4a3ab38..2c4d388 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -406,7 +406,7 @@ struct port {
 
 	struct tty_struct *tty;
 	int tty_open_count;
-	struct semaphore tty_sem;
+	struct mutex tty_sem;
 	wait_queue_head_t tty_wait;
 	struct async_icount tty_icount;
 };
@@ -1560,7 +1560,7 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
 	dc->index_start = ndev_idx * NOZOMI_MAX_PORTS;
 	ndevs[ndev_idx] = dc;
 	for (i = 0; i < NOZOMI_MAX_PORTS; i++) {
-		init_MUTEX(&dc->port[i].tty_sem);
+		mutex_init(&dc->port[i].tty_sem);
 		dc->port[i].tty_open_count = 0;
 		dc->port[i].tty = NULL;
 		tty_register_device(ntty_driver, dc->index_start + i,
@@ -1687,7 +1687,7 @@ static int ntty_open(struct tty_struct *tty, struct file *file)
 	if (!port || !dc)
 		return -ENODEV;
 
-	if (down_interruptible(&port->tty_sem))
+	if (mutex_lock_interruptible(&port->tty_sem))
 		return -ERESTARTSYS;
 
 	port->tty_open_count++;
@@ -1706,7 +1706,7 @@ static int ntty_open(struct tty_struct *tty, struct file *file)
 		spin_unlock_irqrestore(&dc->spin_mutex, flags);
 	}
 
-	up(&port->tty_sem);
+	mutex_unlock(&port->tty_sem);
 
 	return 0;
 }
@@ -1721,8 +1721,7 @@ static void ntty_close(struct tty_struct *tty, struct file *file)
 	if (!dc || !port)
 		return;
 
-	if (down_interruptible(&port->tty_sem))
-		return;
+	mutex_lock(&port->tty_sem);
 
 	if (!port->tty_open_count)
 		goto exit;
@@ -1739,7 +1738,7 @@ static void ntty_close(struct tty_struct *tty, struct file *file)
 	}
 
 exit:
-	up(&port->tty_sem);
+	mutex_unlock(&port->tty_sem);
 }
 
 /*
@@ -1759,14 +1758,14 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
 	if (!dc || !port)
 		return -ENODEV;
 
-	if (unlikely(down_trylock(&port->tty_sem))) {
+	if (unlikely(mutex_trylock(&port->tty_sem))) {
 		/*
 		 * must test lock as tty layer wraps calls
 		 * to this function with BKL
 		 */
 		dev_err(&dc->pdev->dev, "Would have deadlocked - "
-			"return ERESTARTSYS\n");
-		return -ERESTARTSYS;
+			"return EAGAIN\n");
+		return -EAGAIN;
 	}
 
 	if (unlikely(!port->tty_open_count)) {
@@ -1798,7 +1797,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
 	spin_unlock_irqrestore(&dc->spin_mutex, flags);
 
 exit:
-	up(&port->tty_sem);
+	mutex_unlock(&port->tty_sem);
 	return rval;
 }
 
@@ -1816,7 +1815,7 @@ static int ntty_write_room(struct tty_struct *tty)
 
 	if (!dc || !port)
 		return 0;
-	if (down_trylock(&port->tty_sem))
+	if (mutex_trylock(&port->tty_sem))
 		return 0;
 
 	if (!port->tty_open_count)
@@ -1825,7 +1824,7 @@ static int ntty_write_room(struct tty_struct *tty)
 	room = port->fifo_ul->size - __kfifo_len(port->fifo_ul);
 
 exit:
-	up(&port->tty_sem);
+	mutex_unlock(&port->tty_sem);
 	return room;
 }
 

  parent reply	other threads:[~2007-11-09 23:49 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-09 23:43 [RFC 1/13] Char: nozomi, remove unneded stuff Jiri Slaby
2007-11-09 23:44 ` [RFC 2/13] Char: nozomi, expand some functions Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-09 23:44 ` [RFC 3/13] Char: nozomi, fix fail paths Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-09 23:45 ` [RFC 4/13] Char: nozomi, tty index cleanup Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-10 15:50     ` Jiri Slaby
2007-11-09 23:46 ` [RFC 5/13] Char: nozomi, ioctls cleanup Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-09 23:46 ` [RFC 6/13] Char: nozomi, reorder and cleanup probe, remove Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-09 23:47 ` [RFC 7/13] Char: nozomi, remove struct irq Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-12 15:11   ` Frank Seidel
2007-11-09 23:48 ` [RFC 8/13] Char: nozomi, tty cleanup Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-12 18:43   ` Frank Seidel
2007-11-09 23:48 ` Jiri Slaby [this message]
2007-11-10 15:42   ` [RFC 9/13] Char: nozomi, lock cleanup Frank Seidel
2007-11-09 23:49 ` [RFC! 10/13] Char: nozomi, fix tty_flip_buffer_push Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:50 ` [RFC 11/13] Char: nozomi, remove unused includes Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:50 ` [RFC 12/13] Char: nozomi, remove void acc char2 char3 more mp mp.c mp.yy m1 nozomi2 proto rej slock1 casts Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:51 ` [RFC 13/13] Char: nozomi, cleanup read and write Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-10 16:15   ` Adrian Bunk
2007-11-10 22:04     ` Jiri Slaby
2007-11-11  2:37       ` Frank Seidel
2007-11-11 16:02         ` Frank Seidel
2007-11-12  7:54       ` Adrian Bunk
2007-11-12  9:43         ` Frank Seidel
2007-11-10 15:41 ` [RFC 1/13] Char: nozomi, remove unneded stuff Frank Seidel
2007-11-10 15:55   ` Jiri Slaby

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=25311158751454229887.slaby@pripojeni.net \
    --to=jirislaby@gmail.com \
    --cc=fseidel@suse.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®