mirror of https://gitee.com/openkylin/linux.git
USB: auerswald: Convert ccp->mutex in a mutex
The semaphore ccp->mutex is used as mutex, convert it to the mutex API Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net> Cc: Wolfgang Mües <wolfgang@iksw-muees.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
8a0f46b92f
commit
fadec78bd9
|
@ -254,7 +254,7 @@ typedef struct
|
||||||
/* character device context */
|
/* character device context */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
struct semaphore mutex; /* protection in user context */
|
struct mutex mutex; /* protection in user context */
|
||||||
pauerswald_t auerdev; /* context pointer of assigned device */
|
pauerswald_t auerdev; /* context pointer of assigned device */
|
||||||
auerbufctl_t bufctl; /* controls the buffer chain */
|
auerbufctl_t bufctl; /* controls the buffer chain */
|
||||||
auerscon_t scontext; /* service context */
|
auerscon_t scontext; /* service context */
|
||||||
|
@ -1390,7 +1390,7 @@ static int auerchar_open (struct inode *inode, struct file *file)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize device descriptor */
|
/* Initialize device descriptor */
|
||||||
init_MUTEX( &ccp->mutex);
|
mutex_init(&ccp->mutex);
|
||||||
mutex_init(&ccp->readmutex);
|
mutex_init(&ccp->readmutex);
|
||||||
auerbuf_init (&ccp->bufctl);
|
auerbuf_init (&ccp->bufctl);
|
||||||
ccp->scontext.id = AUH_UNASSIGNED;
|
ccp->scontext.id = AUH_UNASSIGNED;
|
||||||
|
@ -1433,23 +1433,23 @@ static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int
|
||||||
dbg ("ioctl");
|
dbg ("ioctl");
|
||||||
|
|
||||||
/* get the mutexes */
|
/* get the mutexes */
|
||||||
if (down_interruptible (&ccp->mutex)) {
|
if (mutex_lock_interruptible(&ccp->mutex)) {
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
}
|
}
|
||||||
cp = ccp->auerdev;
|
cp = ccp->auerdev;
|
||||||
if (!cp) {
|
if (!cp) {
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
if (mutex_lock_interruptible(&cp->mutex)) {
|
if (mutex_lock_interruptible(&cp->mutex)) {
|
||||||
up(&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for removal */
|
/* Check for removal */
|
||||||
if (!cp->usbdev) {
|
if (!cp->usbdev) {
|
||||||
mutex_unlock(&cp->mutex);
|
mutex_unlock(&cp->mutex);
|
||||||
up(&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1552,7 +1552,7 @@ static int auerchar_ioctl (struct inode *inode, struct file *file, unsigned int
|
||||||
}
|
}
|
||||||
/* release the mutexes */
|
/* release the mutexes */
|
||||||
mutex_unlock(&cp->mutex);
|
mutex_unlock(&cp->mutex);
|
||||||
up(&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1575,18 +1575,18 @@ static ssize_t auerchar_read (struct file *file, char __user *buf, size_t count,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* get the mutex */
|
/* get the mutex */
|
||||||
if (down_interruptible (&ccp->mutex))
|
if (mutex_lock_interruptible(&ccp->mutex))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
/* Can we expect to read something? */
|
/* Can we expect to read something? */
|
||||||
if (ccp->scontext.id == AUH_UNASSIGNED) {
|
if (ccp->scontext.id == AUH_UNASSIGNED) {
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only one reader per device allowed */
|
/* only one reader per device allowed */
|
||||||
if (mutex_lock_interruptible(&ccp->readmutex)) {
|
if (mutex_lock_interruptible(&ccp->readmutex)) {
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1604,7 +1604,7 @@ static ssize_t auerchar_read (struct file *file, char __user *buf, size_t count,
|
||||||
if (copy_to_user (buf, bp->bufp+ccp->readoffset, count)) {
|
if (copy_to_user (buf, bp->bufp+ccp->readoffset, count)) {
|
||||||
dbg ("auerswald_read: copy_to_user failed");
|
dbg ("auerswald_read: copy_to_user failed");
|
||||||
mutex_unlock(&ccp->readmutex);
|
mutex_unlock(&ccp->readmutex);
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1619,7 +1619,7 @@ static ssize_t auerchar_read (struct file *file, char __user *buf, size_t count,
|
||||||
/* return with number of bytes read */
|
/* return with number of bytes read */
|
||||||
if (count) {
|
if (count) {
|
||||||
mutex_unlock(&ccp->readmutex);
|
mutex_unlock(&ccp->readmutex);
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1656,12 +1656,12 @@ static ssize_t auerchar_read (struct file *file, char __user *buf, size_t count,
|
||||||
set_current_state (TASK_RUNNING);
|
set_current_state (TASK_RUNNING);
|
||||||
remove_wait_queue (&ccp->readwait, &wait);
|
remove_wait_queue (&ccp->readwait, &wait);
|
||||||
mutex_unlock(&ccp->readmutex);
|
mutex_unlock(&ccp->readmutex);
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -EAGAIN; /* nonblocking, no data available */
|
return -EAGAIN; /* nonblocking, no data available */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* yes, we should wait! */
|
/* yes, we should wait! */
|
||||||
up (&ccp->mutex); /* allow other operations while we wait */
|
mutex_unlock(&ccp->mutex); /* allow other operations while we wait */
|
||||||
schedule();
|
schedule();
|
||||||
remove_wait_queue (&ccp->readwait, &wait);
|
remove_wait_queue (&ccp->readwait, &wait);
|
||||||
if (signal_pending (current)) {
|
if (signal_pending (current)) {
|
||||||
|
@ -1676,7 +1676,7 @@ static ssize_t auerchar_read (struct file *file, char __user *buf, size_t count,
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (down_interruptible (&ccp->mutex)) {
|
if (mutex_lock_interruptible(&ccp->mutex)) {
|
||||||
mutex_unlock(&ccp->readmutex);
|
mutex_unlock(&ccp->readmutex);
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
}
|
}
|
||||||
|
@ -1708,27 +1708,27 @@ static ssize_t auerchar_write (struct file *file, const char __user *buf, size_t
|
||||||
|
|
||||||
write_again:
|
write_again:
|
||||||
/* get the mutex */
|
/* get the mutex */
|
||||||
if (down_interruptible (&ccp->mutex))
|
if (mutex_lock_interruptible(&ccp->mutex))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
/* Can we expect to write something? */
|
/* Can we expect to write something? */
|
||||||
if (ccp->scontext.id == AUH_UNASSIGNED) {
|
if (ccp->scontext.id == AUH_UNASSIGNED) {
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
cp = ccp->auerdev;
|
cp = ccp->auerdev;
|
||||||
if (!cp) {
|
if (!cp) {
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
}
|
}
|
||||||
if (mutex_lock_interruptible(&cp->mutex)) {
|
if (mutex_lock_interruptible(&cp->mutex)) {
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
}
|
}
|
||||||
if (!cp->usbdev) {
|
if (!cp->usbdev) {
|
||||||
mutex_unlock(&cp->mutex);
|
mutex_unlock(&cp->mutex);
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
/* Prepare for sleep */
|
/* Prepare for sleep */
|
||||||
|
@ -1752,7 +1752,7 @@ static ssize_t auerchar_write (struct file *file, const char __user *buf, size_t
|
||||||
/* are there any buffers left? */
|
/* are there any buffers left? */
|
||||||
if (!bp) {
|
if (!bp) {
|
||||||
mutex_unlock(&cp->mutex);
|
mutex_unlock(&cp->mutex);
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
|
|
||||||
/* NONBLOCK: don't wait */
|
/* NONBLOCK: don't wait */
|
||||||
if (file->f_flags & O_NONBLOCK) {
|
if (file->f_flags & O_NONBLOCK) {
|
||||||
|
@ -1785,7 +1785,7 @@ static ssize_t auerchar_write (struct file *file, const char __user *buf, size_t
|
||||||
/* Wake up all processes waiting for a buffer */
|
/* Wake up all processes waiting for a buffer */
|
||||||
wake_up (&cp->bufferwait);
|
wake_up (&cp->bufferwait);
|
||||||
mutex_unlock(&cp->mutex);
|
mutex_unlock(&cp->mutex);
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1810,12 +1810,12 @@ static ssize_t auerchar_write (struct file *file, const char __user *buf, size_t
|
||||||
auerbuf_releasebuf (bp);
|
auerbuf_releasebuf (bp);
|
||||||
/* Wake up all processes waiting for a buffer */
|
/* Wake up all processes waiting for a buffer */
|
||||||
wake_up (&cp->bufferwait);
|
wake_up (&cp->bufferwait);
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dbg ("auerchar_write: Write OK");
|
dbg ("auerchar_write: Write OK");
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1828,7 +1828,7 @@ static int auerchar_release (struct inode *inode, struct file *file)
|
||||||
pauerswald_t cp;
|
pauerswald_t cp;
|
||||||
dbg("release");
|
dbg("release");
|
||||||
|
|
||||||
down(&ccp->mutex);
|
mutex_lock(&ccp->mutex);
|
||||||
cp = ccp->auerdev;
|
cp = ccp->auerdev;
|
||||||
if (cp) {
|
if (cp) {
|
||||||
mutex_lock(&cp->mutex);
|
mutex_lock(&cp->mutex);
|
||||||
|
@ -1845,7 +1845,7 @@ static int auerchar_release (struct inode *inode, struct file *file)
|
||||||
cp = NULL;
|
cp = NULL;
|
||||||
ccp->auerdev = NULL;
|
ccp->auerdev = NULL;
|
||||||
}
|
}
|
||||||
up (&ccp->mutex);
|
mutex_unlock(&ccp->mutex);
|
||||||
auerchar_delete (ccp);
|
auerchar_delete (ccp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue