public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] use mutex instead of semaphore in RocketPort driver v2
@ 2007-04-25 13:08 Matthias Kaehlcke
  2007-04-25 13:54 ` Jiri Slaby
  2007-04-25 13:58 ` Jiri Slaby
  0 siblings, 2 replies; 4+ messages in thread
From: Matthias Kaehlcke @ 2007-04-25 13:08 UTC (permalink / raw)
  To: linux-kernel

the RocketPort driver uses a semaphore as mutex. use the mutex API
instead of the (binary) semaphore

Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>

--

diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 76357c8..7d23790 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -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,8 @@ static int rp_write(struct tty_struct *tty,
 	if (count <= 0 || rocket_paranoia_check(info, "rp_write"))
 		return 0;
 
-	down_interruptible(&info->write_sem);
+	if(mutex_lock_interruptible(&info->write_mtx))
+		return -EINTR;
 
 #ifdef ROCKET_DEBUG_WRITE
 	printk(KERN_INFO "rp_write %d chars...", count);
@@ -1777,7 +1778,7 @@ end:
 		wake_up_interruptible(&tty->poll_wait);
 #endif
 	}
-	up(&info->write_sem);
+	mutex_unlock(&info->write_mtx);
 	return retval;
 }
 
diff --git a/drivers/char/rocket_int.h b/drivers/char/rocket_int.h
index 3a8bcc8..04bcf61 100644
--- a/drivers/char/rocket_int.h
+++ b/drivers/char/rocket_int.h
@@ -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

-- 
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                  `-

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] use mutex instead of semaphore in RocketPort driver v2
  2007-04-25 13:08 [PATCH] use mutex instead of semaphore in RocketPort driver v2 Matthias Kaehlcke
@ 2007-04-25 13:54 ` Jiri Slaby
  2007-04-25 14:06   ` Matthias Kaehlcke
  2007-04-25 13:58 ` Jiri Slaby
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Slaby @ 2007-04-25 13:54 UTC (permalink / raw)
  To: Matthias Kaehlcke, linux-kernel

Matthias Kaehlcke napsal(a):
> the RocketPort driver uses a semaphore as mutex. use the mutex API
> instead of the (binary) semaphore
> 
> Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
> 
> --
> 
> diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
> index 76357c8..7d23790 100644
> --- a/drivers/char/rocket.c
> +++ b/drivers/char/rocket.c
> @@ -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,8 @@ static int rp_write(struct tty_struct *tty,
>  	if (count <= 0 || rocket_paranoia_check(info, "rp_write"))
>  		return 0;
>  
> -	down_interruptible(&info->write_sem);
> +	if(mutex_lock_interruptible(&info->write_mtx))
> +		return -EINTR;

I think that ERESTARTSYS is appropriate here.

reagrds,
-- 
http://www.fi.muni.cz/~xslaby/            Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
 B674 9967 0407 CE62 ACC8  22A0 32CC 55C3 39D4 7A7E

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] use mutex instead of semaphore in RocketPort driver v2
  2007-04-25 13:08 [PATCH] use mutex instead of semaphore in RocketPort driver v2 Matthias Kaehlcke
  2007-04-25 13:54 ` Jiri Slaby
@ 2007-04-25 13:58 ` Jiri Slaby
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2007-04-25 13:58 UTC (permalink / raw)
  To: Matthias Kaehlcke, linux-kernel

Matthias Kaehlcke napsal(a):
> the RocketPort driver uses a semaphore as mutex. use the mutex API
> instead of the (binary) semaphore
> 
> Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
> 
> --
> 
> diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
> index 76357c8..7d23790 100644
> --- a/drivers/char/rocket.c
> +++ b/drivers/char/rocket.c
> @@ -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,8 @@ static int rp_write(struct tty_struct *tty,
>  	if (count <= 0 || rocket_paranoia_check(info, "rp_write"))
>  		return 0;
>  
> -	down_interruptible(&info->write_sem);
> +	if(mutex_lock_interruptible(&info->write_mtx))
          ^
and put a space here "if (".

regards,
-- 
http://www.fi.muni.cz/~xslaby/            Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
 B674 9967 0407 CE62 ACC8  22A0 32CC 55C3 39D4 7A7E

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] use mutex instead of semaphore in RocketPort driver v2
  2007-04-25 13:54 ` Jiri Slaby
@ 2007-04-25 14:06   ` Matthias Kaehlcke
  0 siblings, 0 replies; 4+ messages in thread
From: Matthias Kaehlcke @ 2007-04-25 14:06 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-kernel

El Wed, Apr 25, 2007 at 03:54:36PM +0200 Jiri Slaby ha dit:

> Matthias Kaehlcke napsal(a):
> > the RocketPort driver uses a semaphore as mutex. use the mutex API
> > instead of the (binary) semaphore
> > 
> > Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
> > 
> 
> I think that ERESTARTSYS is appropriate here.

thanks for your remark, i'll take it into account

-- 
Matthias Kaehlcke
Linux Application Developer
Barcelona

            Nothing is more despicable than respect based on fear
                              (Albert Camus)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-04-25 14:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-25 13:08 [PATCH] use mutex instead of semaphore in RocketPort driver v2 Matthias Kaehlcke
2007-04-25 13:54 ` Jiri Slaby
2007-04-25 14:06   ` Matthias Kaehlcke
2007-04-25 13:58 ` Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox