Skip to content

Commit

Permalink
[PATCH] pcmcia: use mutexes instead of semaphores
Browse files Browse the repository at this point in the history
Use mutexes in the PCMICA core, as they suffice for what needs to be done.
Includes a bugfix from and Signed-off-by Andrew Morton.

Signed-off-by: Dominik Brodowski <[email protected]>
  • Loading branch information
Dominik Brodowski committed Mar 31, 2006
1 parent cbbddd1 commit 7fe908d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 58 deletions.
40 changes: 20 additions & 20 deletions drivers/pcmcia/cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state)
list_for_each_entry(socket, &pcmcia_socket_list, socket_list) {
if (socket->dev.dev != dev)
continue;
down(&socket->skt_sem);
mutex_lock(&socket->skt_mutex);
socket_suspend(socket);
up(&socket->skt_sem);
mutex_unlock(&socket->skt_mutex);
}
up_read(&pcmcia_socket_list_rwsem);

Expand All @@ -129,9 +129,9 @@ int pcmcia_socket_dev_resume(struct device *dev)
list_for_each_entry(socket, &pcmcia_socket_list, socket_list) {
if (socket->dev.dev != dev)
continue;
down(&socket->skt_sem);
mutex_lock(&socket->skt_mutex);
socket_resume(socket);
up(&socket->skt_sem);
mutex_unlock(&socket->skt_mutex);
}
up_read(&pcmcia_socket_list_rwsem);

Expand Down Expand Up @@ -237,7 +237,7 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
init_completion(&socket->socket_released);
init_completion(&socket->thread_done);
init_waitqueue_head(&socket->thread_wait);
init_MUTEX(&socket->skt_sem);
mutex_init(&socket->skt_mutex);
spin_lock_init(&socket->thread_lock);

ret = kernel_thread(pccardd, socket, CLONE_KERNEL);
Expand Down Expand Up @@ -662,7 +662,7 @@ static int pccardd(void *__skt)
spin_unlock_irqrestore(&skt->thread_lock, flags);

if (events) {
down(&skt->skt_sem);
mutex_lock(&skt->skt_mutex);
if (events & SS_DETECT)
socket_detect_change(skt);
if (events & SS_BATDEAD)
Expand All @@ -671,7 +671,7 @@ static int pccardd(void *__skt)
send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW);
if (events & SS_READY)
send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW);
up(&skt->skt_sem);
mutex_unlock(&skt->skt_mutex);
continue;
}

Expand Down Expand Up @@ -715,8 +715,8 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
{
int ret = 0;

/* s->skt_sem also protects s->callback */
down(&s->skt_sem);
/* s->skt_mutex also protects s->callback */
mutex_lock(&s->skt_mutex);

if (c) {
/* registration */
Expand All @@ -732,7 +732,7 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
} else
s->callback = NULL;
err:
up(&s->skt_sem);
mutex_unlock(&s->skt_mutex);

return ret;
}
Expand All @@ -750,7 +750,7 @@ int pccard_reset_card(struct pcmcia_socket *skt)

cs_dbg(skt, 1, "resetting socket\n");

down(&skt->skt_sem);
mutex_lock(&skt->skt_mutex);
do {
if (!(skt->state & SOCKET_PRESENT)) {
ret = CS_NO_CARD;
Expand Down Expand Up @@ -779,7 +779,7 @@ int pccard_reset_card(struct pcmcia_socket *skt)

ret = CS_SUCCESS;
} while (0);
up(&skt->skt_sem);
mutex_unlock(&skt->skt_mutex);

return ret;
} /* reset_card */
Expand All @@ -795,7 +795,7 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)

cs_dbg(skt, 1, "suspending socket\n");

down(&skt->skt_sem);
mutex_lock(&skt->skt_mutex);
do {
if (!(skt->state & SOCKET_PRESENT)) {
ret = CS_NO_CARD;
Expand All @@ -812,7 +812,7 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
}
ret = socket_suspend(skt);
} while (0);
up(&skt->skt_sem);
mutex_unlock(&skt->skt_mutex);

return ret;
} /* suspend_card */
Expand All @@ -825,7 +825,7 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)

cs_dbg(skt, 1, "waking up socket\n");

