use mutex instead of semaphore in RocketPort driver
PATCH 1/1 use mutex instead of semaphore in RocketPort driver
the RocketPort driver uses a semaphore as mutex. use the mutex API instead of the (binary) semaphore
--
drivers/char/rocket.c +5 -5
@@ -702,7 +702,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev) } }spin_lock_init (&info->slock); -sema_init (&info->write_sem,1 ); +mutex_init (&info->write_mtx); rp_table[line] = info;if (pci_dev)tty_register_device (rocket_driver, line, &pci_dev->dev);
@@ -1662,7 +1662,7 @@ static void rp_put_char(struct tty_struct *tty, unsigned char ch)return ;/* Grab the port write semaphore, locking out other processes that try to write to this port */ -down (&info->write_sem); +mutex_lock (&info->write_mtx);#ifdef ROCKET_DEBUG_WRITE printk (KERN_INFO "rp_put_char %c..." , ch);
@@ -1684,7 +1684,7 @@ static void rp_put_char(struct tty_struct *tty, unsigned char ch) info->xmit_fifo_room--; }spin_unlock_irqrestore (&info->slock, flags); -up (&info->write_sem); +mutex_unlock (&info->write_mtx); }/*
@@ -1706,7 +1706,7 @@ static int rp_write(struct tty_struct *tty,if (count <=0 ||rocket_paranoia_check (info,"rp_write" ))return 0 ; -down_interruptible (&info->write_sem); +mutex_lock_interruptible (&info->write_mtx);#ifdef ROCKET_DEBUG_WRITE printk (KERN_INFO "rp_write %d chars..." , count);
@@ -1777,7 +1777,7 @@ end:wake_up_interruptible (&tty->poll_wait);#endif } -up (&info->write_sem); +mutex_unlock (&info->write_mtx);return retval; }
drivers/char/rocket_int.h +1 -1
@@ -1171,7 +1171,7 @@ struct r_port {struct wait_queue *close_wait;#endif spinlock_t slock; -struct semaphore write_sem; +struct mutex write_mtx; };#define RPORT_MAGIC 0x525001
Signature · 12 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
Usually when people are sad, they don't do anything. They just cry over
their condition. But when they get angry, they bring about a change
(Malcolm X)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-Am Dienstag, 24. April 2007 19:49 schrieb Matthias Kaehlcke:
Quoted 6 lines
drivers/char/rocket.c +0
-0@@ -1706,7 +1706,7 @@ static int rp_write(struct tty_struct *tty, if (count <= 0 || rocket_paranoia_check(info, "rp_write")) return 0;
- down_interruptible(&info->write_sem); + mutex_lock_interruptible(&info->write_mtx);
This is a bug. It is also present in the current code, but nevertheless it is a bug. If you use an interruptible lock, you must be ready to deal with interrupts, which are ignored by this code.
Regards
Oliver
El Tue, Apr 24, 2007 at 07:53:04PM +0200 Oliver Neukum ha dit:
Quoted 11 lines
Am Dienstag, 24. April 2007 19:49 schrieb Matthias Kaehlcke:
Quoted 6 lines
drivers/char/rocket.c +0
-0@@ -1706,7 +1706,7 @@ static int rp_write(struct tty_struct *tty, if (count <= 0 || rocket_paranoia_check(info, "rp_write")) return 0;
- down_interruptible(&info->write_sem); + mutex_lock_interruptible(&info->write_mtx);This is a bug. It is also present in the current code, but nevertheless it is a bug. If you use an interruptible lock, you must be ready to deal with interrupts, which are ignored by this code.
i fear i don't have the experience/knowledge to fix this bug, thanks for your remark.
i'm a bit confused now about the interruptible locks, i thought using them means that the process will be waked up when receiving a signal. what role are playing interrupts when using interruptible locks?
Signature · 11 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
La libertad es como la mañana. Hay quienes esperan dormidos a que
llegue, pero hay quienes desvelan y caminan la noche para alcanzarla
(Subcomandante Marcos)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-