aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pcmcia/cs.c
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2010-07-11 04:04:59 -0400
committerDominik Brodowski <linux@dominikbrodowski.net>2010-07-30 15:07:32 -0400
commit216d7cdd3b060518a2d4faf584eb15ef5af862b6 (patch)
tree5ab7b1de96ee277f5b1932ba192e9c80fd2418a7 /drivers/pcmcia/cs.c
parent5716d415f8c5a17d44f6e1d5a1e4998f7306a93b (diff)
pcmcia: simplify event callback
The event callback for handling 16bit PCMCIA cards only needs to be informed about a few events. Furthermore, send_event may already only be called with skt->skt_mutex held, which also protects against the module being removed behind the callback's back. Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers/pcmcia/cs.c')
-rw-r--r--drivers/pcmcia/cs.c44
1 files changed, 10 insertions, 34 deletions
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 976d80706eae..5ea196724f5b 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -264,8 +264,6 @@ EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
264 264
265static int send_event(struct pcmcia_socket *s, event_t event, int priority) 265static int send_event(struct pcmcia_socket *s, event_t event, int priority)
266{ 266{
267 int ret;
268
269 if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL)) 267 if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL))
270 return 0; 268 return 0;
271 269
@@ -274,14 +272,8 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority)
274 272
275 if (!s->callback) 273 if (!s->callback)
276 return 0; 274 return 0;
277 if (!try_module_get(s->callback->owner))
278 return 0;
279 275
280 ret = s->callback->event(s, event, priority); 276 return s->callback->event(s, event, priority);
281
282 module_put(s->callback->owner);
283
284 return ret;
285} 277}
286 278
287static int socket_reset(struct pcmcia_socket *skt) 279static int socket_reset(struct pcmcia_socket *skt)
@@ -494,7 +486,6 @@ static int socket_suspend(struct pcmcia_socket *skt)
494 mutex_lock(&skt->ops_mutex); 486 mutex_lock(&skt->ops_mutex);
495 skt->suspended_state = skt->state; 487 skt->suspended_state = skt->state;
496 488
497 send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW);
498 skt->socket = dead_socket; 489 skt->socket = dead_socket;
499 skt->ops->set_socket(skt, &skt->socket); 490 skt->ops->set_socket(skt, &skt->socket);
500 if (skt->ops->suspend) 491 if (skt->ops->suspend)
@@ -654,16 +645,8 @@ static int pccardd(void *__skt)
654 spin_unlock_irqrestore(&skt->thread_lock, flags); 645 spin_unlock_irqrestore(&skt->thread_lock, flags);
655 646
656 mutex_lock(&skt->skt_mutex); 647 mutex_lock(&skt->skt_mutex);
657 if (events) { 648 if (events & SS_DETECT)
658 if (events & SS_DETECT) 649 socket_detect_change(skt);
659 socket_detect_change(skt);
660 if (events & SS_BATDEAD)
661 send_event(skt, CS_EVENT_BATTERY_DEAD, CS_EVENT_PRI_LOW);
662 if (events & SS_BATWARN)
663 send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW);
664 if (events & SS_READY)
665 send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW);
666 }
667 650
668 if (sysfs_events) { 651 if (sysfs_events) {
669 if (sysfs_events & PCMCIA_UEVENT_EJECT) 652 if (sysfs_events & PCMCIA_UEVENT_EJECT)
@@ -823,20 +806,13 @@ int pcmcia_reset_card(struct pcmcia_socket *skt)
823 break; 806 break;
824 } 807 }
825 808
826 ret = send_event(skt, CS_EVENT_RESET_REQUEST, CS_EVENT_PRI_LOW); 809 if (skt->callback)
827 if (ret == 0) { 810 skt->callback->suspend(skt);
828 send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); 811 mutex_lock(&skt->ops_mutex);
829 if (skt->callback) 812 ret = socket_reset(skt);
830 skt->callback->suspend(skt); 813 mutex_unlock(&skt->ops_mutex);
831 mutex_lock(&skt->ops_mutex); 814 if ((ret == 0) && (skt->callback))
832 ret = socket_reset(skt); 815 skt->callback->resume(skt);
833 mutex_unlock(&skt->ops_mutex);
834 if (ret == 0) {
835 send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW);
836 if (skt->callback)
837 skt->callback->resume(skt);
838 }
839 }
840 816
841 ret = 0; 817 ret = 0;
842 } while (0); 818 } while (0);