diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2010-01-17 13:31:45 -0500 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2010-02-17 11:48:24 -0500 |
commit | cfe5d809518eda3d5e2da87c5ccbe8647143573a (patch) | |
tree | dd61ec285412fc0de8090ef5743b824447a9eeda /drivers/pcmcia | |
parent | 3f565232c561fbd9d5e03354aac29b90cb2bc78a (diff) |
pcmcia: use ops_mutex for rsrc_{mgr,nonstatic} locking
Tested-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers/pcmcia')
-rw-r--r-- | drivers/pcmcia/cs.c | 7 | ||||
-rw-r--r-- | drivers/pcmcia/ds.c | 6 | ||||
-rw-r--r-- | drivers/pcmcia/pcmcia_ioctl.c | 4 | ||||
-rw-r--r-- | drivers/pcmcia/rsrc_mgr.c | 2 | ||||
-rw-r--r-- | drivers/pcmcia/rsrc_nonstatic.c | 35 |
5 files changed, 20 insertions, 34 deletions
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 13277eebe46a..7ba45b0cca6b 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c | |||
@@ -224,7 +224,9 @@ int pcmcia_register_socket(struct pcmcia_socket *socket) | |||
224 | spin_lock_init(&socket->thread_lock); | 224 | spin_lock_init(&socket->thread_lock); |
225 | 225 | ||
226 | if (socket->resource_ops->init) { | 226 | if (socket->resource_ops->init) { |
227 | mutex_lock(&socket->ops_mutex); | ||
227 | ret = socket->resource_ops->init(socket); | 228 | ret = socket->resource_ops->init(socket); |
229 | mutex_unlock(&socket->ops_mutex); | ||
228 | if (ret) | 230 | if (ret) |
229 | goto err; | 231 | goto err; |
230 | } | 232 | } |
@@ -282,8 +284,11 @@ void pcmcia_unregister_socket(struct pcmcia_socket *socket) | |||
282 | up_write(&pcmcia_socket_list_rwsem); | 284 | up_write(&pcmcia_socket_list_rwsem); |
283 | 285 | ||
284 | /* wait for sysfs to drop all references */ | 286 | /* wait for sysfs to drop all references */ |
285 | if (socket->resource_ops->exit) | 287 | if (socket->resource_ops->exit) { |
288 | mutex_lock(&socket->ops_mutex); | ||
286 | socket->resource_ops->exit(socket); | 289 | socket->resource_ops->exit(socket); |
290 | mutex_unlock(&socket->ops_mutex); | ||
291 | } | ||
287 | wait_for_completion(&socket->socket_released); | 292 | wait_for_completion(&socket->socket_released); |
288 | } /* pcmcia_unregister_socket */ | 293 | } /* pcmcia_unregister_socket */ |
289 | EXPORT_SYMBOL(pcmcia_unregister_socket); | 294 | EXPORT_SYMBOL(pcmcia_unregister_socket); |
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 253d9aca5f77..76a21638291b 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c | |||
@@ -607,19 +607,23 @@ static int pcmcia_card_add(struct pcmcia_socket *s) | |||
607 | { | 607 | { |
608 | cistpl_longlink_mfc_t mfc; | 608 | cistpl_longlink_mfc_t mfc; |
609 | unsigned int no_funcs, i, no_chains; | 609 | unsigned int no_funcs, i, no_chains; |
610 | int ret = 0; | 610 | int ret = -EAGAIN; |
611 | 611 | ||
612 | mutex_lock(&s->ops_mutex); | ||
612 | if (!(s->resource_setup_done)) { | 613 | if (!(s->resource_setup_done)) { |
613 | dev_dbg(&s->dev, | 614 | dev_dbg(&s->dev, |
614 | "no resources available, delaying card_add\n"); | 615 | "no resources available, delaying card_add\n"); |
616 | mutex_unlock(&s->ops_mutex); | ||
615 | return -EAGAIN; /* try again, but later... */ | 617 | return -EAGAIN; /* try again, but later... */ |
616 | } | 618 | } |
617 | 619 | ||
618 | if (pcmcia_validate_mem(s)) { | 620 | if (pcmcia_validate_mem(s)) { |
619 | dev_dbg(&s->dev, "validating mem resources failed, " | 621 | dev_dbg(&s->dev, "validating mem resources failed, " |
620 | "delaying card_add\n"); | 622 | "delaying card_add\n"); |
623 | mutex_unlock(&s->ops_mutex); | ||
621 | return -EAGAIN; /* try again, but later... */ | 624 | return -EAGAIN; /* try again, but later... */ |
622 | } | 625 | } |
626 | mutex_unlock(&s->ops_mutex); | ||
623 | 627 | ||
624 | ret = pccard_validate_cis(s, &no_chains); | 628 | ret = pccard_validate_cis(s, &no_chains); |
625 | if (ret || !no_chains) { | 629 | if (ret || !no_chains) { |
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c index db2e3db8008b..96fd236f52a9 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) | |||
187 | continue; | 187 | continue; |
188 | } else if (!(s->resource_setup_old)) | 188 | } else if (!(s->resource_setup_old)) |
189 | s->resource_setup_old = 1; | 189 | s->resource_setup_old = 1; |
190 | mutex_unlock(&s->ops_mutex); | ||
191 | 190 | ||
192 | switch (adj->Resource) { | 191 | switch (adj->Resource) { |
193 | case RES_MEMORY_RANGE: | 192 | case RES_MEMORY_RANGE: |
@@ -206,10 +205,9 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) | |||
206 | * last call to adjust_resource_info, we | 205 | * last call to adjust_resource_info, we |
207 | * always need to assume this is the latest | 206 | * always need to assume this is the latest |
208 | * one... */ | 207 | * one... */ |
209 | mutex_lock(&s->ops_mutex); | ||
210 | s->resource_setup_done = 1; | 208 | s->resource_setup_done = 1; |
211 | mutex_unlock(&s->ops_mutex); | ||
212 | } | 209 | } |
210 | mutex_unlock(&s->ops_mutex); | ||
213 | } | 211 | } |
214 | } | 212 | } |
215 | up_read(&pcmcia_socket_list_rwsem); | 213 | up_read(&pcmcia_socket_list_rwsem); |
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index b81586622d02..aca2cfd02ca5 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) | |||
26 | /* the good thing about SS_CAP_STATIC_MAP sockets is | 26 | /* the good thing about SS_CAP_STATIC_MAP sockets is |
27 | * that they don't need a resource database */ | 27 | * that they don't need a resource database */ |
28 | 28 | ||
29 | mutex_lock(&s->ops_mutex); | ||
30 | s->resource_setup_done = 1; | 29 | s->resource_setup_done = 1; |
31 | mutex_unlock(&s->ops_mutex); | ||
32 | 30 | ||
33 | return 0; | 31 | return 0; |
34 | } | 32 | } |
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 1de46cf2772f..c13424f7b479 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c | |||
@@ -59,7 +59,6 @@ struct socket_data { | |||
59 | unsigned int rsrc_mem_probe; | 59 | unsigned int rsrc_mem_probe; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | static DEFINE_MUTEX(rsrc_mutex); | ||
63 | #define MEM_PROBE_LOW (1 << 0) | 62 | #define MEM_PROBE_LOW (1 << 0) |
64 | #define MEM_PROBE_HIGH (1 << 1) | 63 | #define MEM_PROBE_HIGH (1 << 1) |
65 | 64 | ||
@@ -274,7 +273,6 @@ static int readable(struct pcmcia_socket *s, struct resource *res, | |||
274 | { | 273 | { |
275 | int ret = -EINVAL; | 274 | int ret = -EINVAL; |
276 | 275 | ||
277 | mutex_lock(&s->ops_mutex); | ||
278 | s->cis_mem.res = res; | 276 | s->cis_mem.res = res; |
279 | s->cis_virt = ioremap(res->start, s->map_size); | 277 | s->cis_virt = ioremap(res->start, s->map_size); |
280 | if (s->cis_virt) { | 278 | if (s->cis_virt) { |
@@ -288,7 +286,6 @@ static int readable(struct pcmcia_socket *s, struct resource *res, | |||
288 | s->cis_virt = NULL; | 286 | s->cis_virt = NULL; |
289 | } | 287 | } |
290 | s->cis_mem.res = NULL; | 288 | s->cis_mem.res = NULL; |
291 | mutex_unlock(&s->ops_mutex); | ||
292 | if ((ret) || (*count == 0)) | 289 | if ((ret) || (*count == 0)) |
293 | return -EINVAL; | 290 | return -EINVAL; |
294 | return 0; | 291 | return 0; |
@@ -304,8 +301,6 @@ static int checksum(struct pcmcia_socket *s, struct resource *res, | |||
304 | int i, a = 0, b = -1, d; | 301 | int i, a = 0, b = -1, d; |
305 | void __iomem *virt; | 302 | void __iomem *virt; |
306 | 303 | ||
307 | mutex_lock(&s->ops_mutex); | ||
308 | |||
309 | virt = ioremap(res->start, s->map_size); | 304 | virt = ioremap(res->start, s->map_size); |
310 | if (virt) { | 305 | if (virt) { |
311 | map.map = 0; | 306 | map.map = 0; |
@@ -328,8 +323,6 @@ static int checksum(struct pcmcia_socket *s, struct resource *res, | |||
328 | iounmap(virt); | 323 | iounmap(virt); |
329 | } | 324 | } |
330 | 325 | ||
331 | mutex_unlock(&s->ops_mutex); | ||
332 | |||
333 | if (b == -1) | 326 | if (b == -1) |
334 | return -EINVAL; | 327 | return -EINVAL; |
335 | 328 | ||
@@ -570,8 +563,6 @@ static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) | |||
570 | if (!probe_mem) | 563 | if (!probe_mem) |
571 | return 0; | 564 | return 0; |
572 | 565 | ||
573 | mutex_lock(&rsrc_mutex); | ||
574 | |||
575 | if (s->features & SS_CAP_PAGE_REGS) | 566 | if (s->features & SS_CAP_PAGE_REGS) |
576 | probe_mask = MEM_PROBE_HIGH; | 567 | probe_mask = MEM_PROBE_HIGH; |
577 | 568 | ||
@@ -583,8 +574,6 @@ static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) | |||
583 | } | 574 | } |
584 | } | 575 | } |
585 | 576 | ||
586 | mutex_unlock(&rsrc_mutex); | ||
587 | |||
588 | return ret; | 577 | return ret; |
589 | } | 578 | } |
590 | 579 | ||
@@ -661,7 +650,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star | |||
661 | struct socket_data *s_data = s->resource_data; | 650 | struct socket_data *s_data = s->resource_data; |
662 | int ret = -ENOMEM; | 651 | int ret = -ENOMEM; |
663 | 652 | ||
664 | mutex_lock(&rsrc_mutex); | ||
665 | for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) { | 653 | for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) { |
666 | unsigned long start = m->base; | 654 | unsigned long start = m->base; |
667 | unsigned long end = m->base + m->num - 1; | 655 | 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 | |||
672 | ret = adjust_resource(res, r_start, r_end - r_start + 1); | 660 | ret = adjust_resource(res, r_start, r_end - r_start + 1); |
673 | break; | 661 | break; |
674 | } | 662 | } |
675 | mutex_unlock(&rsrc_mutex); | ||
676 | 663 | ||
677 | return ret; | 664 | return ret; |
678 | } | 665 | } |
@@ -706,7 +693,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num, | |||
706 | data.offset = base & data.mask; | 693 | data.offset = base & data.mask; |
707 | data.map = &s_data->io_db; | 694 | data.map = &s_data->io_db; |
708 | 695 | ||
709 | mutex_lock(&rsrc_mutex); | ||
710 | #ifdef CONFIG_PCI | 696 | #ifdef CONFIG_PCI |
711 | if (s->cb_dev) { | 697 | if (s->cb_dev) { |
712 | ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, | 698 | 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, | |||
715 | #endif | 701 | #endif |
716 | ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, | 702 | ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, |
717 | 1, pcmcia_align, &data); | 703 | 1, pcmcia_align, &data); |
718 | mutex_unlock(&rsrc_mutex); | ||
719 | 704 | ||
720 | if (ret != 0) { | 705 | if (ret != 0) { |
721 | kfree(res); | 706 | kfree(res); |
@@ -748,7 +733,6 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num, | |||
748 | min = 0x100000UL + base; | 733 | min = 0x100000UL + base; |
749 | } | 734 | } |
750 | 735 | ||
751 | mutex_lock(&rsrc_mutex); | ||
752 | #ifdef CONFIG_PCI | 736 | #ifdef CONFIG_PCI |
753 | if (s->cb_dev) { | 737 | if (s->cb_dev) { |
754 | ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, | 738 | 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, | |||
758 | #endif | 742 | #endif |
759 | ret = allocate_resource(&iomem_resource, res, num, min, | 743 | ret = allocate_resource(&iomem_resource, res, num, min, |
760 | max, 1, pcmcia_align, &data); | 744 | max, 1, pcmcia_align, &data); |
761 | mutex_unlock(&rsrc_mutex); | ||
762 | if (ret == 0 || low) | 745 | if (ret == 0 || low) |
763 | break; | 746 | break; |
764 | low = 1; | 747 | low = 1; |
@@ -781,7 +764,6 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned | |||
781 | if (end < start) | 764 | if (end < start) |
782 | return -EINVAL; | 765 | return -EINVAL; |
783 | 766 | ||
784 | mutex_lock(&rsrc_mutex); | ||
785 | switch (action) { | 767 | switch (action) { |
786 | case ADD_MANAGED_RESOURCE: | 768 | case ADD_MANAGED_RESOURCE: |
787 | ret = add_interval(&data->mem_db, start, size); | 769 | ret = add_interval(&data->mem_db, start, size); |
@@ -794,7 +776,6 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned | |||
794 | default: | 776 | default: |
795 | ret = -EINVAL; | 777 | ret = -EINVAL; |
796 | } | 778 | } |
797 | mutex_unlock(&rsrc_mutex); | ||
798 | 779 | ||
799 | return ret; | 780 | return ret; |
800 | } | 781 | } |
@@ -812,7 +793,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long | |||
812 | if (end > IO_SPACE_LIMIT) | 793 | if (end > IO_SPACE_LIMIT) |
813 | return -EINVAL; | 794 | return -EINVAL; |
814 | 795 | ||
815 | mutex_lock(&rsrc_mutex); | ||
816 | switch (action) { | 796 | switch (action) { |
817 | case ADD_MANAGED_RESOURCE: | 797 | case ADD_MANAGED_RESOURCE: |
818 | if (add_interval(&data->io_db, start, size) != 0) { | 798 | 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 | |||
831 | ret = -EINVAL; | 811 | ret = -EINVAL; |
832 | break; | 812 | break; |
833 | } | 813 | } |
834 | mutex_unlock(&rsrc_mutex); | ||
835 | 814 | ||
836 | return ret; | 815 | return ret; |
837 | } | 816 | } |
@@ -929,7 +908,6 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s) | |||
929 | struct socket_data *data = s->resource_data; | 908 | struct socket_data *data = s->resource_data; |
930 | struct resource_map *p, *q; | 909 | struct resource_map *p, *q; |
931 | 910 | ||
932 | mutex_lock(&rsrc_mutex); | ||
933 | for (p = data->mem_db.next; p != &data->mem_db; p = q) { | 911 | for (p = data->mem_db.next; p != &data->mem_db; p = q) { |
934 | q = p->next; | 912 | q = p->next; |
935 | kfree(p); | 913 | kfree(p); |
@@ -938,7 +916,6 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s) | |||
938 | q = p->next; | 916 | q = p->next; |
939 | kfree(p); | 917 | kfree(p); |
940 | } | 918 | } |
941 | mutex_unlock(&rsrc_mutex); | ||
942 | } | 919 | } |
943 | 920 | ||
944 | 921 | ||
@@ -965,7 +942,7 @@ static ssize_t show_io_db(struct device *dev, | |||
965 | struct resource_map *p; | 942 | struct resource_map *p; |
966 | ssize_t ret = 0; | 943 | ssize_t ret = 0; |
967 | 944 | ||
968 | mutex_lock(&rsrc_mutex); | 945 | mutex_lock(&s->ops_mutex); |
969 | data = s->resource_data; | 946 | data = s->resource_data; |
970 | 947 | ||
971 | for (p = data->io_db.next; p != &data->io_db; p = p->next) { | 948 | 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, | |||
977 | ((unsigned long) p->base + p->num - 1)); | 954 | ((unsigned long) p->base + p->num - 1)); |
978 | } | 955 | } |
979 | 956 | ||
980 | mutex_unlock(&rsrc_mutex); | 957 | mutex_unlock(&s->ops_mutex); |
981 | return ret; | 958 | return ret; |
982 | } | 959 | } |
983 | 960 | ||
@@ -1005,9 +982,11 @@ static ssize_t store_io_db(struct device *dev, | |||
1005 | if (end_addr < start_addr) | 982 | if (end_addr < start_addr) |
1006 | return -EINVAL; | 983 | return -EINVAL; |
1007 | 984 | ||
985 | mutex_lock(&s->ops_mutex); | ||
1008 | ret = adjust_io(s, add, start_addr, end_addr); | 986 | ret = adjust_io(s, add, start_addr, end_addr); |
1009 | if (!ret) | 987 | if (!ret) |
1010 | s->resource_setup_new = 1; | 988 | s->resource_setup_new = 1; |
989 | mutex_unlock(&s->ops_mutex); | ||
1011 | 990 | ||
1012 | return ret ? ret : count; | 991 | return ret ? ret : count; |
1013 | } | 992 | } |
@@ -1021,7 +1000,7 @@ static ssize_t show_mem_db(struct device *dev, | |||
1021 | struct resource_map *p; | 1000 | struct resource_map *p; |
1022 | ssize_t ret = 0; | 1001 | ssize_t ret = 0; |
1023 | 1002 | ||
1024 | mutex_lock(&rsrc_mutex); | 1003 | mutex_lock(&s->ops_mutex); |
1025 | data = s->resource_data; | 1004 | data = s->resource_data; |
1026 | 1005 | ||
1027 | for (p = data->mem_db.next; p != &data->mem_db; p = p->next) { | 1006 | 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, | |||
1033 | ((unsigned long) p->base + p->num - 1)); | 1012 | ((unsigned long) p->base + p->num - 1)); |
1034 | } | 1013 | } |
1035 | 1014 | ||
1036 | mutex_unlock(&rsrc_mutex); | 1015 | mutex_unlock(&s->ops_mutex); |
1037 | return ret; | 1016 | return ret; |
1038 | } | 1017 | } |
1039 | 1018 | ||
@@ -1061,9 +1040,11 @@ static ssize_t store_mem_db(struct device *dev, | |||
1061 | if (end_addr < start_addr) | 1040 | if (end_addr < start_addr) |
1062 | return -EINVAL; | 1041 | return -EINVAL; |
1063 | 1042 | ||
1043 | mutex_lock(&s->ops_mutex); | ||
1064 | ret = adjust_memory(s, add, start_addr, end_addr); | 1044 | ret = adjust_memory(s, add, start_addr, end_addr); |
1065 | if (!ret) | 1045 | if (!ret) |
1066 | s->resource_setup_new = 1; | 1046 | s->resource_setup_new = 1; |
1047 | mutex_unlock(&s->ops_mutex); | ||
1067 | 1048 | ||
1068 | return ret ? ret : count; | 1049 | return ret ? ret : count; |
1069 | } | 1050 | } |