Re: [PATCH] use mutex instead of binary semaphore in CDU-31A driver

2007-04-24 Thread Corey Minyard

This is fine with me; I don't see any problems in it and the mutex
is better.  However, I cannot test this as I have no hardware
left capable of hosting the drive.

-corey

Matthias Kaehlcke wrote:

use mutex instead of binary semaphore in CDU-31A driver

Signed-off-by: Matthias Kaehlcke <[EMAIL PROTECTED]>

--
diff --git a/drivers/cdrom/cdu31a.c b/drivers/cdrom/cdu31a.c
index 2157c58..d3649e4 100644
--- a/drivers/cdrom/cdu31a.c
+++ b/drivers/cdrom/cdu31a.c
@@ -263,7 +263,7 @@ static int sony_toc_read = 0;   /* Has the TOC been 
read for
 static struct s_sony_subcode last_sony_subcode;/* Points to the last
   subcode address read */
 
-static DECLARE_MUTEX(sony_sem);		/* Semaphore for drive hardware access */

+static DEFINE_MUTEX(sony_mtx); /* Mutex for drive hardware access */
 
 static int is_double_speed = 0;	/* does the drive support double speed ? */
 
@@ -339,11 +339,11 @@ static int scd_drive_status(struct cdrom_device_info *cdi, int slot_nr)

return -EINVAL;
if (sony_spun_up)
return CDS_DISC_OK;
-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
if (scd_spinup() == 0)
sony_spun_up = 1;
-   up(_sem);
+   mutex_unlock(_mtx);
return sony_spun_up ? CDS_DISC_OK : CDS_DRIVE_NOT_READY;
 }
 
@@ -452,7 +452,7 @@ static int scd_reset(struct cdrom_device_info *cdi)

 {
unsigned long retry_count;
 
-	if (down_interruptible(_sem))

+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
reset_drive();
 
@@ -461,7 +461,7 @@ static int scd_reset(struct cdrom_device_info *cdi)

sony_sleep();
}
 
-	up(_sem);

+   mutex_unlock(_mtx);
return 0;
 }
 
@@ -655,10 +655,10 @@ static int scd_select_speed(struct cdrom_device_info *cdi, int speed)

else
sony_speed = speed - 1;
 
-	if (down_interruptible(_sem))

+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
set_drive_params(sony_speed);
-   up(_sem);
+   mutex_unlock(_mtx);
return 0;
 }
 
@@ -673,10 +673,10 @@ static int scd_lock_door(struct cdrom_device_info *cdi, int lock)

} else {
is_auto_eject = 0;
}
-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
set_drive_params(sony_speed);
-   up(_sem);
+   mutex_unlock(_mtx);
return 0;
 }
 