down(&skt->skt_sem);
mutex_lock(&skt->skt_mutex);
do {
if (!(skt->state & SOCKET_PRESENT)) {
ret = CS_NO_CARD;
Expand All @@ -839,7 +839,7 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
if (!ret && skt->callback)
skt->callback->resume(skt);
} while (0);
up(&skt->skt_sem);
mutex_unlock(&skt->skt_mutex);

return ret;
} /* resume_card */
Expand All @@ -853,7 +853,7 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)

cs_dbg(skt, 1, "user eject request\n");

down(&skt->skt_sem);
mutex_lock(&skt->skt_mutex);
do {
if (!(skt->state & SOCKET_PRESENT)) {
ret = -ENODEV;
Expand All @@ -869,7 +869,7 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)
socket_remove(skt);
ret = 0;
} while (0);
up(&skt->skt_sem);
mutex_unlock(&skt->skt_mutex);

return ret;
} /* eject_card */
Expand All @@ -882,7 +882,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)

cs_dbg(skt, 1, "user insert request\n");

down(&skt->skt_sem);
mutex_lock(&skt->skt_mutex);
do {
if (skt->state & SOCKET_PRESENT) {
ret = -EBUSY;
Expand All @@ -894,7 +894,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
}
ret = 0;
} while (0);
up(&skt->skt_sem);
mutex_unlock(&skt->skt_mutex);

return ret;
} /* insert_card */
Expand Down
14 changes: 7 additions & 7 deletions drivers/pcmcia/ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
* won't work, this doesn't matter much at the moment: the driver core doesn't
* support it either.
*/
static DECLARE_MUTEX(device_add_lock);
static DEFINE_MUTEX(device_add_lock);

struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function)
{
Expand All @@ -576,7 +576,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
if (!s)
return NULL;

down(&device_add_lock);
mutex_lock(&device_add_lock);

/* max of 2 devices per card */
if (s->device_count == 2)
Expand Down Expand Up @@ -640,7 +640,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
if (device_register(&p_dev->dev))
goto err_unreg;

up(&device_add_lock);
mutex_unlock(&device_add_lock);

return p_dev;

Expand All @@ -654,7 +654,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
kfree(p_dev);
s->device_count--;
err_put:
up(&device_add_lock);
mutex_unlock(&device_add_lock);
pcmcia_put_socket(s);

return NULL;
Expand Down Expand Up @@ -713,7 +713,7 @@ static void pcmcia_bus_rescan(struct pcmcia_socket *skt)
int no_devices=0;
unsigned long flags;

/* must be called with skt_sem held */
/* must be called with skt_mutex held */
spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
if (list_empty(&skt->devices_list))
no_devices=1;
Expand Down Expand Up @@ -999,9 +999,9 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
if (!count)
return -EINVAL;

down(&p_dev->socket->skt_sem);
mutex_lock(&p_dev->socket->skt_mutex);
p_dev->allow_func_id_match = 1;
up(&p_dev->socket->skt_sem);
mutex_unlock(&p_dev->socket->skt_mutex);

bus_rescan_devices(&pcmcia_bus_type);

Expand Down
12 changes: 6 additions & 6 deletions drivers/pcmcia/pcmcia_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
/*
* Prevent this racing with a card insertion.
*/
down(&s->skt_sem);
mutex_lock(&s->skt_mutex);
bus_rescan_devices(&pcmcia_bus_type);
up(&s->skt_sem);
mutex_unlock(&s->skt_mutex);

/* check whether the driver indeed matched. I don't care if this
* is racy or not, because it can only happen on cardmgr access
Expand Down Expand Up @@ -606,9 +606,9 @@ static int ds_ioctl(struct inode * inode, struct file * file,
}
break;
case DS_GET_FIRST_TUPLE:
down(&s->skt_sem);
mutex_lock(&s->skt_mutex);
pcmcia_validate_mem(s);
up(&s->skt_sem);
mutex_unlock(&s->skt_mutex);
ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple);
break;
case DS_GET_NEXT_TUPLE:
Expand Down Expand Up @@ -637,9 +637,9 @@ static int ds_ioctl(struct inode * inode, struct file * file,
}
break;
case DS_VALIDATE_CIS:
down(&s->skt_sem);
mutex_lock(&s->skt_mutex);
pcmcia_validate_mem(s);
up(&s->skt_sem);
mutex_unlock(&s->skt_mutex);
ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo);
break;
case DS_SUSPEND_CARD:
Expand Down
Loading

0 comments on commit 7fe908d

Please sign in to comment.