From 933a838aa1aae8388438bb002fbdaf6fca519a5c Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Tue, 29 Dec 2009 18:21:39 +0100 Subject: pcmcia: make use of pcmcia_dev_resume() return value In runtime_resume(), do not throw away the return value of pcmcia_dev_resume(), for we can use it (at least) in pcmcia_store_pm_state(). This also fixes the pointless assignment previosly seen there, as noted by Dan Carpenter. CC: Dan Carpenter Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 1a4a3c49cc1..defa44c27b9 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -970,13 +970,14 @@ static int runtime_suspend(struct device *dev) return rc; } -static void runtime_resume(struct device *dev) +static int runtime_resume(struct device *dev) { int rc; down(&dev->sem); rc = pcmcia_dev_resume(dev); up(&dev->sem); + return rc; } /************************ per-device sysfs output ***************************/ @@ -1027,7 +1028,7 @@ static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute if ((!p_dev->suspended) && !strncmp(buf, "off", 3)) ret = runtime_suspend(dev); else if (p_dev->suspended && !strncmp(buf, "on", 2)) - runtime_resume(dev); + ret = runtime_resume(dev); return ret ? ret : count; } -- cgit v1.2.3-70-g09d2 From 88b060d6c03fcb9e4d2018b4349954c4242a5c7f Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 2 Jan 2010 14:14:23 +0100 Subject: pcmcia: improve check for same card in slot after resume During a suspend/resume cycle, an user may change the card in the PCMCIA/CardBus slot. The pcmcia_core can at least look at the socket state to check whether it is the same. For PCMCIA devices, move the detection and handling of such a change to ds.c. For CardBus devices, the PCI hotplug interface doesn't offer a "rescan" facility which also _removes_ devices no longer to be found behind a bridge. Therefore, remove and re-add all devices unconditionally. CC: Jesse Barnes CC: Linus Torvalds Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cistpl.c | 1 + drivers/pcmcia/cs.c | 65 +++++++++++++++++++++++-------------------------- drivers/pcmcia/ds.c | 16 +++++++++++- include/pcmcia/ss.h | 1 + 4 files changed, 47 insertions(+), 36 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 04bf1ba607f..a8323cb2e34 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -377,6 +377,7 @@ int verify_cis_cache(struct pcmcia_socket *s) kfree(buf); return 0; } +EXPORT_SYMBOL(verify_cis_cache); /*====================================================================== diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 96d8d25c209..8c51493d1f9 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -328,7 +328,7 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) { int ret; - if (s->state & SOCKET_CARDBUS) + if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL)) return 0; dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n", @@ -346,13 +346,6 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) return ret; } -static void socket_remove_drivers(struct pcmcia_socket *skt) -{ - dev_dbg(&skt->dev, "remove_drivers\n"); - - send_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); -} - static int socket_reset(struct pcmcia_socket *skt) { int status, i; @@ -395,7 +388,7 @@ static void socket_shutdown(struct pcmcia_socket *s) dev_dbg(&s->dev, "shutdown\n"); - socket_remove_drivers(s); + send_event(s, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); s->state &= SOCKET_INUSE | SOCKET_PRESENT; msleep(shutdown_delay * 10); s->state &= SOCKET_INUSE; @@ -462,7 +455,8 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay) return -EINVAL; } skt->state |= SOCKET_CARDBUS; - } + } else + skt->state &= ~SOCKET_CARDBUS; /* * Decode the card voltage requirements, and apply power to the card. @@ -544,6 +538,8 @@ static int socket_suspend(struct pcmcia_socket *skt) if (skt->state & SOCKET_SUSPEND) return -EBUSY; + skt->suspended_state = skt->state; + send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); skt->socket = dead_socket; skt->ops->set_socket(skt, &skt->socket); @@ -566,38 +562,37 @@ static int socket_early_resume(struct pcmcia_socket *skt) static int socket_late_resume(struct pcmcia_socket *skt) { - if (!(skt->state & SOCKET_PRESENT)) { - skt->state &= ~SOCKET_SUSPEND; + skt->state &= ~SOCKET_SUSPEND; + + if (!(skt->state & SOCKET_PRESENT)) return socket_insert(skt); + + if (skt->resume_status) { + socket_shutdown(skt); + return 0; } - if (skt->resume_status == 0) { - /* - * FIXME: need a better check here for cardbus cards. - */ - if (verify_cis_cache(skt) != 0) { - dev_dbg(&skt->dev, "cis mismatch - different card\n"); - socket_remove_drivers(skt); - destroy_cis_cache(skt); - kfree(skt->fake_cis); - skt->fake_cis = NULL; - /* - * Workaround: give DS time to schedule removal. - * Remove me once the 100ms delay is eliminated - * in ds.c - */ - msleep(200); - send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); - } else { - dev_dbg(&skt->dev, "cis matches cache\n"); - send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW); - } - } else { + if (skt->suspended_state != skt->state) { + dev_dbg(&skt->dev, + "suspend state 0x%x != resume state 0x%x\n", + skt->suspended_state, skt->state); + socket_shutdown(skt); + return socket_insert(skt); } - skt->state &= ~SOCKET_SUSPEND; +#ifdef CONFIG_CARDBUS + if (skt->state & SOCKET_CARDBUS) { + /* We can't be sure the CardBus card is the same + * as the one previously inserted. Therefore, remove + * and re-add... */ + cb_free(skt); + cb_alloc(skt); + return 0; + } +#endif + send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW); return 0; } diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index defa44c27b9..87e06395c12 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -1252,8 +1252,22 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) case CS_EVENT_EJECTION_REQUEST: break; - case CS_EVENT_PM_SUSPEND: case CS_EVENT_PM_RESUME: + if (verify_cis_cache(skt) != 0) { + dev_dbg(&skt->dev, "cis mismatch - different card\n"); + /* first, remove the card */ + ds_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); + destroy_cis_cache(skt); + kfree(skt->fake_cis); + skt->fake_cis = NULL; + /* now, add the new card */ + ds_event(skt, CS_EVENT_CARD_INSERTION, + CS_EVENT_PRI_LOW); + } + handle_event(skt, event); + break; + + case CS_EVENT_PM_SUSPEND: case CS_EVENT_RESET_PHYSICAL: case CS_EVENT_CARD_RESET: default: diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h index cbfba885eb8..b0ebd11130c 100644 --- a/include/pcmcia/ss.h +++ b/include/pcmcia/ss.h @@ -137,6 +137,7 @@ struct pcmcia_socket { spinlock_t lock; socket_state_t socket; u_int state; + u_int suspended_state; /* state before suspend */ u_short functions; u_short lock_count; pccard_mem_map cis_mem; -- cgit v1.2.3-70-g09d2 From 180c33ee409eb3ed605d4ad9884e4a526a7655ff Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 2 Jan 2010 17:34:09 +0100 Subject: pcmcia: call CIS cleanup from ds.c As ds.c is the only real user of CIS access functions, call the cleanup functions from ds.c, too. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs.c | 3 --- drivers/pcmcia/ds.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 8c51493d1f9..9d8b9c1f5a6 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -283,8 +283,6 @@ void pcmcia_unregister_socket(struct pcmcia_socket *socket) if (socket->thread) kthread_stop(socket->thread); - release_cis_mem(socket); - /* remove from our own list */ down_write(&pcmcia_socket_list_rwsem); list_del(&socket->socket_list); @@ -399,7 +397,6 @@ static void socket_shutdown(struct pcmcia_socket *s) s->ops->set_socket(s, &s->socket); s->irq.AssignedIRQ = s->irq.Config = 0; s->lock_count = 0; - destroy_cis_cache(s); kfree(s->fake_cis); s->fake_cis = NULL; #ifdef CONFIG_CARDBUS diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 87e06395c12..7bb52b003f0 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -1241,10 +1241,12 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) s->pcmcia_state.present = 0; pcmcia_card_remove(skt, NULL); handle_event(skt, event); + destroy_cis_cache(s); break; case CS_EVENT_CARD_INSERTION: s->pcmcia_state.present = 1; + destroy_cis_cache(s); /* to be on the safe side... */ pcmcia_card_add(skt); handle_event(skt, event); break; @@ -1366,6 +1368,7 @@ static void pcmcia_bus_remove_socket(struct device *dev, /* unregister any unbound devices */ mutex_lock(&socket->skt_mutex); pcmcia_card_remove(socket, NULL); + release_cis_mem(socket); mutex_unlock(&socket->skt_mutex); pcmcia_put_socket(socket); -- cgit v1.2.3-70-g09d2 From 6e7b51a733fde86d3be748543215a69da04d5bb7 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 6 Jan 2010 13:57:43 +0100 Subject: pcmcia: move cistpl.c into pcmcia module As PCMCIA is the only real user of CIS access functions, include cistpl.c in the PCMCIA module, not in the PCMCIA & CardBus core module. Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/Makefile | 4 +- drivers/pcmcia/cistpl.c | 158 +++++++++++++++++++++++++++++++++++++--- drivers/pcmcia/cs_internal.h | 44 ++++++----- drivers/pcmcia/ds.c | 10 +++ drivers/pcmcia/rsrc_nonstatic.c | 4 +- drivers/pcmcia/socket_sysfs.c | 150 +------------------------------------- 6 files changed, 183 insertions(+), 187 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile index 83ff802de54..3c83f68c803 100644 --- a/drivers/pcmcia/Makefile +++ b/drivers/pcmcia/Makefile @@ -2,11 +2,11 @@ # Makefile for the kernel pcmcia subsystem (c/o David Hinds) # -pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o +pcmcia_core-y += cs.o rsrc_mgr.o socket_sysfs.o pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o obj-$(CONFIG_PCCARD) += pcmcia_core.o -pcmcia-y += ds.o pcmcia_resource.o +pcmcia-y += ds.o pcmcia_resource.o cistpl.o pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o obj-$(CONFIG_PCMCIA) += pcmcia.o diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 368367ced62..936417c3e79 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -76,7 +76,6 @@ void release_cis_mem(struct pcmcia_socket *s) s->cis_virt = NULL; } } -EXPORT_SYMBOL(release_cis_mem); /* * Map the card memory at "card_offset" into virtual space. @@ -195,7 +194,6 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, *(u_char *)(ptr+2), *(u_char *)(ptr+3)); return 0; } -EXPORT_SYMBOL(pcmcia_read_cis_mem); void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, @@ -254,7 +252,6 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, } } } -EXPORT_SYMBOL(pcmcia_write_cis_mem); /*====================================================================== @@ -335,7 +332,6 @@ void destroy_cis_cache(struct pcmcia_socket *s) kfree(cis); } } -EXPORT_SYMBOL(destroy_cis_cache); /*====================================================================== @@ -374,7 +370,6 @@ int verify_cis_cache(struct pcmcia_socket *s) kfree(buf); return 0; } -EXPORT_SYMBOL(verify_cis_cache); /*====================================================================== @@ -400,7 +395,6 @@ int pcmcia_replace_cis(struct pcmcia_socket *s, memcpy(s->fake_cis, data, len); return 0; } -EXPORT_SYMBOL(pcmcia_replace_cis); /*====================================================================== @@ -446,7 +440,6 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple } return pccard_get_next_tuple(s, function, tuple); } -EXPORT_SYMBOL(pccard_get_first_tuple); static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) { @@ -582,7 +575,6 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ tuple->CISOffset = ofs + 2; return 0; } -EXPORT_SYMBOL(pccard_get_next_tuple); /*====================================================================*/ @@ -606,7 +598,6 @@ int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) _MIN(len, tuple->TupleDataMax), tuple->TupleData); return 0; } -EXPORT_SYMBOL(pccard_get_tuple_data); /*====================================================================== @@ -1379,7 +1370,6 @@ done: kfree(buf); return ret; } -EXPORT_SYMBOL(pccard_read_tuple); /** @@ -1439,7 +1429,6 @@ next_entry: kfree(buf); return ret; } -EXPORT_SYMBOL(pccard_loop_tuple); /** @@ -1533,4 +1522,149 @@ done: kfree(p); return ret; } -EXPORT_SYMBOL(pccard_validate_cis); + + +#define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev) + +static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, + loff_t off, size_t count) +{ + tuple_t tuple; + int status, i; + loff_t pointer = 0; + ssize_t ret = 0; + u_char *tuplebuffer; + u_char *tempbuffer; + + tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); + if (!tuplebuffer) + return -ENOMEM; + + tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); + if (!tempbuffer) { + ret = -ENOMEM; + goto free_tuple; + } + + memset(&tuple, 0, sizeof(tuple_t)); + + tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; + tuple.DesiredTuple = RETURN_FIRST_TUPLE; + tuple.TupleOffset = 0; + + status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); + while (!status) { + tuple.TupleData = tuplebuffer; + tuple.TupleDataMax = 255; + memset(tuplebuffer, 0, sizeof(u_char) * 255); + + status = pccard_get_tuple_data(s, &tuple); + if (status) + break; + + if (off < (pointer + 2 + tuple.TupleDataLen)) { + tempbuffer[0] = tuple.TupleCode & 0xff; + tempbuffer[1] = tuple.TupleLink & 0xff; + for (i = 0; i < tuple.TupleDataLen; i++) + tempbuffer[i + 2] = tuplebuffer[i] & 0xff; + + for (i = 0; i < (2 + tuple.TupleDataLen); i++) { + if (((i + pointer) >= off) && + (i + pointer) < (off + count)) { + buf[ret] = tempbuffer[i]; + ret++; + } + } + } + + pointer += 2 + tuple.TupleDataLen; + + if (pointer >= (off + count)) + break; + + if (tuple.TupleCode == CISTPL_END) + break; + status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); + } + + kfree(tempbuffer); + free_tuple: + kfree(tuplebuffer); + + return ret; +} + + +static ssize_t pccard_show_cis(struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) +{ + unsigned int size = 0x200; + + if (off >= size) + count = 0; + else { + struct pcmcia_socket *s; + unsigned int chains; + + if (off + count > size) + count = size - off; + + s = to_socket(container_of(kobj, struct device, kobj)); + + if (!(s->state & SOCKET_PRESENT)) + return -ENODEV; + if (pccard_validate_cis(s, &chains)) + return -EIO; + if (!chains) + return -ENODATA; + + count = pccard_extract_cis(s, buf, off, count); + } + + return count; +} + + +static ssize_t pccard_store_cis(struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) +{ + struct pcmcia_socket *s; + int error; + + s = to_socket(container_of(kobj, struct device, kobj)); + + if (off) + return -EINVAL; + + if (count >= CISTPL_MAX_CIS_SIZE) + return -EINVAL; + + if (!(s->state & SOCKET_PRESENT)) + return -ENODEV; + + error = pcmcia_replace_cis(s, buf, count); + if (error) + return -EIO; + + mutex_lock(&s->skt_mutex); + if ((s->callback) && (s->state & SOCKET_PRESENT) && + !(s->state & SOCKET_CARDBUS)) { + if (try_module_get(s->callback->owner)) { + s->callback->requery(s, 1); + module_put(s->callback->owner); + } + } + mutex_unlock(&s->skt_mutex); + + return count; +} + + +struct bin_attribute pccard_cis_attr = { + .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, + .size = 0x200, + .read = pccard_show_cis, + .write = pccard_store_cis, +}; diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index ad05e3b5947..3f438afdcd4 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -92,9 +92,6 @@ struct pccard_resource_ops { * Stuff internal to module "pcmcia_core": */ -/* cistpl.c */ -int verify_cis_cache(struct pcmcia_socket *s); - /* socket_sysfs.c */ extern int pccard_sysfs_add_socket(struct device *dev); extern void pccard_sysfs_remove_socket(struct device *dev); @@ -102,8 +99,6 @@ extern void pccard_sysfs_remove_socket(struct device *dev); /* cardbus.c */ int cb_alloc(struct pcmcia_socket *s); void cb_free(struct pcmcia_socket *s); -int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, - void *ptr); @@ -116,6 +111,7 @@ struct pcmcia_callback{ int (*event) (struct pcmcia_socket *s, event_t event, int priority); void (*requery) (struct pcmcia_socket *s, int new_cis); + int (*validate) (struct pcmcia_socket *s, unsigned int *i); int (*suspend) (struct pcmcia_socket *s); int (*resume) (struct pcmcia_socket *s); }; @@ -137,7 +133,26 @@ int pcmcia_insert_card(struct pcmcia_socket *skt); struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt); void pcmcia_put_socket(struct pcmcia_socket *skt); +/* rsrc_mgr.c */ +int pcmcia_validate_mem(struct pcmcia_socket *s); +struct resource *pcmcia_find_mem_region(u_long base, + u_long num, + u_long align, + int low, + struct pcmcia_socket *s); + +/* + * Stuff internal to module "pcmcia". + */ +/* ds.c */ +extern struct bus_type pcmcia_bus_type; + +/* pcmcia_resource.c */ +extern int pcmcia_release_configuration(struct pcmcia_device *p_dev); + /* cistpl.c */ +extern struct bin_attribute pccard_cis_attr; + int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, u_int len, void *ptr); void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, @@ -149,8 +164,8 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, int pcmcia_replace_cis(struct pcmcia_socket *s, const u8 *data, const size_t len); int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count); +int verify_cis_cache(struct pcmcia_socket *s); -/* loop over CIS entries */ int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, cisparse_t *parse, void *priv_data, int (*loop_tuple) (tuple_t *tuple, @@ -166,23 +181,6 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); -/* rsrc_mgr.c */ -int pcmcia_validate_mem(struct pcmcia_socket *s); -struct resource *pcmcia_find_mem_region(u_long base, - u_long num, - u_long align, - int low, - struct pcmcia_socket *s); - -/* - * Stuff internal to module "pcmcia". - */ -/* ds.c */ -extern struct bus_type pcmcia_bus_type; - -/* pcmcia_resource.c */ -extern int pcmcia_release_configuration(struct pcmcia_device *p_dev); - #ifdef CONFIG_PCMCIA_IOCTL /* ds.c */ extern spinlock_t pcmcia_dev_list_lock; diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 7bb52b003f0..0ab4fe04592 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -1313,6 +1313,7 @@ static struct pcmcia_callback pcmcia_bus_callback = { .owner = THIS_MODULE, .event = ds_event, .requery = pcmcia_bus_rescan, + .validate = pccard_validate_cis, .suspend = pcmcia_bus_suspend, .resume = pcmcia_bus_resume, }; @@ -1336,6 +1337,13 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev, */ msleep(250); + ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); + if (ret) { + dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n"); + pcmcia_put_socket(socket); + return ret; + } + #ifdef CONFIG_PCMCIA_IOCTL init_waitqueue_head(&socket->queue); #endif @@ -1371,6 +1379,8 @@ static void pcmcia_bus_remove_socket(struct device *dev, release_cis_mem(socket); mutex_unlock(&socket->skt_mutex); + sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); + pcmcia_put_socket(socket); return; diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 120d5ad9929..91626c17f97 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -277,7 +277,9 @@ static int readable(struct pcmcia_socket *s, struct resource *res, s->cis_mem.res = res; s->cis_virt = ioremap(res->start, s->map_size); if (s->cis_virt) { - ret = pccard_validate_cis(s, count); + /* as we're only called from pcmcia.c, we're safe */ + if (s->callback->validate) + ret = s->callback->validate(s, count); /* invalidate mapping */ iounmap(s->cis_virt); s->cis_virt = NULL; diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 7a456000332..537d79305e7 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -213,138 +213,6 @@ static ssize_t pccard_store_resource(struct device *dev, } static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource); - -static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count) -{ - tuple_t tuple; - int status, i; - loff_t pointer = 0; - ssize_t ret = 0; - u_char *tuplebuffer; - u_char *tempbuffer; - - tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); - if (!tuplebuffer) - return -ENOMEM; - - tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); - if (!tempbuffer) { - ret = -ENOMEM; - goto free_tuple; - } - - memset(&tuple, 0, sizeof(tuple_t)); - - tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; - tuple.DesiredTuple = RETURN_FIRST_TUPLE; - tuple.TupleOffset = 0; - - status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); - while (!status) { - tuple.TupleData = tuplebuffer; - tuple.TupleDataMax = 255; - memset(tuplebuffer, 0, sizeof(u_char) * 255); - - status = pccard_get_tuple_data(s, &tuple); - if (status) - break; - - if (off < (pointer + 2 + tuple.TupleDataLen)) { - tempbuffer[0] = tuple.TupleCode & 0xff; - tempbuffer[1] = tuple.TupleLink & 0xff; - for (i = 0; i < tuple.TupleDataLen; i++) - tempbuffer[i + 2] = tuplebuffer[i] & 0xff; - - for (i = 0; i < (2 + tuple.TupleDataLen); i++) { - if (((i + pointer) >= off) && - (i + pointer) < (off + count)) { - buf[ret] = tempbuffer[i]; - ret++; - } - } - } - - pointer += 2 + tuple.TupleDataLen; - - if (pointer >= (off + count)) - break; - - if (tuple.TupleCode == CISTPL_END) - break; - status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); - } - - kfree(tempbuffer); - free_tuple: - kfree(tuplebuffer); - - return ret; -} - -static ssize_t pccard_show_cis(struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) -{ - unsigned int size = 0x200; - - if (off >= size) - count = 0; - else { - struct pcmcia_socket *s; - unsigned int chains; - - if (off + count > size) - count = size - off; - - s = to_socket(container_of(kobj, struct device, kobj)); - - if (!(s->state & SOCKET_PRESENT)) - return -ENODEV; - if (pccard_validate_cis(s, &chains)) - return -EIO; - if (!chains) - return -ENODATA; - - count = pccard_extract_cis(s, buf, off, count); - } - - return count; -} - -static ssize_t pccard_store_cis(struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) -{ - struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj)); - int error; - - if (off) - return -EINVAL; - - if (count >= CISTPL_MAX_CIS_SIZE) - return -EINVAL; - - if (!(s->state & SOCKET_PRESENT)) - return -ENODEV; - - error = pcmcia_replace_cis(s, buf, count); - if (error) - return -EIO; - - mutex_lock(&s->skt_mutex); - if ((s->callback) && (s->state & SOCKET_PRESENT) && - !(s->state & SOCKET_CARDBUS)) { - if (try_module_get(s->callback->owner)) { - s->callback->requery(s, 1); - module_put(s->callback->owner); - } - } - mutex_unlock(&s->skt_mutex); - - return count; -} - - static struct attribute *pccard_socket_attributes[] = { &dev_attr_card_type.attr, &dev_attr_card_voltage.attr, @@ -362,28 +230,12 @@ static const struct attribute_group socket_attrs = { .attrs = pccard_socket_attributes, }; -static struct bin_attribute pccard_cis_attr = { - .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, - .size = 0x200, - .read = pccard_show_cis, - .write = pccard_store_cis, -}; - int pccard_sysfs_add_socket(struct device *dev) { - int ret = 0; - - ret = sysfs_create_group(&dev->kobj, &socket_attrs); - if (!ret) { - ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); - if (ret) - sysfs_remove_group(&dev->kobj, &socket_attrs); - } - return ret; + return sysfs_create_group(&dev->kobj, &socket_attrs); } void pccard_sysfs_remove_socket(struct device *dev) { - sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); sysfs_remove_group(&dev->kobj, &socket_attrs); } -- cgit v1.2.3-70-g09d2 From 8680c4b3faa298dc768c2a78a94a84d89854eca9 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Tue, 12 Jan 2010 22:05:36 +0100 Subject: 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: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cistpl.c | 18 +++++++++++++++++- drivers/pcmcia/ds.c | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 9ad66c9848e..14de287a8bf 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -277,20 +277,24 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, if (s->state & SOCKET_CARDBUS) return; + mutex_lock(&s->ops_mutex); if (s->fake_cis) { if (s->fake_cis_len >= addr+len) memcpy(ptr, s->fake_cis+addr, len); else memset(ptr, 0xff, len); + mutex_unlock(&s->ops_mutex); return; } list_for_each_entry(cis, &s->cis_cache, node) { if (cis->addr == addr && cis->len == len && cis->attr == attr) { memcpy(ptr, cis->cache, len); + mutex_unlock(&s->ops_mutex); return; } } + mutex_unlock(&s->ops_mutex); 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, cis->len = len; cis->attr = attr; memcpy(cis->cache, ptr, len); + mutex_lock(&s->ops_mutex); 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) { struct cis_cache_entry *cis; + mutex_lock(&s->ops_mutex); list_for_each_entry(cis, &s->cis_cache, node) if (cis->addr == addr && cis->len == len && cis->attr == attr) { list_del(&cis->node); kfree(cis); break; } + mutex_unlock(&s->ops_mutex); } /** * destroy_cis_cache() - destroy the CIS cache * @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) @@ -391,14 +400,17 @@ int pcmcia_replace_cis(struct pcmcia_socket *s, dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); return -EINVAL; } + mutex_lock(&s->ops_mutex); kfree(s->fake_cis); s->fake_cis = kmalloc(len, GFP_KERNEL); if (s->fake_cis == NULL) { dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); + mutex_unlock(&s->ops_mutex); return -ENOMEM; } s->fake_cis_len = len; memcpy(s->fake_cis, data, len); + mutex_unlock(&s->ops_mutex); return 0; } @@ -1461,7 +1473,9 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) return -EINVAL; /* We do not want to validate the CIS cache... */ + mutex_lock(&s->ops_mutex); destroy_cis_cache(s); + mutex_unlock(&s->ops_mutex); tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); if (tuple == NULL) { @@ -1518,7 +1532,9 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) done: /* invalidate CIS cache on failure */ if (!dev_ok || !ident_ok || !count) { + mutex_lock(&s->ops_mutex); destroy_cis_cache(s); + mutex_unlock(&s->ops_mutex); ret = -EIO; } diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 0ab4fe04592..4f7308df22c 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -1241,12 +1241,16 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) s->pcmcia_state.present = 0; pcmcia_card_remove(skt, NULL); handle_event(skt, event); + mutex_lock(&s->ops_mutex); destroy_cis_cache(s); + mutex_unlock(&s->ops_mutex); break; case CS_EVENT_CARD_INSERTION: s->pcmcia_state.present = 1; + mutex_lock(&s->ops_mutex); destroy_cis_cache(s); /* to be on the safe side... */ + mutex_unlock(&s->ops_mutex); pcmcia_card_add(skt); handle_event(skt, event); break; @@ -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"); /* first, remove the card */ ds_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); + mutex_lock(&s->ops_mutex); destroy_cis_cache(skt); kfree(skt->fake_cis); skt->fake_cis = NULL; + mutex_unlock(&s->ops_mutex); /* now, add the new card */ ds_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); -- cgit v1.2.3-70-g09d2 From e6e4f397e5d0970ee1bb7a5591ac93b37cfa524a Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 16 Jan 2010 01:34:06 +0100 Subject: pcmcia: protect s->device_count Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 4f7308df22c..bcb9ef10342 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -265,6 +265,7 @@ static int pcmcia_device_probe(struct device *dev) struct pcmcia_device_id *did; struct pcmcia_socket *s; cistpl_config_t cis_config; + unsigned long flags; int ret = 0; dev = get_device(dev); @@ -315,9 +316,11 @@ static int pcmcia_device_probe(struct device *dev) goto put_module; } + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) pcmcia_add_device_later(p_dev->socket, 0); + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); put_module: if (ret) @@ -342,10 +345,12 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le "pcmcia_card_remove(%d) %s\n", s->sock, leftover ? leftover->devname : ""); + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); if (!leftover) s->device_count = 0; else s->device_count = 1; + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); /* unregister all pcmcia_devices registered with this socket, except leftover */ list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) { @@ -382,7 +387,7 @@ static int pcmcia_device_remove(struct device *dev) */ did = dev_get_drvdata(&p_dev->dev); if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && - (p_dev->socket->device_count != 0) && + (p_dev->socket->device_count > 0) && (p_dev->device_no == 0)) pcmcia_card_remove(p_dev->socket, p_dev); @@ -512,16 +517,19 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu pr_debug("adding device to %d, function %d\n", s->sock, function); - /* max of 4 devices per card */ - if (s->device_count == 4) - goto err_put; - p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL); if (!p_dev) goto err_put; - p_dev->socket = s; + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); p_dev->device_no = (s->device_count++); + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + + /* max of 4 devices per card */ + if (p_dev->device_no >= 4) + goto err_free; + + p_dev->socket = s; p_dev->func = function; p_dev->dev.bus = &pcmcia_bus_type; @@ -586,9 +594,12 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); err_free: + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + s->device_count--; + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + kfree(p_dev->devname); kfree(p_dev); - s->device_count--; err_put: mutex_unlock(&device_add_lock); pcmcia_put_socket(s); -- cgit v1.2.3-70-g09d2 From 3d3de32fad19e37695e6649136e4cb17f9d46329 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 16 Jan 2010 08:32:56 +0100 Subject: pcmcia: add locking to struct pcmcia_socket->pcmcia_state() Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index bcb9ef10342..0eb242cbed1 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -649,10 +649,17 @@ static void pcmcia_delayed_add_device(struct work_struct *work) { struct pcmcia_socket *s = container_of(work, struct pcmcia_socket, device_add); - dev_dbg(&s->dev, "adding additional device to %d\n", s->sock); - pcmcia_device_add(s, s->pcmcia_state.mfc_pfc); + u8 mfc_pfc; + unsigned long flags; + + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mfc_pfc = s->pcmcia_state.mfc_pfc; s->pcmcia_state.device_add_pending = 0; s->pcmcia_state.mfc_pfc = 0; + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + + dev_dbg(&s->dev, "adding additional device to %d\n", s->sock); + pcmcia_device_add(s, mfc_pfc); } static int pcmcia_requery(struct device *dev, void * _data) @@ -761,8 +768,13 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) if (old_funcs > no_funcs) pcmcia_card_remove(s, dev); - else if (no_funcs > old_funcs) + else if (no_funcs > old_funcs) { + unsigned long flags; + + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); pcmcia_add_device_later(s, 1); + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + } } release: release_firmware(fw); @@ -1236,6 +1248,7 @@ static int pcmcia_bus_suspend(struct pcmcia_socket *skt) static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) { struct pcmcia_socket *s = pcmcia_get_socket(skt); + unsigned long flags; if (!s) { dev_printk(KERN_ERR, &skt->dev, @@ -1249,7 +1262,9 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) switch (event) { case CS_EVENT_CARD_REMOVAL: + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); s->pcmcia_state.present = 0; + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); pcmcia_card_remove(skt, NULL); handle_event(skt, event); mutex_lock(&s->ops_mutex); @@ -1258,7 +1273,9 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) break; case CS_EVENT_CARD_INSERTION: + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); s->pcmcia_state.present = 1; + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); mutex_lock(&s->ops_mutex); destroy_cis_cache(s); /* to be on the safe side... */ mutex_unlock(&s->ops_mutex); @@ -1304,14 +1321,19 @@ struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *_p_dev) { struct pcmcia_device *p_dev; struct pcmcia_device *ret = NULL; + unsigned long flags; p_dev = pcmcia_get_dev(_p_dev); if (!p_dev) return NULL; + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); if (!p_dev->socket->pcmcia_state.present) goto out; + if (p_dev->socket->pcmcia_state.dead) + goto out; + if (p_dev->_removed) goto out; @@ -1320,6 +1342,7 @@ struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *_p_dev) ret = p_dev; out: + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); pcmcia_put_dev(p_dev); return ret; } @@ -1383,11 +1406,15 @@ static void pcmcia_bus_remove_socket(struct device *dev, struct class_interface *class_intf) { struct pcmcia_socket *socket = dev_get_drvdata(dev); + unsigned long flags; if (!socket) return; + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); socket->pcmcia_state.dead = 1; + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + pccard_register_pcmcia(socket, NULL); /* unregister any unbound devices */ -- cgit v1.2.3-70-g09d2 From 00ce99ff506a17882747a7d6874e3f5206a99043 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 16 Jan 2010 09:14:11 +0100 Subject: pcmcia: simplify locking replace pcmcia_socket->lock and pcmcia_dev_list_lock by using the per-socket "ops_mutex", as we do neither need different locks nor a spinlock here. Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs.c | 2 -- drivers/pcmcia/cs_internal.h | 2 -- drivers/pcmcia/ds.c | 70 +++++++++++++++++-------------------------- drivers/pcmcia/pcmcia_ioctl.c | 36 ++++++++++------------ drivers/pcmcia/rsrc_mgr.c | 6 ++-- drivers/pcmcia/socket_sysfs.c | 5 ++-- include/pcmcia/ss.h | 7 +++-- 7 files changed, 51 insertions(+), 77 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index cc0ba8aef59..13277eebe46 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -175,8 +175,6 @@ int pcmcia_register_socket(struct pcmcia_socket *socket) dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops); - spin_lock_init(&socket->lock); - /* try to obtain a socket number [yes, it gets ugly if we * register more than 2^sizeof(unsigned int) pcmcia * sockets... but the socket number is deprecated diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 76ac4444f0e..bd386d77845 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -182,8 +182,6 @@ int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); #ifdef CONFIG_PCMCIA_IOCTL /* ds.c */ -extern spinlock_t pcmcia_dev_list_lock; - extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev); extern void pcmcia_put_dev(struct pcmcia_device *p_dev); diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 0eb242cbed1..4c40db8889d 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -42,8 +42,6 @@ MODULE_DESCRIPTION("PCMCIA Driver Services"); MODULE_LICENSE("GPL"); -spinlock_t pcmcia_dev_list_lock; - /*====================================================================*/ static void pcmcia_check_driver(struct pcmcia_driver *p_drv) @@ -265,7 +263,6 @@ static int pcmcia_device_probe(struct device *dev) struct pcmcia_device_id *did; struct pcmcia_socket *s; cistpl_config_t cis_config; - unsigned long flags; int ret = 0; dev = get_device(dev); @@ -316,11 +313,11 @@ static int pcmcia_device_probe(struct device *dev) goto put_module; } - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) pcmcia_add_device_later(p_dev->socket, 0); - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); put_module: if (ret) @@ -339,28 +336,27 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le { struct pcmcia_device *p_dev; struct pcmcia_device *tmp; - unsigned long flags; dev_dbg(leftover ? &leftover->dev : &s->dev, "pcmcia_card_remove(%d) %s\n", s->sock, leftover ? leftover->devname : ""); - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); if (!leftover) s->device_count = 0; else s->device_count = 1; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); /* unregister all pcmcia_devices registered with this socket, except leftover */ list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) { if (p_dev == leftover) continue; - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); list_del(&p_dev->socket_device_list); p_dev->_removed = 1; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); dev_dbg(&p_dev->dev, "unregistering device\n"); device_unregister(&p_dev->dev); @@ -507,7 +503,6 @@ static DEFINE_MUTEX(device_add_lock); struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) { struct pcmcia_device *p_dev, *tmp_dev; - unsigned long flags; s = pcmcia_get_socket(s); if (!s) @@ -521,9 +516,9 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu if (!p_dev) goto err_put; - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); p_dev->device_no = (s->device_count++); - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); /* max of 4 devices per card */ if (p_dev->device_no >= 4) @@ -546,7 +541,7 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu goto err_free; dev_dbg(&p_dev->dev, "devname is %s\n", p_dev->devname); - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); /* * p_dev->function_config must be the same for all card functions. @@ -564,7 +559,7 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu /* Add to the list in pcmcia_bus_socket */ list_add(&p_dev->socket_device_list, &s->devices_list); - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); if (!p_dev->function_config) { dev_dbg(&p_dev->dev, "creating config_t\n"); @@ -589,14 +584,14 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu return p_dev; err_unreg: - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); list_del(&p_dev->socket_device_list); - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); err_free: - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); s->device_count--; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); kfree(p_dev->devname); kfree(p_dev); @@ -650,13 +645,12 @@ static void pcmcia_delayed_add_device(struct work_struct *work) struct pcmcia_socket *s = container_of(work, struct pcmcia_socket, device_add); u8 mfc_pfc; - unsigned long flags; - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); mfc_pfc = s->pcmcia_state.mfc_pfc; s->pcmcia_state.device_add_pending = 0; s->pcmcia_state.mfc_pfc = 0; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); dev_dbg(&s->dev, "adding additional device to %d\n", s->sock); pcmcia_device_add(s, mfc_pfc); @@ -677,15 +671,14 @@ static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis) { int no_devices = 0; int ret = 0; - unsigned long flags; /* must be called with skt_mutex held */ dev_dbg(&skt->dev, "re-scanning socket %d\n", skt->sock); - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&skt->ops_mutex); if (list_empty(&skt->devices_list)) no_devices = 1; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&skt->ops_mutex); /* If this is because of a CIS override, start over */ if (new_cis && !no_devices) @@ -769,11 +762,9 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) if (old_funcs > no_funcs) pcmcia_card_remove(s, dev); else if (no_funcs > old_funcs) { - unsigned long flags; - - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); pcmcia_add_device_later(s, 1); - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); } } release: @@ -1248,7 +1239,6 @@ static int pcmcia_bus_suspend(struct pcmcia_socket *skt) static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) { struct pcmcia_socket *s = pcmcia_get_socket(skt); - unsigned long flags; if (!s) { dev_printk(KERN_ERR, &skt->dev, @@ -1262,9 +1252,9 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) switch (event) { case CS_EVENT_CARD_REMOVAL: - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); s->pcmcia_state.present = 0; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); pcmcia_card_remove(skt, NULL); handle_event(skt, event); mutex_lock(&s->ops_mutex); @@ -1273,10 +1263,8 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) break; case CS_EVENT_CARD_INSERTION: - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); - s->pcmcia_state.present = 1; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); mutex_lock(&s->ops_mutex); + s->pcmcia_state.present = 1; destroy_cis_cache(s); /* to be on the safe side... */ mutex_unlock(&s->ops_mutex); pcmcia_card_add(skt); @@ -1321,13 +1309,12 @@ struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *_p_dev) { struct pcmcia_device *p_dev; struct pcmcia_device *ret = NULL; - unsigned long flags; p_dev = pcmcia_get_dev(_p_dev); if (!p_dev) return NULL; - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&p_dev->socket->ops_mutex); if (!p_dev->socket->pcmcia_state.present) goto out; @@ -1342,7 +1329,7 @@ struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *_p_dev) ret = p_dev; out: - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&p_dev->socket->ops_mutex); pcmcia_put_dev(p_dev); return ret; } @@ -1406,14 +1393,13 @@ static void pcmcia_bus_remove_socket(struct device *dev, struct class_interface *class_intf) { struct pcmcia_socket *socket = dev_get_drvdata(dev); - unsigned long flags; if (!socket) return; - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&socket->ops_mutex); socket->pcmcia_state.dead = 1; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&socket->ops_mutex); pccard_register_pcmcia(socket, NULL); @@ -1455,8 +1441,6 @@ static int __init init_pcmcia_bus(void) { int ret; - spin_lock_init(&pcmcia_dev_list_lock); - ret = bus_register(&pcmcia_bus_type); if (ret < 0) { printk(KERN_WARNING "pcmcia: bus_register error: %d\n", ret); diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c index f73fd5beaa3..db2e3db8008 100644 --- a/drivers/pcmcia/pcmcia_ioctl.c +++ b/drivers/pcmcia/pcmcia_ioctl.c @@ -62,16 +62,15 @@ static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s, unsigned int function) { struct pcmcia_device *p_dev = NULL; - unsigned long flags; - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { if (p_dev->func == function) { - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); return pcmcia_get_dev(p_dev); } } - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); return NULL; } @@ -169,7 +168,6 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) { struct pcmcia_socket *s; int ret = -ENOSYS; - unsigned long flags; down_read(&pcmcia_socket_list_rwsem); list_for_each_entry(s, &pcmcia_socket_list, socket_list) { @@ -182,14 +180,14 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) /* you can't use the old interface if the new * one was used before */ - spin_lock_irqsave(&s->lock, flags); + mutex_lock(&s->ops_mutex); if ((s->resource_setup_new) && !(s->resource_setup_old)) { - spin_unlock_irqrestore(&s->lock, flags); + mutex_unlock(&s->ops_mutex); continue; } else if (!(s->resource_setup_old)) s->resource_setup_old = 1; - spin_unlock_irqrestore(&s->lock, flags); + mutex_unlock(&s->ops_mutex); switch (adj->Resource) { case RES_MEMORY_RANGE: @@ -208,9 +206,9 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) * last call to adjust_resource_info, we * always need to assume this is the latest * one... */ - spin_lock_irqsave(&s->lock, flags); + mutex_lock(&s->ops_mutex); s->resource_setup_done = 1; - spin_unlock_irqrestore(&s->lock, flags); + mutex_unlock(&s->ops_mutex); } } } @@ -470,7 +468,6 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) struct pcmcia_driver *p_drv; struct pcmcia_device *p_dev; int ret = 0; - unsigned long flags; s = pcmcia_get_socket(s); if (!s) @@ -490,7 +487,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) goto err_put_driver; } - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { if (p_dev->func == bind_info->function) { if ((p_dev->dev.driver == &p_drv->drv)) { @@ -499,7 +496,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) * registered, and it was registered * by userspace before, we need to * return the "instance". */ - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); bind_info->instance = p_dev; ret = -EBUSY; goto err_put_module; @@ -507,7 +504,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) /* the correct driver managed to bind * itself magically to the correct * device. */ - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); p_dev->cardmgr = p_drv; ret = 0; goto err_put_module; @@ -516,12 +513,12 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) /* there's already a device available where * no device has been bound to yet. So we don't * need to register a device! */ - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); goto rescan; } } } - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); p_dev = pcmcia_device_add(s, bind_info->function); if (!p_dev) { @@ -578,7 +575,6 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int dev_node_t *node; struct pcmcia_device *p_dev; struct pcmcia_driver *p_drv; - unsigned long flags; int ret = 0; #ifdef CONFIG_CARDBUS @@ -617,7 +613,7 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int } #endif - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + mutex_lock(&s->ops_mutex); list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { if (p_dev->func == bind_info->function) { p_dev = pcmcia_get_dev(p_dev); @@ -626,11 +622,11 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int goto found; } } - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); return -ENODEV; found: - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + mutex_unlock(&s->ops_mutex); p_drv = to_pcmcia_drv(p_dev->dev.driver); if (p_drv && !p_dev->_locked) { diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index cdd30c18006..b81586622d0 100644 --- a/drivers/pcmcia/rsrc_mgr.c +++ b/drivers/pcmcia/rsrc_mgr.c @@ -23,14 +23,12 @@ static int static_init(struct pcmcia_socket *s) { - unsigned long flags; - /* the good thing about SS_CAP_STATIC_MAP sockets is * that they don't need a resource database */ - spin_lock_irqsave(&s->lock, flags); + mutex_lock(&s->ops_mutex); s->resource_setup_done = 1; - spin_unlock_irqrestore(&s->lock, flags); + mutex_unlock(&s->ops_mutex); return 0; } diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 1cba9d38d81..e8826df00a3 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -189,16 +189,15 @@ static ssize_t pccard_store_resource(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - unsigned long flags; struct pcmcia_socket *s = to_socket(dev); if (!count) return -EINVAL; - spin_lock_irqsave(&s->lock, flags); + mutex_lock(&s->ops_mutex); if (!s->resource_setup_done) s->resource_setup_done = 1; - spin_unlock_irqrestore(&s->lock, flags); + mutex_unlock(&s->ops_mutex); mutex_lock(&s->skt_mutex); if ((s->callback) && diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h index e756069859b..cfaccc224b5 100644 --- a/include/pcmcia/ss.h +++ b/include/pcmcia/ss.h @@ -134,7 +134,6 @@ struct pccard_operations { struct pcmcia_socket { struct module *owner; - spinlock_t lock; socket_state_t socket; u_int state; u_int suspended_state; /* state before suspend */ @@ -201,10 +200,12 @@ struct pcmcia_socket { struct task_struct *thread; struct completion thread_done; unsigned int thread_events; - /* protects socket h/w state */ + + /* For the non-trivial interaction between these locks, + * see Documentation/pcmcia/locking.txt */ struct mutex skt_mutex; - /* protects PCMCIA state */ struct mutex ops_mutex; + /* protects thread_events */ spinlock_t thread_lock; -- cgit v1.2.3-70-g09d2 From 94a819f80297e1f635a7cde4ed5317612e512ba7 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 17 Jan 2010 18:31:34 +0100 Subject: pcmcia: assert locking to struct pcmcia_device Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- Documentation/pcmcia/locking.txt | 25 ++++++++ drivers/pcmcia/ds.c | 38 ++++++++---- drivers/pcmcia/pcmcia_resource.c | 122 ++++++++++++++++++++++++--------------- 3 files changed, 129 insertions(+), 56 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/Documentation/pcmcia/locking.txt b/Documentation/pcmcia/locking.txt index 5f25de4cdb4..d6251056128 100644 --- a/Documentation/pcmcia/locking.txt +++ b/Documentation/pcmcia/locking.txt @@ -90,3 +90,28 @@ or single-use fields not mentioned): struct list_head devices_list; u8 device_count; struct pcmcia_state; + + +3. Per PCMCIA-device Data: +-------------------------- + +The "main" struct pcmcia_devie is protected as follows (read-only fields +or single-use fields not mentioned): + + +- by pcmcia_socket->ops_mutex: + struct list_head socket_device_list; + struct config_t *function_config; + u16 _irq:1; + u16 _io:1; + u16 _win:4; + u16 _locked:1; + u16 allow_func_id_match:1; + u16 suspended:1; + u16 _removed:1; + +- by the PCMCIA driver: + io_req_t io; + irq_req_t irq; + config_req_t conf; + window_handle_t win; diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 4c40db8889d..83b51ddd3da 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -835,6 +835,8 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, } if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) { + int ret; + if ((!dev->has_func_id) || (dev->func_id != did->func_id)) return 0; @@ -849,10 +851,15 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, * after it has re-checked that there is no possible module * with a prod_id/manf_id/card_id match. */ - dev_dbg(&dev->dev, - "skipping FUNC_ID match until userspace interaction\n"); - if (!dev->allow_func_id_match) + mutex_lock(&dev->socket->ops_mutex); + ret = dev->allow_func_id_match; + mutex_unlock(&dev->socket->ops_mutex); + + if (!ret) { + dev_dbg(&dev->dev, + "skipping FUNC_ID match until userspace ACK\n"); return 0; + } } if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { @@ -1079,9 +1086,9 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev, if (!count) return -EINVAL; - mutex_lock(&p_dev->socket->skt_mutex); + mutex_lock(&p_dev->socket->ops_mutex); p_dev->allow_func_id_match = 1; - mutex_unlock(&p_dev->socket->skt_mutex); + mutex_unlock(&p_dev->socket->ops_mutex); ret = bus_rescan_devices(&pcmcia_bus_type); if (ret) @@ -1114,8 +1121,13 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state) struct pcmcia_driver *p_drv = NULL; int ret = 0; - if (p_dev->suspended) + mutex_lock(&p_dev->socket->ops_mutex); + if (p_dev->suspended) { + mutex_unlock(&p_dev->socket->ops_mutex); return 0; + } + p_dev->suspended = 1; + mutex_unlock(&p_dev->socket->ops_mutex); dev_dbg(dev, "suspending\n"); @@ -1132,6 +1144,9 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state) "pcmcia: device %s (driver %s) did " "not want to go to sleep (%d)\n", p_dev->devname, p_drv->drv.name, ret); + mutex_lock(&p_dev->socket->ops_mutex); + p_dev->suspended = 0; + mutex_unlock(&p_dev->socket->ops_mutex); goto out; } } @@ -1142,8 +1157,6 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state) } out: - if (!ret) - p_dev->suspended = 1; return ret; } @@ -1154,8 +1167,13 @@ static int pcmcia_dev_resume(struct device *dev) struct pcmcia_driver *p_drv = NULL; int ret = 0; - if (!p_dev->suspended) + mutex_lock(&p_dev->socket->ops_mutex); + if (!p_dev->suspended) { + mutex_unlock(&p_dev->socket->ops_mutex); return 0; + } + p_dev->suspended = 0; + mutex_unlock(&p_dev->socket->ops_mutex); dev_dbg(dev, "resuming\n"); @@ -1176,8 +1194,6 @@ static int pcmcia_dev_resume(struct device *dev) ret = p_drv->resume(p_dev); out: - if (!ret) - p_dev->suspended = 0; return ret; } diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index f0de7b8b123..b2df04199a2 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -191,14 +191,18 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, return -EINVAL; s = p_dev->socket; + + mutex_lock(&s->ops_mutex); c = p_dev->function_config; if (!(c->state & CONFIG_LOCKED)) { dev_dbg(&s->dev, "Configuration isnt't locked\n"); + mutex_unlock(&s->ops_mutex); return -EACCES; } addr = (c->ConfigBase + reg->Offset) >> 1; + mutex_unlock(&s->ops_mutex); switch (reg->Action) { case CS_READ: @@ -254,19 +258,22 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, config_t *c; s = p_dev->socket; + + mutex_lock(&s->ops_mutex); c = p_dev->function_config; if (!(s->state & SOCKET_PRESENT)) { dev_dbg(&s->dev, "No card present\n"); + mutex_unlock(&s->ops_mutex); return -ENODEV; } if (!(c->state & CONFIG_LOCKED)) { dev_dbg(&s->dev, "Configuration isnt't locked\n"); + mutex_unlock(&s->ops_mutex); return -EACCES; } if (mod->Attributes & CONF_IRQ_CHANGE_VALID) { - mutex_lock(&s->ops_mutex); if (mod->Attributes & CONF_ENABLE_IRQ) { c->Attributes |= CONF_ENABLE_IRQ; s->socket.io_irq = s->irq.AssignedIRQ; @@ -275,7 +282,6 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, s->socket.io_irq = 0; } s->ops->set_socket(s, &s->socket); - mutex_unlock(&s->ops_mutex); } if (mod->Attributes & CONF_VCC_CHANGE_VALID) { @@ -288,9 +294,9 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { if (mod->Vpp1 != mod->Vpp2) { dev_dbg(&s->dev, "Vpp1 and Vpp2 must be the same\n"); + mutex_unlock(&s->ops_mutex); return -EINVAL; } - mutex_lock(&s->ops_mutex); s->socket.Vpp = mod->Vpp1; if (s->ops->set_socket(s, &s->socket)) { mutex_unlock(&s->ops_mutex); @@ -298,10 +304,10 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, "Unable to set VPP\n"); return -EIO; } - mutex_unlock(&s->ops_mutex); } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { dev_dbg(&s->dev, "changing Vcc is not allowed at this time\n"); + mutex_unlock(&s->ops_mutex); return -EINVAL; } @@ -311,7 +317,6 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, int i; io_on.speed = io_speed; - mutex_lock(&s->ops_mutex); for (i = 0; i < MAX_IO_WIN; i++) { if (!s->io[i].res) continue; @@ -326,8 +331,8 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, mdelay(40); s->ops->set_io_map(s, &io_on); } - mutex_unlock(&s->ops_mutex); } + mutex_unlock(&s->ops_mutex); return 0; } /* modify_configuration */ @@ -338,10 +343,11 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev) { pccard_io_map io = { 0, 0, 0, 0, 1 }; struct pcmcia_socket *s = p_dev->socket; - config_t *c = p_dev->function_config; + config_t *c; int i; mutex_lock(&s->ops_mutex); + c = p_dev->function_config; if (p_dev->_locked) { p_dev->_locked = 0; if (--(s->lock_count) == 0) { @@ -381,10 +387,14 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev) static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) { struct pcmcia_socket *s = p_dev->socket; - config_t *c = p_dev->function_config; + int ret = -EINVAL; + config_t *c; + + mutex_lock(&s->ops_mutex); + c = p_dev->function_config; if (!p_dev->_io) - return -EINVAL; + goto out; p_dev->_io = 0; @@ -392,7 +402,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) (c->io.NumPorts1 != req->NumPorts1) || (c->io.BasePort2 != req->BasePort2) || (c->io.NumPorts2 != req->NumPorts2)) - return -EINVAL; + goto out; c->state &= ~CONFIG_IO_REQ; @@ -400,30 +410,38 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) if (req->NumPorts2) release_io_space(s, req->BasePort2, req->NumPorts2); - return 0; +out: + mutex_unlock(&s->ops_mutex); + + return ret; } /* pcmcia_release_io */ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) { struct pcmcia_socket *s = p_dev->socket; - config_t *c = p_dev->function_config; + config_t *c; + int ret = -EINVAL; + + mutex_lock(&s->ops_mutex); + + c = p_dev->function_config; if (!p_dev->_irq) - return -EINVAL; + goto out; + p_dev->_irq = 0; if (c->state & CONFIG_LOCKED) - return -EACCES; + goto out; + if (c->irq.Attributes != req->Attributes) { dev_dbg(&s->dev, "IRQ attributes must match assigned ones\n"); - return -EINVAL; + goto out; } - mutex_lock(&s->ops_mutex); if (s->irq.AssignedIRQ != req->AssignedIRQ) { - mutex_unlock(&s->ops_mutex); dev_dbg(&s->dev, "IRQ must match assigned one\n"); - return -EINVAL; + goto out; } if (--s->irq.Config == 0) { c->state &= ~CONFIG_IRQ_REQ; @@ -436,9 +454,12 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) #ifdef CONFIG_PCMCIA_PROBE pcmcia_used_irq[req->AssignedIRQ]--; #endif + ret = 0; + +out: mutex_unlock(&s->ops_mutex); - return 0; + return ret; } /* pcmcia_release_irq */ @@ -495,13 +516,15 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, dev_dbg(&s->dev, "IntType may not be INT_CARDBUS\n"); return -EINVAL; } + + mutex_lock(&s->ops_mutex); c = p_dev->function_config; if (c->state & CONFIG_LOCKED) { + mutex_unlock(&s->ops_mutex); dev_dbg(&s->dev, "Configuration is locked\n"); return -EACCES; } - mutex_lock(&s->ops_mutex); /* Do power control. We don't allow changes in Vcc. */ s->socket.Vpp = req->Vpp; if (s->ops->set_socket(s, &s->socket)) { @@ -615,58 +638,65 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) { struct pcmcia_socket *s = p_dev->socket; config_t *c; + int ret = -EINVAL; + + mutex_lock(&s->ops_mutex); if (!(s->state & SOCKET_PRESENT)) { dev_dbg(&s->dev, "No card present\n"); - return -ENODEV; + goto out; } if (!req) - return -EINVAL; + goto out; + c = p_dev->function_config; if (c->state & CONFIG_LOCKED) { dev_dbg(&s->dev, "Configuration is locked\n"); - return -EACCES; + goto out; } if (c->state & CONFIG_IO_REQ) { dev_dbg(&s->dev, "IO already configured\n"); - return -EBUSY; + goto out; } if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) { dev_dbg(&s->dev, "bad attribute setting for IO region 1\n"); - return -EINVAL; + goto out; } if ((req->NumPorts2 > 0) && (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) { dev_dbg(&s->dev, "bad attribute setting for IO region 2\n"); - return -EINVAL; + goto out; } - mutex_lock(&s->ops_mutex); dev_dbg(&s->dev, "trying to allocate resource 1\n"); - if (alloc_io_space(s, req->Attributes1, &req->BasePort1, - req->NumPorts1, req->IOAddrLines)) { + ret = alloc_io_space(s, req->Attributes1, &req->BasePort1, + req->NumPorts1, req->IOAddrLines); + if (ret) { dev_dbg(&s->dev, "allocation of resource 1 failed\n"); - mutex_unlock(&s->ops_mutex); - return -EBUSY; + goto out; } if (req->NumPorts2) { dev_dbg(&s->dev, "trying to allocate resource 2\n"); - if (alloc_io_space(s, req->Attributes2, &req->BasePort2, - req->NumPorts2, req->IOAddrLines)) { + ret = alloc_io_space(s, req->Attributes2, &req->BasePort2, + req->NumPorts2, req->IOAddrLines); + if (ret) { dev_dbg(&s->dev, "allocation of resource 2 failed\n"); release_io_space(s, req->BasePort1, req->NumPorts1); - mutex_unlock(&s->ops_mutex); - return -EBUSY; + goto out; } } - mutex_unlock(&s->ops_mutex); c->io = *req; c->state |= CONFIG_IO_REQ; p_dev->_io = 1; - return 0; + dev_dbg(&s->dev, "allocating resources succeeded: %d\n", ret); + +out: + mutex_unlock(&s->ops_mutex); + + return ret; } /* pcmcia_request_io */ EXPORT_SYMBOL(pcmcia_request_io); @@ -695,21 +725,22 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) int ret = -EINVAL, irq = 0; int type; + mutex_lock(&s->ops_mutex); + if (!(s->state & SOCKET_PRESENT)) { dev_dbg(&s->dev, "No card present\n"); - return -ENODEV; + goto out; } c = p_dev->function_config; if (c->state & CONFIG_LOCKED) { dev_dbg(&s->dev, "Configuration is locked\n"); - return -EACCES; + goto out; } if (c->state & CONFIG_IRQ_REQ) { dev_dbg(&s->dev, "IRQ already configured\n"); - return -EBUSY; + goto out; } - mutex_lock(&s->ops_mutex); /* Decide what type of interrupt we are registering */ type = 0; if (s->functions > 1) /* All of this ought to be handled higher up */ @@ -768,7 +799,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) if (ret && !s->irq.AssignedIRQ) { if (!s->pci_irq) { dev_printk(KERN_INFO, &s->dev, "no IRQ found\n"); - return ret; + goto out; } type = IRQF_SHARED; irq = s->pci_irq; @@ -780,7 +811,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) if (ret) { dev_printk(KERN_INFO, &s->dev, "request_irq() failed\n"); - return ret; + goto out; } } @@ -803,9 +834,10 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) pcmcia_used_irq[irq]++; #endif + ret = 0; +out: mutex_unlock(&s->ops_mutex); - - return 0; + return ret; } /* pcmcia_request_irq */ EXPORT_SYMBOL(pcmcia_request_irq); -- cgit v1.2.3-70-g09d2 From 3f565232c561fbd9d5e03354aac29b90cb2bc78a Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 16 Jan 2010 13:06:40 +0100 Subject: pcmcia: use mutex for dynid lock Even though we weren't calling a blocking function within the dynid spinlock, we do not need a spinlock here but can and should be using a mutex. Reported-by: Jiri Slaby Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 16 ++++++++-------- include/pcmcia/ds.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 83b51ddd3da..253d9aca5f7 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -124,9 +124,9 @@ pcmcia_store_new_id(struct device_driver *driver, const char *buf, size_t count) dynid->id.device_no = device_no; memcpy(dynid->id.prod_id_hash, prod_id_hash, sizeof(__u32) * 4); - spin_lock(&pdrv->dynids.lock); + mutex_lock(&pdrv->dynids.lock); list_add_tail(&dynid->node, &pdrv->dynids.list); - spin_unlock(&pdrv->dynids.lock); + mutex_unlock(&pdrv->dynids.lock); if (get_driver(&pdrv->drv)) { retval = driver_attach(&pdrv->drv); @@ -144,12 +144,12 @@ pcmcia_free_dynids(struct pcmcia_driver *drv) { struct pcmcia_dynid *dynid, *n; - spin_lock(&drv->dynids.lock); + mutex_lock(&drv->dynids.lock); list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { list_del(&dynid->node); kfree(dynid); } - spin_unlock(&drv->dynids.lock); + mutex_unlock(&drv->dynids.lock); } static int @@ -180,7 +180,7 @@ int pcmcia_register_driver(struct pcmcia_driver *driver) /* initialize common fields */ driver->drv.bus = &pcmcia_bus_type; driver->drv.owner = driver->owner; - spin_lock_init(&driver->dynids.lock); + mutex_init(&driver->dynids.lock); INIT_LIST_HEAD(&driver->dynids.list); pr_debug("registering driver %s\n", driver->drv.name); @@ -894,16 +894,16 @@ static int pcmcia_bus_match(struct device *dev, struct device_driver *drv) struct pcmcia_dynid *dynid; /* match dynamic devices first */ - spin_lock(&p_drv->dynids.lock); + mutex_lock(&p_drv->dynids.lock); list_for_each_entry(dynid, &p_drv->dynids.list, node) { dev_dbg(dev, "trying to match to %s\n", drv->name); if (pcmcia_devmatch(p_dev, &dynid->id)) { dev_dbg(dev, "matched to %s\n", drv->name); - spin_unlock(&p_drv->dynids.lock); + mutex_unlock(&p_drv->dynids.lock); return 1; } } - spin_unlock(&p_drv->dynids.lock); + mutex_unlock(&p_drv->dynids.lock); #ifdef CONFIG_PCMCIA_IOCTL /* matching by cardmgr */ diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h index ee148573c11..d57847f2f6c 100644 --- a/include/pcmcia/ds.h +++ b/include/pcmcia/ds.h @@ -40,7 +40,7 @@ struct net_device; * Documentation/pcmcia/driver.txt for details. */ struct pcmcia_dynids { - spinlock_t lock; + struct mutex lock; struct list_head list; }; -- cgit v1.2.3-70-g09d2 From cfe5d809518eda3d5e2da87c5ccbe8647143573a Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 17 Jan 2010 19:31:45 +0100 Subject: pcmcia: use ops_mutex for rsrc_{mgr,nonstatic} locking Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- Documentation/pcmcia/locking.txt | 5 +++-- drivers/pcmcia/cs.c | 7 ++++++- drivers/pcmcia/ds.c | 6 +++++- drivers/pcmcia/pcmcia_ioctl.c | 4 +--- drivers/pcmcia/rsrc_mgr.c | 2 -- drivers/pcmcia/rsrc_nonstatic.c | 35 ++++++++--------------------------- 6 files changed, 23 insertions(+), 36 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/Documentation/pcmcia/locking.txt b/Documentation/pcmcia/locking.txt index d6251056128..68f622bc406 100644 --- a/Documentation/pcmcia/locking.txt +++ b/Documentation/pcmcia/locking.txt @@ -36,7 +36,8 @@ be called with "ops_mutex" held: socket_reset() socket_setup() - struct pccard_operations *ops + struct pccard_operations *ops + struct pccard_resource_ops *resource_ops; Note that send_event() and struct pcmcia_callback *callback must not be called with "ops_mutex" held. @@ -54,7 +55,7 @@ protected by pcmcia_socket_list_rwsem; 2. Per-Socket Data: ------------------- -The resource_ops are on their own to provide proper locking. +The resource_ops and their data are protected by ops_mutex. The "main" struct pcmcia_socket is protected as follows (read-only fields or single-use fields not mentioned): diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 13277eebe46..7ba45b0cca6 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -224,7 +224,9 @@ int pcmcia_register_socket(struct pcmcia_socket *socket) spin_lock_init(&socket->thread_lock); if (socket->resource_ops->init) { + mutex_lock(&socket->ops_mutex); ret = socket->resource_ops->init(socket); + mutex_unlock(&socket->ops_mutex); if (ret) goto err; } @@ -282,8 +284,11 @@ void pcmcia_unregister_socket(struct pcmcia_socket *socket) up_write(&pcmcia_socket_list_rwsem); /* wait for sysfs to drop all references */ - if (socket->resource_ops->exit) + if (socket->resource_ops->exit) { + mutex_lock(&socket->ops_mutex); socket->resource_ops->exit(socket); + mutex_unlock(&socket->ops_mutex); + } wait_for_completion(&socket->socket_released); } /* pcmcia_unregister_socket */ EXPORT_SYMBOL(pcmcia_unregister_socket); diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 253d9aca5f7..76a21638291 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -607,19 +607,23 @@ static int pcmcia_card_add(struct pcmcia_socket *s) { cistpl_longlink_mfc_t mfc; unsigned int no_funcs, i, no_chains; - int ret = 0; + int ret = -EAGAIN; + mutex_lock(&s->ops_mutex); if (!(s->resource_setup_done)) { dev_dbg(&s->dev, "no resources available, delaying card_add\n"); + mutex_unlock(&s->ops_mutex); return -EAGAIN; /* try again, but later... */ } if (pcmcia_validate_mem(s)) { dev_dbg(&s->dev, "validating mem resources failed, " "delaying card_add\n"); + mutex_unlock(&s->ops_mutex); return -EAGAIN; /* try again, but later... */ } + mutex_unlock(&s->ops_mutex); ret = pccard_validate_cis(s, &no_chains); if (ret || !no_chains) { diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c index db2e3db8008..96fd236f52a 100644 --- a/drivers/pcmcia/pcmcia_ioctl.c +++ b/drivers/pcmcia/pcmcia_ioctl.c @@ -187,7 +187,6 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) continue; } else if (!(s->resource_setup_old)) s->resource_setup_old = 1; - mutex_unlock(&s->ops_mutex); switch (adj->Resource) { case RES_MEMORY_RANGE: @@ -206,10 +205,9 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) * last call to adjust_resource_info, we * always need to assume this is the latest * one... */ - mutex_lock(&s->ops_mutex); s->resource_setup_done = 1; - mutex_unlock(&s->ops_mutex); } + mutex_unlock(&s->ops_mutex); } } up_read(&pcmcia_socket_list_rwsem); diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index b81586622d0..aca2cfd02ca 100644 --- a/drivers/pcmcia/rsrc_mgr.c +++ b/drivers/pcmcia/rsrc_mgr.c @@ -26,9 +26,7 @@ static int static_init(struct pcmcia_socket *s) /* the good thing about SS_CAP_STATIC_MAP sockets is * that they don't need a resource database */ - mutex_lock(&s->ops_mutex); s->resource_setup_done = 1; - mutex_unlock(&s->ops_mutex); return 0; } diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 1de46cf2772..c13424f7b47 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -59,7 +59,6 @@ struct socket_data { unsigned int rsrc_mem_probe; }; -static DEFINE_MUTEX(rsrc_mutex); #define MEM_PROBE_LOW (1 << 0) #define MEM_PROBE_HIGH (1 << 1) @@ -274,7 +273,6 @@ static int readable(struct pcmcia_socket *s, struct resource *res, { int ret = -EINVAL; - mutex_lock(&s->ops_mutex); s->cis_mem.res = res; s->cis_virt = ioremap(res->start, s->map_size); if (s->cis_virt) { @@ -288,7 +286,6 @@ static int readable(struct pcmcia_socket *s, struct resource *res, s->cis_virt = NULL; } s->cis_mem.res = NULL; - mutex_unlock(&s->ops_mutex); if ((ret) || (*count == 0)) return -EINVAL; return 0; @@ -304,8 +301,6 @@ static int checksum(struct pcmcia_socket *s, struct resource *res, int i, a = 0, b = -1, d; void __iomem *virt; - mutex_lock(&s->ops_mutex); - virt = ioremap(res->start, s->map_size); if (virt) { map.map = 0; @@ -328,8 +323,6 @@ static int checksum(struct pcmcia_socket *s, struct resource *res, iounmap(virt); } - mutex_unlock(&s->ops_mutex); - if (b == -1) return -EINVAL; @@ -570,8 +563,6 @@ static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) if (!probe_mem) return 0; - mutex_lock(&rsrc_mutex); - if (s->features & SS_CAP_PAGE_REGS) probe_mask = MEM_PROBE_HIGH; @@ -583,8 +574,6 @@ static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) } } - mutex_unlock(&rsrc_mutex); - return ret; } @@ -661,7 +650,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star struct socket_data *s_data = s->resource_data; int ret = -ENOMEM; - mutex_lock(&rsrc_mutex); for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) { unsigned long start = m->base; unsigned long end = m->base + m->num - 1; @@ -672,7 +660,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star ret = adjust_resource(res, r_start, r_end - r_start + 1); break; } - mutex_unlock(&rsrc_mutex); return ret; } @@ -706,7 +693,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num, data.offset = base & data.mask; data.map = &s_data->io_db; - mutex_lock(&rsrc_mutex); #ifdef CONFIG_PCI if (s->cb_dev) { ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, @@ -715,7 +701,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num, #endif ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, 1, pcmcia_align, &data); - mutex_unlock(&rsrc_mutex); if (ret != 0) { kfree(res); @@ -748,7 +733,6 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num, min = 0x100000UL + base; } - mutex_lock(&rsrc_mutex); #ifdef CONFIG_PCI if (s->cb_dev) { ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, @@ -758,7 +742,6 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num, #endif ret = allocate_resource(&iomem_resource, res, num, min, max, 1, pcmcia_align, &data); - mutex_unlock(&rsrc_mutex); if (ret == 0 || low) break; low = 1; @@ -781,7 +764,6 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned if (end < start) return -EINVAL; - mutex_lock(&rsrc_mutex); switch (action) { case ADD_MANAGED_RESOURCE: ret = add_interval(&data->mem_db, start, size); @@ -794,7 +776,6 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned default: ret = -EINVAL; } - mutex_unlock(&rsrc_mutex); return ret; } @@ -812,7 +793,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long if (end > IO_SPACE_LIMIT) return -EINVAL; - mutex_lock(&rsrc_mutex); switch (action) { case ADD_MANAGED_RESOURCE: if (add_interval(&data->io_db, start, size) != 0) { @@ -831,7 +811,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long ret = -EINVAL; break; } - mutex_unlock(&rsrc_mutex); return ret; } @@ -929,7 +908,6 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s) struct socket_data *data = s->resource_data; struct resource_map *p, *q; - mutex_lock(&rsrc_mutex); for (p = data->mem_db.next; p != &data->mem_db; p = q) { q = p->next; kfree(p); @@ -938,7 +916,6 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s) q = p->next; kfree(p); } - mutex_unlock(&rsrc_mutex); } @@ -965,7 +942,7 @@ static ssize_t show_io_db(struct device *dev, struct resource_map *p; ssize_t ret = 0; - mutex_lock(&rsrc_mutex); + mutex_lock(&s->ops_mutex); data = s->resource_data; for (p = data->io_db.next; p != &data->io_db; p = p->next) { @@ -977,7 +954,7 @@ static ssize_t show_io_db(struct device *dev, ((unsigned long) p->base + p->num - 1)); } - mutex_unlock(&rsrc_mutex); + mutex_unlock(&s->ops_mutex); return ret; } @@ -1005,9 +982,11 @@ static ssize_t store_io_db(struct device *dev, if (end_addr < start_addr) return -EINVAL; + mutex_lock(&s->ops_mutex); ret = adjust_io(s, add, start_addr, end_addr); if (!ret) s->resource_setup_new = 1; + mutex_unlock(&s->ops_mutex); return ret ? ret : count; } @@ -1021,7 +1000,7 @@ static ssize_t show_mem_db(struct device *dev, struct resource_map *p; ssize_t ret = 0; - mutex_lock(&rsrc_mutex); + mutex_lock(&s->ops_mutex); data = s->resource_data; for (p = data->mem_db.next; p != &data->mem_db; p = p->next) { @@ -1033,7 +1012,7 @@ static ssize_t show_mem_db(struct device *dev, ((unsigned long) p->base + p->num - 1)); } - mutex_unlock(&rsrc_mutex); + mutex_unlock(&s->ops_mutex); return ret; } @@ -1061,9 +1040,11 @@ static ssize_t store_mem_db(struct device *dev, if (end_addr < start_addr) return -EINVAL; + mutex_lock(&s->ops_mutex); ret = adjust_memory(s, add, start_addr, end_addr); if (!ret) s->resource_setup_new = 1; + mutex_unlock(&s->ops_mutex); return ret ? ret : count; } -- cgit v1.2.3-70-g09d2 From af461fc1875b6ec18e23b5f670af36c4ed35c84e Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 17 Jan 2010 19:30:53 +0100 Subject: pcmcia: delay re-scanning and re-querying of PCMCIA bus After a CIS update -- or the finalization of the resource database --, proceed with the re-scanning or re-querying of PCMCIA cards only in a separate thread to avoid deadlocks. Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cistpl.c | 10 +----- drivers/pcmcia/cs.c | 8 ++++- drivers/pcmcia/cs_internal.h | 3 +- drivers/pcmcia/ds.c | 80 ++++++++++++++++++++++++++----------------- drivers/pcmcia/socket_sysfs.c | 11 +----- 5 files changed, 59 insertions(+), 53 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 14de287a8bf..17a5da32cce 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -1670,15 +1670,7 @@ static ssize_t pccard_store_cis(struct kobject *kobj, if (error) return -EIO; - mutex_lock(&s->skt_mutex); - if ((s->callback) && (s->state & SOCKET_PRESENT) && - !(s->state & SOCKET_CARDBUS)) { - if (try_module_get(s->callback->owner)) { - s->callback->requery(s, 1); - module_put(s->callback->owner); - } - } - mutex_unlock(&s->skt_mutex); + pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); return count; } diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 823ecda3221..d529e02c2d5 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -728,6 +728,11 @@ static int pccardd(void *__skt) if (!ret) socket_suspend(skt); } + if ((sysfs_events & PCMCIA_UEVENT_REQUERY) && + !(skt->state & SOCKET_CARDBUS)) { + if (!ret && skt->callback) + skt->callback->requery(skt); + } } mutex_unlock(&skt->skt_mutex); @@ -783,7 +788,8 @@ EXPORT_SYMBOL(pcmcia_parse_events); * userspace-issued insert, eject, suspend and resume commands must be * handled by pccardd to avoid any sysfs-related deadlocks. Valid events * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert), - * PCMCIA_UEVENT_RESUME (for resume) and PCMCIA_UEVENT_SUSPEND (for suspend). + * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend) + * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card). */ void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events) { diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 127c97acf84..f95864c2191 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -110,7 +110,7 @@ struct pcmcia_callback{ struct module *owner; int (*event) (struct pcmcia_socket *s, event_t event, int priority); - void (*requery) (struct pcmcia_socket *s, int new_cis); + void (*requery) (struct pcmcia_socket *s); int (*validate) (struct pcmcia_socket *s, unsigned int *i); int (*suspend) (struct pcmcia_socket *s); int (*resume) (struct pcmcia_socket *s); @@ -129,6 +129,7 @@ void pcmcia_parse_uevents(struct pcmcia_socket *socket, unsigned int events); #define PCMCIA_UEVENT_INSERT 0x0002 #define PCMCIA_UEVENT_SUSPEND 0x0004 #define PCMCIA_UEVENT_RESUME 0x0008 +#define PCMCIA_UEVENT_REQUERY 0x0010 struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt); void pcmcia_put_socket(struct pcmcia_socket *skt); diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 76a21638291..5400e20c664 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -432,16 +432,20 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, CISTPL_MANFID, &manf_id)) { + mutex_lock(&p_dev->socket->ops_mutex); p_dev->manf_id = manf_id.manf; p_dev->card_id = manf_id.card; p_dev->has_manf_id = 1; p_dev->has_card_id = 1; + mutex_unlock(&p_dev->socket->ops_mutex); } if (!pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_FUNCID, &func_id)) { + mutex_lock(&p_dev->socket->ops_mutex); p_dev->func_id = func_id.func; p_dev->has_func_id = 1; + mutex_unlock(&p_dev->socket->ops_mutex); } else { /* rule of thumb: cards with no FUNCID, but with * common memory device geometry information, are @@ -458,14 +462,17 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) dev_dbg(&p_dev->dev, "mem device geometry probably means " "FUNCID_MEMORY\n"); + mutex_lock(&p_dev->socket->ops_mutex); p_dev->func_id = CISTPL_FUNCID_MEMORY; p_dev->has_func_id = 1; + mutex_unlock(&p_dev->socket->ops_mutex); } kfree(devgeo); } if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, CISTPL_VERS_1, vers1)) { + mutex_lock(&p_dev->socket->ops_mutex); for (i = 0; i < min_t(unsigned int, 4, vers1->ns); i++) { char *tmp; unsigned int length; @@ -484,6 +491,7 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) p_dev->prod_id[i] = strncpy(p_dev->prod_id[i], tmp, length); } + mutex_unlock(&p_dev->socket->ops_mutex); } kfree(vers1); @@ -660,7 +668,7 @@ static void pcmcia_delayed_add_device(struct work_struct *work) pcmcia_device_add(s, mfc_pfc); } -static int pcmcia_requery(struct device *dev, void * _data) +static int pcmcia_requery_callback(struct device *dev, void * _data) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); if (!p_dev->dev.driver) { @@ -671,44 +679,57 @@ static int pcmcia_requery(struct device *dev, void * _data) return 0; } -static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis) +static void pcmcia_requery(struct pcmcia_socket *s) { - int no_devices = 0; - int ret = 0; - - /* must be called with skt_mutex held */ - dev_dbg(&skt->dev, "re-scanning socket %d\n", skt->sock); + int present; - mutex_lock(&skt->ops_mutex); - if (list_empty(&skt->devices_list)) - no_devices = 1; - mutex_unlock(&skt->ops_mutex); + mutex_lock(&s->ops_mutex); + present = s->pcmcia_state.present; + mutex_unlock(&s->ops_mutex); - /* If this is because of a CIS override, start over */ - if (new_cis && !no_devices) - pcmcia_card_remove(skt, NULL); + if (!present) + return; - /* if no devices were added for this socket yet because of - * missing resource information or other trouble, we need to - * do this now. */ - if (no_devices || new_cis) { - ret = pcmcia_card_add(skt); - if (ret) - return; + if (s->functions == 0) { + pcmcia_card_add(s); + return; } /* some device information might have changed because of a CIS * update or because we can finally read it correctly... so * determine it again, overwriting old values if necessary. */ - bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery); + bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery_callback); + + /* if the CIS changed, we need to check whether the number of + * functions changed. */ + if (s->fake_cis) { + int old_funcs, new_funcs; + cistpl_longlink_mfc_t mfc; + + /* does this cis override add or remove functions? */ + old_funcs = s->functions; + + if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, + &mfc)) + new_funcs = mfc.nfn; + else + new_funcs = 1; + if (old_funcs > new_funcs) { + pcmcia_card_remove(s, NULL); + pcmcia_card_add(s); + } else if (new_funcs > old_funcs) { + s->functions = new_funcs; + pcmcia_device_add(s, 1); + } + } /* we re-scan all devices, not just the ones connected to this * socket. This does not matter, though. */ - ret = bus_rescan_devices(&pcmcia_bus_type); - if (ret) - printk(KERN_INFO "pcmcia: bus_rescan_devices failed\n"); + if (bus_rescan_devices(&pcmcia_bus_type)) + dev_warn(&s->dev, "rescanning the bus failed\n"); } + #ifdef CONFIG_PCMCIA_LOAD_CIS /** @@ -1085,7 +1106,6 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); - int ret; if (!count) return -EINVAL; @@ -1093,11 +1113,7 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev, mutex_lock(&p_dev->socket->ops_mutex); p_dev->allow_func_id_match = 1; mutex_unlock(&p_dev->socket->ops_mutex); - - ret = bus_rescan_devices(&pcmcia_bus_type); - if (ret) - printk(KERN_INFO "pcmcia: bus_rescan_devices failed after " - "allowing func_id matches\n"); + pcmcia_parse_uevents(p_dev->socket, PCMCIA_UEVENT_REQUERY); return count; } @@ -1359,7 +1375,7 @@ EXPORT_SYMBOL(pcmcia_dev_present); static struct pcmcia_callback pcmcia_bus_callback = { .owner = THIS_MODULE, .event = ds_event, - .requery = pcmcia_bus_rescan, + .requery = pcmcia_requery, .validate = pccard_validate_cis, .suspend = pcmcia_bus_suspend, .resume = pcmcia_bus_resume, diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index fba0e30183f..08278016e58 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -201,16 +201,7 @@ static ssize_t pccard_store_resource(struct device *dev, s->resource_setup_done = 1; mutex_unlock(&s->ops_mutex); - mutex_lock(&s->skt_mutex); - if ((s->callback) && - (s->state & SOCKET_PRESENT) && - !(s->state & SOCKET_CARDBUS)) { - if (try_module_get(s->callback->owner)) { - s->callback->requery(s, 0); - module_put(s->callback->owner); - } - } - mutex_unlock(&s->skt_mutex); + pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); return count; } -- cgit v1.2.3-70-g09d2 From aa584ca4cdd8db370a524c61fd3ca408303281e9 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 24 Jan 2010 14:36:59 +0100 Subject: pcmcia: use state machine for extended requery The requery callback now also handles the addition of a second pseudo multifunction device. Avoids messing with dev_{g,s}et_drvdata(), and fixes any workqueue <-> skt_mutex deadlock. Tested-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 92 +++++++++++++---------------------------------------- include/pcmcia/ss.h | 11 ++----- 2 files changed, 25 insertions(+), 78 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 5400e20c664..9968c0d3a5f 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -244,23 +244,11 @@ static void pcmcia_release_dev(struct device *dev) kfree(p_dev); } -static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc) -{ - if (!s->pcmcia_state.device_add_pending) { - dev_dbg(&s->dev, "scheduling to add %s secondary" - " device to %d\n", mfc ? "mfc" : "pfc", s->sock); - s->pcmcia_state.device_add_pending = 1; - s->pcmcia_state.mfc_pfc = mfc; - schedule_work(&s->device_add); - } - return; -} static int pcmcia_device_probe(struct device *dev) { struct pcmcia_device *p_dev; struct pcmcia_driver *p_drv; - struct pcmcia_device_id *did; struct pcmcia_socket *s; cistpl_config_t cis_config; int ret = 0; @@ -273,18 +261,6 @@ static int pcmcia_device_probe(struct device *dev) p_drv = to_pcmcia_drv(dev->driver); s = p_dev->socket; - /* The PCMCIA code passes the match data in via dev_set_drvdata(dev) - * which is an ugly hack. Once the driver probe is called it may - * and often will overwrite the match data so we must save it first - * - * handle pseudo multifunction devices: - * there are at most two pseudo multifunction devices. - * if we're matching against the first, schedule a - * call which will then check whether there are two - * pseudo devices, and if not, add the second one. - */ - did = dev_get_drvdata(&p_dev->dev); - dev_dbg(dev, "trying to bind to %s\n", p_drv->drv.name); if ((!p_drv->probe) || (!p_dev->function_config) || @@ -314,9 +290,9 @@ static int pcmcia_device_probe(struct device *dev) } mutex_lock(&s->ops_mutex); - if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && + if ((s->pcmcia_state.has_pfc) && (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) - pcmcia_add_device_later(p_dev->socket, 0); + pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); mutex_unlock(&s->ops_mutex); put_module: @@ -369,7 +345,6 @@ static int pcmcia_device_remove(struct device *dev) { struct pcmcia_device *p_dev; struct pcmcia_driver *p_drv; - struct pcmcia_device_id *did; int i; p_dev = to_pcmcia_dev(dev); @@ -381,8 +356,7 @@ static int pcmcia_device_remove(struct device *dev) * pseudo multi-function card, we need to unbind * all devices */ - did = dev_get_drvdata(&p_dev->dev); - if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && + if ((p_dev->socket->pcmcia_state.has_pfc) && (p_dev->socket->device_count > 0) && (p_dev->device_no == 0)) pcmcia_card_remove(p_dev->socket, p_dev); @@ -528,8 +502,8 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu p_dev->device_no = (s->device_count++); mutex_unlock(&s->ops_mutex); - /* max of 4 devices per card */ - if (p_dev->device_no >= 4) + /* max of 2 devices per card */ + if (p_dev->device_no >= 2) goto err_free; p_dev->socket = s; @@ -652,22 +626,6 @@ static int pcmcia_card_add(struct pcmcia_socket *s) } -static void pcmcia_delayed_add_device(struct work_struct *work) -{ - struct pcmcia_socket *s = - container_of(work, struct pcmcia_socket, device_add); - u8 mfc_pfc; - - mutex_lock(&s->ops_mutex); - mfc_pfc = s->pcmcia_state.mfc_pfc; - s->pcmcia_state.device_add_pending = 0; - s->pcmcia_state.mfc_pfc = 0; - mutex_unlock(&s->ops_mutex); - - dev_dbg(&s->dev, "adding additional device to %d\n", s->sock); - pcmcia_device_add(s, mfc_pfc); -} - static int pcmcia_requery_callback(struct device *dev, void * _data) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); @@ -679,9 +637,10 @@ static int pcmcia_requery_callback(struct device *dev, void * _data) return 0; } + static void pcmcia_requery(struct pcmcia_socket *s) { - int present; + int present, has_pfc; mutex_lock(&s->ops_mutex); present = s->pcmcia_state.present; @@ -723,6 +682,15 @@ static void pcmcia_requery(struct pcmcia_socket *s) } } + /* If the PCMCIA device consists of two pseudo devices, + * call pcmcia_device_add() -- which will fail if both + * devices are already registered. */ + mutex_lock(&s->ops_mutex); + has_pfc = s->pcmcia_state.has_pfc; + mutex_unlock(&s->ops_mutex); + if (has_pfc) + pcmcia_device_add(s, 0); + /* we re-scan all devices, not just the ones connected to this * socket. This does not matter, though. */ if (bus_rescan_devices(&pcmcia_bus_type)) @@ -746,9 +714,6 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) struct pcmcia_socket *s = dev->socket; const struct firmware *fw; int ret = -ENOMEM; - int no_funcs; - int old_funcs; - cistpl_longlink_mfc_t mfc; if (!filename) return -EINVAL; @@ -775,22 +740,8 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) /* update information */ pcmcia_device_query(dev); - /* does this cis override add or remove functions? */ - old_funcs = s->functions; - - if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc)) - no_funcs = mfc.nfn; - else - no_funcs = 1; - s->functions = no_funcs; - - if (old_funcs > no_funcs) - pcmcia_card_remove(s, dev); - else if (no_funcs > old_funcs) { - mutex_lock(&s->ops_mutex); - pcmcia_add_device_later(s, 1); - mutex_unlock(&s->ops_mutex); - } + /* requery (as number of functions might have changed) */ + pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); } release: release_firmware(fw); @@ -857,6 +808,9 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) { if (dev->device_no != did->device_no) return 0; + mutex_lock(&dev->socket->ops_mutex); + dev->socket->pcmcia_state.has_pfc = 1; + mutex_unlock(&dev->socket->ops_mutex); } if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) { @@ -905,8 +859,6 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, return 0; } - dev_set_drvdata(&dev->dev, did); - return 1; } @@ -1300,6 +1252,7 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) case CS_EVENT_CARD_INSERTION: mutex_lock(&s->ops_mutex); + s->pcmcia_state.has_pfc = 0; s->pcmcia_state.present = 1; destroy_cis_cache(s); /* to be on the safe side... */ mutex_unlock(&s->ops_mutex); @@ -1411,7 +1364,6 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev, init_waitqueue_head(&socket->queue); #endif INIT_LIST_HEAD(&socket->devices_list); - INIT_WORK(&socket->device_add, pcmcia_delayed_add_device); memset(&socket->pcmcia_state, 0, sizeof(u8)); socket->device_count = 0; diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h index ea5dec8c0d7..32896a77391 100644 --- a/include/pcmcia/ss.h +++ b/include/pcmcia/ss.h @@ -230,18 +230,13 @@ struct pcmcia_socket { u8 busy:1; /* pcmcia module is being unloaded */ u8 dead:1; - /* a multifunction-device add event is pending */ - u8 device_add_pending:1; - /* the pending event adds a mfc (1) or pfc (0) */ - u8 mfc_pfc:1; + /* the PCMCIA card consists of two pseudo devices */ + u8 has_pfc:1; - u8 reserved:3; + u8 reserved:4; } pcmcia_state; - /* for adding further pseudo-multifunction devices */ - struct work_struct device_add; - #ifdef CONFIG_PCMCIA_IOCTL struct user_info_t *user; wait_queue_head_t queue; -- cgit v1.2.3-70-g09d2 From 44961a03adbf16d872f0b83ec848d0759516d33f Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 24 Jan 2010 12:11:02 +0100 Subject: pcmcia: avoid prod_id memleak Reported-by: Wolfram Sang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 9968c0d3a5f..93925f5908b 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -237,8 +237,11 @@ static void pcmcia_release_function(struct kref *ref) static void pcmcia_release_dev(struct device *dev) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); + int i; dev_dbg(dev, "releasing device\n"); pcmcia_put_socket(p_dev->socket); + for (i = 0; i < 4; i++) + kfree(p_dev->prod_id[i]); kfree(p_dev->devname); kref_put(&p_dev->function_config->ref, pcmcia_release_function); kfree(p_dev); @@ -450,6 +453,7 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) for (i = 0; i < min_t(unsigned int, 4, vers1->ns); i++) { char *tmp; unsigned int length; + char *new; tmp = vers1->str + vers1->ofs[i]; @@ -457,13 +461,15 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) if ((length < 2) || (length > 255)) continue; - p_dev->prod_id[i] = kmalloc(sizeof(char) * length, - GFP_KERNEL); - if (!p_dev->prod_id[i]) + new = kmalloc(sizeof(char) * length, GFP_KERNEL); + if (!new) continue; - p_dev->prod_id[i] = strncpy(p_dev->prod_id[i], - tmp, length); + new = strncpy(new, tmp, length); + + tmp = p_dev->prod_id[i]; + p_dev->prod_id[i] = new; + kfree(tmp); } mutex_unlock(&p_dev->socket->ops_mutex); } @@ -485,6 +491,7 @@ static DEFINE_MUTEX(device_add_lock); struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) { struct pcmcia_device *p_dev, *tmp_dev; + int i; s = pcmcia_get_socket(s); if (!s) @@ -575,6 +582,8 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu s->device_count--; mutex_unlock(&s->ops_mutex); + for (i = 0; i < 4; i++) + kfree(p_dev->prod_id[i]); kfree(p_dev->devname); kfree(p_dev); err_put: -- cgit v1.2.3-70-g09d2 From d801c1409ef7d45339cbe8ac9de28ade6ed4699a Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 17 Feb 2010 11:02:22 +0100 Subject: pcmcia: remove useless msleep in ds.c As this is the socket thread (pccardd) starting up, we do not have anything to wait for in ds.c. Instead, wait the same amount of time in pccardd to allow userspace to catch up and - possibly - execute pcmcia-socket-startup. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs.c | 3 +++ drivers/pcmcia/ds.c | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers/pcmcia/ds.c') diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 9a49c394f04..e679e708db6 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -689,6 +689,9 @@ static int pccardd(void *__skt) complete(&skt->thread_done); + /* wait for userspace to catch up */ + msleep(250); + set_freezable(); for (;;) { unsigned long flags; diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 93925f5908b..0f98be4450b 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -1356,12 +1356,6 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev, return -ENODEV; } - /* - * Ugly. But we want to wait for the socket threads to have started up. - * We really should let the drivers themselves drive some of this.. - */ - msleep(250); - ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); if (ret) { dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n"); -- cgit v1.2.3-70-g09d2