Commit 8680c4b3 authored by Dominik Brodowski's avatar Dominik Brodowski

pcmcia: also lock fake and cache CIS by ops_mutex

Specifically,

	struct list_head		cis_cache;
	size_t				fake_cis_len;
	u8				*fake_cis;

are protected.
Tested-by: default avatarWolfram Sang <w.sang@pengutronix.de>
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
parent 6b8e087b
...@@ -277,20 +277,24 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, ...@@ -277,20 +277,24 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
if (s->state & SOCKET_CARDBUS) if (s->state & SOCKET_CARDBUS)
return; return;
mutex_lock(&s->ops_mutex);
if (s->fake_cis) { if (s->fake_cis) {
if (s->fake_cis_len >= addr+len) if (s->fake_cis_len >= addr+len)
memcpy(ptr, s->fake_cis+addr, len); memcpy(ptr, s->fake_cis+addr, len);
else else
memset(ptr, 0xff, len); memset(ptr, 0xff, len);
mutex_unlock(&s->ops_mutex);
return; return;
} }
list_for_each_entry(cis, &s->cis_cache, node) { list_for_each_entry(cis, &s->cis_cache, node) {
if (cis->addr == addr && cis->len == len && cis->attr == attr) { if (cis->addr == addr && cis->len == len && cis->attr == attr) {
memcpy(ptr, cis->cache, len); memcpy(ptr, cis->cache, len);
mutex_unlock(&s->ops_mutex);
return; return;
} }
} }
mutex_unlock(&s->ops_mutex);
ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr); ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr);
...@@ -302,7 +306,9 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, ...@@ -302,7 +306,9 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
cis->len = len; cis->len = len;
cis->attr = attr; cis->attr = attr;
memcpy(cis->cache, ptr, len); memcpy(cis->cache, ptr, len);
mutex_lock(&s->ops_mutex);
list_add(&cis->node, &s->cis_cache); list_add(&cis->node, &s->cis_cache);
mutex_unlock(&s->ops_mutex);
} }
} }
} }
...@@ -312,19 +318,22 @@ remove_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, u_int len) ...@@ -312,19 +318,22 @@ remove_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, u_int len)
{ {
struct cis_cache_entry *cis; struct cis_cache_entry *cis;
mutex_lock(&s->ops_mutex);
list_for_each_entry(cis, &s->cis_cache, node) list_for_each_entry(cis, &s->cis_cache, node)
if (cis->addr == addr && cis->len == len && cis->attr == attr) { if (cis->addr == addr && cis->len == len && cis->attr == attr) {
list_del(&cis->node); list_del(&cis->node);
kfree(cis); kfree(cis);
break; break;
} }
mutex_unlock(&s->ops_mutex);
} }
/** /**
* destroy_cis_cache() - destroy the CIS cache * destroy_cis_cache() - destroy the CIS cache
* @s: pcmcia_socket for which CIS cache shall be destroyed * @s: pcmcia_socket for which CIS cache shall be destroyed
* *
* This destroys the CIS cache but keeps any fake CIS alive. * This destroys the CIS cache but keeps any fake CIS alive. Must be
* called with ops_mutex held.
*/ */
void destroy_cis_cache(struct pcmcia_socket *s) void destroy_cis_cache(struct pcmcia_socket *s)
...@@ -391,14 +400,17 @@ int pcmcia_replace_cis(struct pcmcia_socket *s, ...@@ -391,14 +400,17 @@ int pcmcia_replace_cis(struct pcmcia_socket *s,
dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n");
return -EINVAL; return -EINVAL;
} }
mutex_lock(&s->ops_mutex);
kfree(s->fake_cis); kfree(s->fake_cis);
s->fake_cis = kmalloc(len, GFP_KERNEL); s->fake_cis = kmalloc(len, GFP_KERNEL);
if (s->fake_cis == NULL) { if (s->fake_cis == NULL) {
dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n");
mutex_unlock(&s->ops_mutex);
return -ENOMEM; return -ENOMEM;
} }
s->fake_cis_len = len; s->fake_cis_len = len;
memcpy(s->fake_cis, data, len); memcpy(s->fake_cis, data, len);
mutex_unlock(&s->ops_mutex);
return 0; return 0;
} }
...@@ -1461,7 +1473,9 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) ...@@ -1461,7 +1473,9 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
return -EINVAL; return -EINVAL;
/* We do not want to validate the CIS cache... */ /* We do not want to validate the CIS cache... */
mutex_lock(&s->ops_mutex);
destroy_cis_cache(s); destroy_cis_cache(s);
mutex_unlock(&s->ops_mutex);
tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); tuple = kmalloc(sizeof(*tuple), GFP_KERNEL);
if (tuple == NULL) { if (tuple == NULL) {
...@@ -1518,7 +1532,9 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) ...@@ -1518,7 +1532,9 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
done: done:
/* invalidate CIS cache on failure */ /* invalidate CIS cache on failure */
if (!dev_ok || !ident_ok || !count) { if (!dev_ok || !ident_ok || !count) {
mutex_lock(&s->ops_mutex);
destroy_cis_cache(s); destroy_cis_cache(s);
mutex_unlock(&s->ops_mutex);
ret = -EIO; ret = -EIO;
} }
......
...@@ -1241,12 +1241,16 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) ...@@ -1241,12 +1241,16 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
s->pcmcia_state.present = 0; s->pcmcia_state.present = 0;
pcmcia_card_remove(skt, NULL); pcmcia_card_remove(skt, NULL);
handle_event(skt, event); handle_event(skt, event);
mutex_lock(&s->ops_mutex);
destroy_cis_cache(s); destroy_cis_cache(s);
mutex_unlock(&s->ops_mutex);
break; break;
case CS_EVENT_CARD_INSERTION: case CS_EVENT_CARD_INSERTION:
s->pcmcia_state.present = 1; s->pcmcia_state.present = 1;
mutex_lock(&s->ops_mutex);
destroy_cis_cache(s); /* to be on the safe side... */ destroy_cis_cache(s); /* to be on the safe side... */
mutex_unlock(&s->ops_mutex);
pcmcia_card_add(skt); pcmcia_card_add(skt);
handle_event(skt, event); handle_event(skt, event);
break; break;
...@@ -1259,9 +1263,11 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) ...@@ -1259,9 +1263,11 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
dev_dbg(&skt->dev, "cis mismatch - different card\n"); dev_dbg(&skt->dev, "cis mismatch - different card\n");
/* first, remove the card */ /* first, remove the card */
ds_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); ds_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH);
mutex_lock(&s->ops_mutex);
destroy_cis_cache(skt); destroy_cis_cache(skt);
kfree(skt->fake_cis); kfree(skt->fake_cis);
skt->fake_cis = NULL; skt->fake_cis = NULL;
mutex_unlock(&s->ops_mutex);
/* now, add the new card */ /* now, add the new card */
ds_event(skt, CS_EVENT_CARD_INSERTION, ds_event(skt, CS_EVENT_CARD_INSERTION,
CS_EVENT_PRI_LOW); CS_EVENT_PRI_LOW);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment