diff options
Diffstat (limited to 'drivers/input/joystick/db9.c')
-rw-r--r-- | drivers/input/joystick/db9.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c index cfdd3acf06a1..fbd3eed07f90 100644 --- a/drivers/input/joystick/db9.c +++ b/drivers/input/joystick/db9.c | |||
@@ -87,7 +87,7 @@ __obsolete_setup("db9_3="); | |||
87 | #define DB9_NORMAL 0x0a | 87 | #define DB9_NORMAL 0x0a |
88 | #define DB9_NOSELECT 0x08 | 88 | #define DB9_NOSELECT 0x08 |
89 | 89 | ||
90 | #define DB9_MAX_DEVICES 2 | 90 | #define DB9_MAX_DEVICES 2 |
91 | 91 | ||
92 | #define DB9_GENESIS6_DELAY 14 | 92 | #define DB9_GENESIS6_DELAY 14 |
93 | #define DB9_REFRESH_TIME HZ/100 | 93 | #define DB9_REFRESH_TIME HZ/100 |
@@ -98,6 +98,7 @@ struct db9 { | |||
98 | struct pardevice *pd; | 98 | struct pardevice *pd; |
99 | int mode; | 99 | int mode; |
100 | int used; | 100 | int used; |
101 | struct semaphore sem; | ||
101 | char phys[2][32]; | 102 | char phys[2][32]; |
102 | }; | 103 | }; |
103 | 104 | ||
@@ -503,6 +504,11 @@ static int db9_open(struct input_dev *dev) | |||
503 | { | 504 | { |
504 | struct db9 *db9 = dev->private; | 505 | struct db9 *db9 = dev->private; |
505 | struct parport *port = db9->pd->port; | 506 | struct parport *port = db9->pd->port; |
507 | int err; | ||
508 | |||
509 | err = down_interruptible(&db9->sem); | ||
510 | if (err) | ||
511 | return err; | ||
506 | 512 | ||
507 | if (!db9->used++) { | 513 | if (!db9->used++) { |
508 | parport_claim(db9->pd); | 514 | parport_claim(db9->pd); |
@@ -514,6 +520,7 @@ static int db9_open(struct input_dev *dev) | |||
514 | mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); | 520 | mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); |
515 | } | 521 | } |
516 | 522 | ||
523 | up(&db9->sem); | ||
517 | return 0; | 524 | return 0; |
518 | } | 525 | } |
519 | 526 | ||
@@ -522,12 +529,14 @@ static void db9_close(struct input_dev *dev) | |||
522 | struct db9 *db9 = dev->private; | 529 | struct db9 *db9 = dev->private; |
523 | struct parport *port = db9->pd->port; | 530 | struct parport *port = db9->pd->port; |
524 | 531 | ||
532 | down(&db9->sem); | ||
525 | if (!--db9->used) { | 533 | if (!--db9->used) { |
526 | del_timer(&db9->timer); | 534 | del_timer_sync(&db9->timer); |
527 | parport_write_control(port, 0x00); | 535 | parport_write_control(port, 0x00); |
528 | parport_data_forward(port); | 536 | parport_data_forward(port); |
529 | parport_release(db9->pd); | 537 | parport_release(db9->pd); |
530 | } | 538 | } |
539 | up(&db9->sem); | ||
531 | } | 540 | } |
532 | 541 | ||
533 | static struct db9 __init *db9_probe(int *config, int nargs) | 542 | static struct db9 __init *db9_probe(int *config, int nargs) |
@@ -563,12 +572,12 @@ static struct db9 __init *db9_probe(int *config, int nargs) | |||
563 | } | 572 | } |
564 | } | 573 | } |
565 | 574 | ||
566 | if (!(db9 = kmalloc(sizeof(struct db9), GFP_KERNEL))) { | 575 | if (!(db9 = kcalloc(1, sizeof(struct db9), GFP_KERNEL))) { |
567 | parport_put_port(pp); | 576 | parport_put_port(pp); |
568 | return NULL; | 577 | return NULL; |
569 | } | 578 | } |
570 | memset(db9, 0, sizeof(struct db9)); | ||
571 | 579 | ||
580 | init_MUTEX(&db9->sem); | ||
572 | db9->mode = config[1]; | 581 | db9->mode = config[1]; |
573 | init_timer(&db9->timer); | 582 | init_timer(&db9->timer); |
574 | db9->timer.data = (long) db9; | 583 | db9->timer.data = (long) db9; |