@@ -1143,7 +1143,7 @@ static void handle_abort_timeout(unsigned long data)

 {
pr_debug(PFX "Entering %s\n", __FUNCTION__);
/* If it is in use, ignore it. */
-   if (down_trylock(_sem) == 0) {
+   if (mutex_trylock(_mtx) == 0) {
/* We can't use abort_read(), because it will sleep
   or schedule in the timer interrupt.  Just start
   the operation, finish it on the next access to
@@ -1154,7 +1154,7 @@ static void handle_abort_timeout(unsigned long data)
 
 		sony_blocks_left = 0;

abort_read_started = 1;
-   up(_sem);
+   mutex_unlock(_mtx);
}
pr_debug(PFX "Leaving %s\n", __FUNCTION__);
 }
@@ -1300,7 +1300,7 @@ static void do_cdu31a_request(request_queue_t * q)
pr_debug(PFX "Entering %s\n", __FUNCTION__);
 
 	spin_unlock_irq(q->queue_lock);

-   if (down_interruptible(_sem)) {
+   if (mutex_lock_interruptible(_mtx)) {
spin_lock_irq(q->queue_lock);
return;
}
@@ -1435,7 +1435,7 @@ static void do_cdu31a_request(request_queue_t * q)
add_timer(_abort_timer);
 #endif
 
-	up(_sem);

+   mutex_unlock(_mtx);
spin_lock_irq(q->queue_lock);
pr_debug(PFX "Leaving %s at %d\n", __FUNCTION__, __LINE__);
 }
@@ -1906,10 +1906,10 @@ static int scd_get_last_session(struct 
cdrom_device_info *cdi,
return 1;
 
 	if (!sony_toc_read) {

-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
sony_get_toc();
-   up(_sem);
+   mutex_unlock(_mtx);
}
 
 	ms_info->addr_format = CDROM_LBA;

@@ -1988,11 +1988,11 @@ scd_get_mcn(struct cdrom_device_info *cdi, struct 
cdrom_mcn *mcn)
unsigned int res_size;
 
 	memset(mcn->medium_catalog_number, 0, 14);

-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
do_sony_cd_cmd(SONY_REQ_UPC_EAN_CMD,
   NULL, 0, resbuffer, _size);
-   up(_sem);
+   mutex_unlock(_mtx);
if ((res_size < 2) || ((resbuffer[0] & 0xf0) == 0x20));
else {
/* packed bcd to single ASCII digits */
@@ -2207,7 +2207,7 @@ static int read_audio(struct cdrom_read_audio *ra)

Re: [PATCH] use mutex instead of binary semaphore in CDU-31A driver

2007-04-24 Thread Corey Minyard

This is fine with me; I don't see any problems in it and the mutex
is better.  However, I cannot test this as I have no hardware
left capable of hosting the drive.

-corey

Matthias Kaehlcke wrote:

use mutex instead of binary semaphore in CDU-31A driver

Signed-off-by: Matthias Kaehlcke [EMAIL PROTECTED]

--
diff --git a/drivers/cdrom/cdu31a.c b/drivers/cdrom/cdu31a.c
index 2157c58..d3649e4 100644
--- a/drivers/cdrom/cdu31a.c
+++ b/drivers/cdrom/cdu31a.c
@@ -263,7 +263,7 @@ static int sony_toc_read = 0;   /* Has the TOC been 
read for
 static struct s_sony_subcode last_sony_subcode;/* Points to the last
   subcode address read */
 
-static DECLARE_MUTEX(sony_sem);		/* Semaphore for drive hardware access */

+static DEFINE_MUTEX(sony_mtx); /* Mutex for drive hardware access */
 
 static int is_double_speed = 0;	/* does the drive support double speed ? */
 
@@ -339,11 +339,11 @@ static int scd_drive_status(struct cdrom_device_info *cdi, int slot_nr)

return -EINVAL;
if (sony_spun_up)
return CDS_DISC_OK;
-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
if (scd_spinup() == 0)
sony_spun_up = 1;
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
return sony_spun_up ? CDS_DISC_OK : CDS_DRIVE_NOT_READY;
 }
 
@@ -452,7 +452,7 @@ static int scd_reset(struct cdrom_device_info *cdi)

 {
unsigned long retry_count;
 
-	if (down_interruptible(sony_sem))

+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
reset_drive();
 
@@ -461,7 +461,7 @@ static int scd_reset(struct cdrom_device_info *cdi)

sony_sleep();
}
 
-	up(sony_sem);

+   mutex_unlock(sony_mtx);
return 0;
 }
 
@@ -655,10 +655,10 @@ static int scd_select_speed(struct cdrom_device_info *cdi, int speed)

else
sony_speed = speed - 1;
 
-	if (down_interruptible(sony_sem))

+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
set_drive_params(sony_speed);
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
return 0;
 }
 
@@ -673,10 +673,10 @@ static int scd_lock_door(struct cdrom_device_info *cdi, int lock)

} else {
is_auto_eject = 0;
}
-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
set_drive_params(sony_speed);
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
return 0;
 }
 
@@ -1143,7 +1143,7 @@ static void handle_abort_timeout(unsigned long data)

 {
pr_debug(PFX Entering %s\n, __FUNCTION__);
/* If it is in use, ignore it. */
-   if (down_trylock(sony_sem) == 0) {
+   if (mutex_trylock(sony_mtx) == 0) {
/* We can't use abort_read(), because it will sleep
   or schedule in the timer interrupt.  Just start
   the operation, finish it on the next access to
@@ -1154,7 +1154,7 @@ static void handle_abort_timeout(unsigned long data)
 
 		sony_blocks_left = 0;

abort_read_started = 1;
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
}
pr_debug(PFX Leaving %s\n, __FUNCTION__);
 }
@@ -1300,7 +1300,7 @@ static void do_cdu31a_request(request_queue_t * q)
pr_debug(PFX Entering %s\n, __FUNCTION__);
 
 	spin_unlock_irq(q-queue_lock);

-   if (down_interruptible(sony_sem)) {
+   if (mutex_lock_interruptible(sony_mtx)) {
spin_lock_irq(q-queue_lock);
return;
}
@@ -1435,7 +1435,7 @@ static void do_cdu31a_request(request_queue_t * q)
add_timer(cdu31a_abort_timer);
 #endif
 
-	up(sony_sem);

+   mutex_unlock(sony_mtx);
spin_lock_irq(q-queue_lock);
pr_debug(PFX Leaving %s at %d\n, __FUNCTION__, __LINE__);
 }
@@ -1906,10 +1906,10 @@ static int scd_get_last_session(struct 
cdrom_device_info *cdi,
return 1;
 
 	if (!sony_toc_read) {

-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
sony_get_toc();
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
}
 
 	ms_info-addr_format = CDROM_LBA;

@@ -1988,11 +1988,11 @@ scd_get_mcn(struct cdrom_device_info *cdi, struct 
cdrom_mcn *mcn)
unsigned int res_size;
 
 	memset(mcn-medium_catalog_number, 0, 14);

-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
do_sony_cd_cmd(SONY_REQ_UPC_EAN_CMD,
   NULL, 0, resbuffer, res_size);
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
if ((res_size  2) || ((resbuffer[0]  0xf0) == 0x20));
else {

[PATCH] use mutex instead of binary semaphore in CDU-31A driver

2007-04-23 Thread Matthias Kaehlcke
use mutex instead of binary semaphore in CDU-31A driver

Signed-off-by: Matthias Kaehlcke <[EMAIL PROTECTED]>

--
diff --git a/drivers/cdrom/cdu31a.c b/drivers/cdrom/cdu31a.c
index 2157c58..d3649e4 100644
--- a/drivers/cdrom/cdu31a.c
+++ b/drivers/cdrom/cdu31a.c
@@ -263,7 +263,7 @@ static int sony_toc_read = 0;   /* Has the TOC been 
read for
 static struct s_sony_subcode last_sony_subcode;/* Points to the last
   subcode address read */
 
-static DECLARE_MUTEX(sony_sem);/* Semaphore for drive hardware 
access */
+static DEFINE_MUTEX(sony_mtx); /* Mutex for drive hardware access */
 
 static int is_double_speed = 0;/* does the drive support double speed 
? */
 
@@ -339,11 +339,11 @@ static int scd_drive_status(struct cdrom_device_info 
*cdi, int slot_nr)
return -EINVAL;
if (sony_spun_up)
return CDS_DISC_OK;
-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
if (scd_spinup() == 0)
sony_spun_up = 1;
-   up(_sem);
+   mutex_unlock(_mtx);
return sony_spun_up ? CDS_DISC_OK : CDS_DRIVE_NOT_READY;
 }
 
@@ -452,7 +452,7 @@ static int scd_reset(struct cdrom_device_info *cdi)
 {
unsigned long retry_count;
 
-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
reset_drive();
 
@@ -461,7 +461,7 @@ static int scd_reset(struct cdrom_device_info *cdi)
sony_sleep();
}
 
-   up(_sem);
+   mutex_unlock(_mtx);
return 0;
 }
 
@@ -655,10 +655,10 @@ static int scd_select_speed(struct cdrom_device_info 
*cdi, int speed)
else
sony_speed = speed - 1;
 
-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
set_drive_params(sony_speed);
-   up(_sem);
+   mutex_unlock(_mtx);
return 0;
 }
 
@@ -673,10 +673,10 @@ static int scd_lock_door(struct cdrom_device_info *cdi, 
int lock)
} else {
is_auto_eject = 0;
}
-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
set_drive_params(sony_speed);
-   up(_sem);
+   mutex_unlock(_mtx);
return 0;
 }
 
@@ -1143,7 +1143,7 @@ static void handle_abort_timeout(unsigned long data)
 {
pr_debug(PFX "Entering %s\n", __FUNCTION__);
/* If it is in use, ignore it. */
-   if (down_trylock(_sem) == 0) {
+   if (mutex_trylock(_mtx) == 0) {
/* We can't use abort_read(), because it will sleep
   or schedule in the timer interrupt.  Just start
   the operation, finish it on the next access to
@@ -1154,7 +1154,7 @@ static void handle_abort_timeout(unsigned long data)
 
sony_blocks_left = 0;
abort_read_started = 1;
-   up(_sem);
+   mutex_unlock(_mtx);
}
pr_debug(PFX "Leaving %s\n", __FUNCTION__);
 }
@@ -1300,7 +1300,7 @@ static void do_cdu31a_request(request_queue_t * q)
pr_debug(PFX "Entering %s\n", __FUNCTION__);
 
spin_unlock_irq(q->queue_lock);
-   if (down_interruptible(_sem)) {
+   if (mutex_lock_interruptible(_mtx)) {
spin_lock_irq(q->queue_lock);
return;
}
@@ -1435,7 +1435,7 @@ static void do_cdu31a_request(request_queue_t * q)
add_timer(_abort_timer);
 #endif
 
-   up(_sem);
+   mutex_unlock(_mtx);
spin_lock_irq(q->queue_lock);
pr_debug(PFX "Leaving %s at %d\n", __FUNCTION__, __LINE__);
 }
@@ -1906,10 +1906,10 @@ static int scd_get_last_session(struct 
cdrom_device_info *cdi,
return 1;
 
if (!sony_toc_read) {
-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
sony_get_toc();
-   up(_sem);
+   mutex_unlock(_mtx);
}
 
ms_info->addr_format = CDROM_LBA;
@@ -1988,11 +1988,11 @@ scd_get_mcn(struct cdrom_device_info *cdi, struct 
cdrom_mcn *mcn)
unsigned int res_size;
 
memset(mcn->medium_catalog_number, 0, 14);
-   if (down_interruptible(_sem))
+   if (mutex_lock_interruptible(_mtx))
return -ERESTARTSYS;
do_sony_cd_cmd(SONY_REQ_UPC_EAN_CMD,
   NULL, 0, resbuffer, _size);
-   up(_sem);
+   mutex_unlock(_mtx);
if ((res_size < 2) || ((resbuffer[0] & 0xf0) == 0x20));
else {
/* packed bcd to single ASCII digits */
@@ -2207,7 +2207,7 @@ static int read_audio(struct cdrom_read_audio *ra)
unsigned int res_size;
unsigned int cframe;
 
-   if (down_interruptible(_sem))
+   if 

[PATCH] use mutex instead of binary semaphore in CDU-31A driver

2007-04-23 Thread Matthias Kaehlcke
use mutex instead of binary semaphore in CDU-31A driver

Signed-off-by: Matthias Kaehlcke [EMAIL PROTECTED]

--
diff --git a/drivers/cdrom/cdu31a.c b/drivers/cdrom/cdu31a.c
index 2157c58..d3649e4 100644
--- a/drivers/cdrom/cdu31a.c
+++ b/drivers/cdrom/cdu31a.c
@@ -263,7 +263,7 @@ static int sony_toc_read = 0;   /* Has the TOC been 
read for
 static struct s_sony_subcode last_sony_subcode;/* Points to the last
   subcode address read */
 
-static DECLARE_MUTEX(sony_sem);/* Semaphore for drive hardware 
access */
+static DEFINE_MUTEX(sony_mtx); /* Mutex for drive hardware access */
 
 static int is_double_speed = 0;/* does the drive support double speed 
? */
 
@@ -339,11 +339,11 @@ static int scd_drive_status(struct cdrom_device_info 
*cdi, int slot_nr)
return -EINVAL;
if (sony_spun_up)
return CDS_DISC_OK;
-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
if (scd_spinup() == 0)
sony_spun_up = 1;
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
return sony_spun_up ? CDS_DISC_OK : CDS_DRIVE_NOT_READY;
 }
 
@@ -452,7 +452,7 @@ static int scd_reset(struct cdrom_device_info *cdi)
 {
unsigned long retry_count;
 
-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
reset_drive();
 
@@ -461,7 +461,7 @@ static int scd_reset(struct cdrom_device_info *cdi)
sony_sleep();
}
 
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
return 0;
 }
 
@@ -655,10 +655,10 @@ static int scd_select_speed(struct cdrom_device_info 
*cdi, int speed)
else
sony_speed = speed - 1;
 
-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
set_drive_params(sony_speed);
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
return 0;
 }
 
