[PATCH] pcmcia/pccard deadlock fix

From: Markus Rechberger
Date: Tue Feb 20 2007 - 10:07:59 EST


following patch prevents a mutex/semaphore deadlock within the pcmcia
framework when ejecting devices multiple times using pccardctl eject.

For some more details see:
http://lkml.org/lkml/2007/2/19/58

Signed-off-by: Markus Rechberger <markus.rechberger@xxxxxxx>

--
Markus Rechberger
Operating System Research Center
AMD Saxony LLC & Co. KG

index ac00424..c02bf0d 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -856,7 +856,8 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)

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

- mutex_lock(&skt->skt_mutex);
+ if (!mutex_trylock(&skt->skt_mutex))
+ return -EAGAIN;
do {
if (!(skt->state & SOCKET_PRESENT)) {
ret = -ENODEV;
index 18e111e..b9d3440 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -1100,7 +1100,9 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
if (!count)
return -EINVAL;

- mutex_lock(&p_dev->socket->skt_mutex);
+ if (!mutex_trylock(&p_dev->socket->skt_mutex))
+ return -EAGAIN;
+
p_dev->allow_func_id_match = 1;
mutex_unlock(&p_dev->socket->skt_mutex);