diff options
Diffstat (limited to 'drivers/pcmcia/pcmcia_ioctl.c')
-rw-r--r-- | drivers/pcmcia/pcmcia_ioctl.c | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c index 80969f7e7a0b..c53db7ceda5e 100644 --- a/drivers/pcmcia/pcmcia_ioctl.c +++ b/drivers/pcmcia/pcmcia_ioctl.c | |||
@@ -18,7 +18,6 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | 20 | ||
21 | #include <linux/config.h> | ||
22 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
23 | #include <linux/module.h> | 22 | #include <linux/module.h> |
24 | #include <linux/init.h> | 23 | #include <linux/init.h> |
@@ -70,10 +69,26 @@ extern int ds_pc_debug; | |||
70 | #define ds_dbg(lvl, fmt, arg...) do { } while (0) | 69 | #define ds_dbg(lvl, fmt, arg...) do { } while (0) |
71 | #endif | 70 | #endif |
72 | 71 | ||
72 | static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s, | ||
73 | unsigned int function) | ||
74 | { | ||
75 | struct pcmcia_device *p_dev = NULL; | ||
76 | unsigned long flags; | ||
77 | |||
78 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | ||
79 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { | ||
80 | if (p_dev->func == function) { | ||
81 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
82 | return pcmcia_get_dev(p_dev); | ||
83 | } | ||
84 | } | ||
85 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
86 | return NULL; | ||
87 | } | ||
73 | 88 | ||
74 | /* backwards-compatible accessing of driver --- by name! */ | 89 | /* backwards-compatible accessing of driver --- by name! */ |
75 | 90 | ||
76 | static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info) | 91 | static struct pcmcia_driver *get_pcmcia_driver(dev_info_t *dev_info) |
77 | { | 92 | { |
78 | struct device_driver *drv; | 93 | struct device_driver *drv; |
79 | struct pcmcia_driver *p_drv; | 94 | struct pcmcia_driver *p_drv; |
@@ -214,7 +229,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) | |||
214 | * by userspace before, we need to | 229 | * by userspace before, we need to |
215 | * return the "instance". */ | 230 | * return the "instance". */ |
216 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 231 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); |
217 | bind_info->instance = p_dev->instance; | 232 | bind_info->instance = p_dev; |
218 | ret = -EBUSY; | 233 | ret = -EBUSY; |
219 | goto err_put_module; | 234 | goto err_put_module; |
220 | } else { | 235 | } else { |
@@ -253,9 +268,9 @@ rescan: | |||
253 | /* | 268 | /* |
254 | * Prevent this racing with a card insertion. | 269 | * Prevent this racing with a card insertion. |
255 | */ | 270 | */ |
256 | down(&s->skt_sem); | 271 | mutex_lock(&s->skt_mutex); |
257 | bus_rescan_devices(&pcmcia_bus_type); | 272 | bus_rescan_devices(&pcmcia_bus_type); |
258 | up(&s->skt_sem); | 273 | mutex_unlock(&s->skt_mutex); |
259 | 274 | ||
260 | /* check whether the driver indeed matched. I don't care if this | 275 | /* check whether the driver indeed matched. I don't care if this |
261 | * is racy or not, because it can only happen on cardmgr access | 276 | * is racy or not, because it can only happen on cardmgr access |
@@ -289,6 +304,7 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int | |||
289 | { | 304 | { |
290 | dev_node_t *node; | 305 | dev_node_t *node; |
291 | struct pcmcia_device *p_dev; | 306 | struct pcmcia_device *p_dev; |
307 | struct pcmcia_driver *p_drv; | ||
292 | unsigned long flags; | 308 | unsigned long flags; |
293 | int ret = 0; | 309 | int ret = 0; |
294 | 310 | ||
@@ -343,16 +359,16 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int | |||
343 | found: | 359 | found: |
344 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 360 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); |
345 | 361 | ||
346 | if ((!p_dev->instance) || | 362 | p_drv = to_pcmcia_drv(p_dev->dev.driver); |
347 | (p_dev->instance->state & DEV_CONFIG_PENDING)) { | 363 | if (p_drv && !p_dev->_locked) { |
348 | ret = -EAGAIN; | 364 | ret = -EAGAIN; |
349 | goto err_put; | 365 | goto err_put; |
350 | } | 366 | } |
351 | 367 | ||
352 | if (first) | 368 | if (first) |
353 | node = p_dev->instance->dev; | 369 | node = p_dev->dev_node; |
354 | else | 370 | else |
355 | for (node = p_dev->instance->dev; node; node = node->next) | 371 | for (node = p_dev->dev_node; node; node = node->next) |
356 | if (node == bind_info->next) | 372 | if (node == bind_info->next) |
357 | break; | 373 | break; |
358 | if (!node) { | 374 | if (!node) { |
@@ -583,14 +599,16 @@ static int ds_ioctl(struct inode * inode, struct file * file, | |||
583 | if (buf->config.Function && | 599 | if (buf->config.Function && |
584 | (buf->config.Function >= s->functions)) | 600 | (buf->config.Function >= s->functions)) |
585 | ret = CS_BAD_ARGS; | 601 | ret = CS_BAD_ARGS; |
586 | else | 602 | else { |
587 | ret = pccard_get_configuration_info(s, | 603 | struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function); |
588 | buf->config.Function, &buf->config); | 604 | ret = pccard_get_configuration_info(s, p_dev, &buf->config); |
605 | pcmcia_put_dev(p_dev); | ||
606 | } | ||
589 | break; | 607 | break; |
590 | case DS_GET_FIRST_TUPLE: | 608 | case DS_GET_FIRST_TUPLE: |
591 | down(&s->skt_sem); | 609 | mutex_lock(&s->skt_mutex); |
592 | pcmcia_validate_mem(s); | 610 | pcmcia_validate_mem(s); |
593 | up(&s->skt_sem); | 611 | mutex_unlock(&s->skt_mutex); |
594 | ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple); | 612 | ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple); |
595 | break; | 613 | break; |
596 | case DS_GET_NEXT_TUPLE: | 614 | case DS_GET_NEXT_TUPLE: |
@@ -609,16 +627,19 @@ static int ds_ioctl(struct inode * inode, struct file * file, | |||
609 | ret = pccard_reset_card(s); | 627 | ret = pccard_reset_card(s); |
610 | break; | 628 | break; |
611 | case DS_GET_STATUS: | 629 | case DS_GET_STATUS: |
612 | if (buf->status.Function && | 630 | if (buf->status.Function && |
613 | (buf->status.Function >= s->functions)) | 631 | (buf->status.Function >= s->functions)) |
614 | ret = CS_BAD_ARGS; | 632 | ret = CS_BAD_ARGS; |
615 | else | 633 | else { |
616 | ret = pccard_get_status(s, buf->status.Function, &buf->status); | 634 | struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function); |
617 | break; | 635 | ret = pccard_get_status(s, p_dev, &buf->status); |
636 | pcmcia_put_dev(p_dev); | ||
637 | } | ||
638 | break; | ||
618 | case DS_VALIDATE_CIS: | 639 | case DS_VALIDATE_CIS: |
619 | down(&s->skt_sem); | 640 | mutex_lock(&s->skt_mutex); |
620 | pcmcia_validate_mem(s); | 641 | pcmcia_validate_mem(s); |
621 | up(&s->skt_sem); | 642 | mutex_unlock(&s->skt_mutex); |
622 | ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo); | 643 | ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo); |
623 | break; | 644 | break; |
624 | case DS_SUSPEND_CARD: | 645 | case DS_SUSPEND_CARD: |
@@ -638,12 +659,16 @@ static int ds_ioctl(struct inode * inode, struct file * file, | |||
638 | err = -EPERM; | 659 | err = -EPERM; |
639 | goto free_out; | 660 | goto free_out; |
640 | } | 661 | } |
641 | if (buf->conf_reg.Function && | 662 | |
642 | (buf->conf_reg.Function >= s->functions)) | 663 | ret = CS_BAD_ARGS; |
643 | ret = CS_BAD_ARGS; | 664 | |
644 | else | 665 | if (!(buf->conf_reg.Function && |
645 | ret = pccard_access_configuration_register(s, | 666 | (buf->conf_reg.Function >= s->functions))) { |
646 | buf->conf_reg.Function, &buf->conf_reg); | 667 | struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->conf_reg.Function); |
668 | if (p_dev) | ||
669 | ret = pcmcia_access_configuration_register(p_dev, &buf->conf_reg); | ||
670 | pcmcia_put_dev(p_dev); | ||
671 | } | ||
647 | break; | 672 | break; |
648 | case DS_GET_FIRST_REGION: | 673 | case DS_GET_FIRST_REGION: |
649 | case DS_GET_NEXT_REGION: | 674 | case DS_GET_NEXT_REGION: |