@@ -673,10 +673,10 @@ static int scd_lock_door(struct cdrom_device_info *cdi, 
int lock)
} else {
is_auto_eject = 0;
}
-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
set_drive_params(sony_speed);
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
return 0;
 }
 
@@ -1143,7 +1143,7 @@ static void handle_abort_timeout(unsigned long data)
 {
pr_debug(PFX Entering %s\n, __FUNCTION__);
/* If it is in use, ignore it. */
-   if (down_trylock(sony_sem) == 0) {
+   if (mutex_trylock(sony_mtx) == 0) {
/* We can't use abort_read(), because it will sleep
   or schedule in the timer interrupt.  Just start
   the operation, finish it on the next access to
@@ -1154,7 +1154,7 @@ static void handle_abort_timeout(unsigned long data)
 
sony_blocks_left = 0;
abort_read_started = 1;
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
}
pr_debug(PFX Leaving %s\n, __FUNCTION__);
 }
@@ -1300,7 +1300,7 @@ static void do_cdu31a_request(request_queue_t * q)
pr_debug(PFX Entering %s\n, __FUNCTION__);
 
spin_unlock_irq(q-queue_lock);
-   if (down_interruptible(sony_sem)) {
+   if (mutex_lock_interruptible(sony_mtx)) {
spin_lock_irq(q-queue_lock);
return;
}
@@ -1435,7 +1435,7 @@ static void do_cdu31a_request(request_queue_t * q)
add_timer(cdu31a_abort_timer);
 #endif
 
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
spin_lock_irq(q-queue_lock);
pr_debug(PFX Leaving %s at %d\n, __FUNCTION__, __LINE__);
 }
@@ -1906,10 +1906,10 @@ static int scd_get_last_session(struct 
cdrom_device_info *cdi,
return 1;
 
if (!sony_toc_read) {
-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
sony_get_toc();
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
}
 
ms_info-addr_format = CDROM_LBA;
@@ -1988,11 +1988,11 @@ scd_get_mcn(struct cdrom_device_info *cdi, struct 
cdrom_mcn *mcn)
unsigned int res_size;
 
memset(mcn-medium_catalog_number, 0, 14);
-   if (down_interruptible(sony_sem))
+   if (mutex_lock_interruptible(sony_mtx))
return -ERESTARTSYS;
do_sony_cd_cmd(SONY_REQ_UPC_EAN_CMD,
   NULL, 0, resbuffer, res_size);
-   up(sony_sem);
+   mutex_unlock(sony_mtx);
if ((res_size  2) || ((resbuffer[0]  0xf0) == 0x20));
else {
/* packed bcd to single ASCII digits */
@@ -2207,7 +2207,7 @@ static int read_audio(struct cdrom_read_audio *ra)
unsigned