aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2011-12-30 18:16:45 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2011-12-30 18:26:36 -0500
commitee9dfd7a1d1256b0f51a0bf54bed0a8927c8e2ea (patch)
tree68969aa5568644cc3908f07371992aedba70f7f0 /drivers/input
parent509f87c5f564627b6b9fc763e74ef3608213d610 (diff)
Input: psmouse - make sure we do not use stale methods
Several protocol initialization routines can fail after they set up psmouse methods, such as reconnect and disconnect. This may lead to these stale methods used with different protocol that they were intended to be used for and may cause unpredictavle behavior and/or crashes. Make sure we start with a clean slate before executing each and every protocol detection and/or initialization routine. Reported-by: Paul Fox <pgf@laptop.org> Acked-by: Tai-hwa Liang <avatar@sentelic.com> Acked-by: Paul Fox <pgf@laptop.org> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/mouse/psmouse-base.c193
1 files changed, 124 insertions, 69 deletions
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 200be9c9dbc..de7e8bc17b1 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -418,6 +418,49 @@ int psmouse_reset(struct psmouse *psmouse)
418 return 0; 418 return 0;
419} 419}
420 420
421/*
422 * Here we set the mouse resolution.
423 */
424
425void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
426{
427 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
428 unsigned char p;
429
430 if (resolution == 0 || resolution > 200)
431 resolution = 200;
432
433 p = params[resolution / 50];
434 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
435 psmouse->resolution = 25 << p;
436}
437
438/*
439 * Here we set the mouse report rate.
440 */
441
442static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
443{
444 static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
445 unsigned char r;
446 int i = 0;
447
448 while (rates[i] > rate) i++;
449 r = rates[i];
450 ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE);
451 psmouse->rate = r;
452}
453
454/*
455 * psmouse_poll() - default poll handler. Everyone except for ALPS uses it.
456 */
457
458static int psmouse_poll(struct psmouse *psmouse)
459{
460 return ps2_command(&psmouse->ps2dev, psmouse->packet,
461 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8));
462}
463
421 464
422/* 465/*
423 * Genius NetMouse magic init. 466 * Genius NetMouse magic init.
@@ -603,6 +646,56 @@ static int cortron_detect(struct psmouse *psmouse, bool set_properties)
603} 646}
604 647
605/* 648/*
649 * Apply default settings to the psmouse structure. Most of them will
650 * be overridden by individual protocol initialization routines.
651 */
652
653static void psmouse_apply_defaults(struct psmouse *psmouse)
654{
655 struct input_dev *input_dev = psmouse->dev;
656
657 memset(input_dev->evbit, 0, sizeof(input_dev->evbit));
658 memset(input_dev->keybit, 0, sizeof(input_dev->keybit));
659 memset(input_dev->relbit, 0, sizeof(input_dev->relbit));
660 memset(input_dev->absbit, 0, sizeof(input_dev->absbit));
661 memset(input_dev->mscbit, 0, sizeof(input_dev->mscbit));
662
663 __set_bit(EV_KEY, input_dev->evbit);
664 __set_bit(EV_REL, input_dev->evbit);
665
666 __set_bit(BTN_LEFT, input_dev->keybit);
667 __set_bit(BTN_RIGHT, input_dev->keybit);
668
669 __set_bit(REL_X, input_dev->relbit);
670 __set_bit(REL_Y, input_dev->relbit);
671
672 psmouse->set_rate = psmouse_set_rate;
673 psmouse->set_resolution = psmouse_set_resolution;
674 psmouse->poll = psmouse_poll;
675 psmouse->protocol_handler = psmouse_process_byte;
676 psmouse->pktsize = 3;
677 psmouse->reconnect = NULL;
678 psmouse->disconnect = NULL;
679 psmouse->cleanup = NULL;
680 psmouse->pt_activate = NULL;
681 psmouse->pt_deactivate = NULL;
682}
683
684/*
685 * Apply default settings to the psmouse structure and call specified
686 * protocol detection or initialization routine.
687 */
688static int psmouse_do_detect(int (*detect)(struct psmouse *psmouse,
689 bool set_properties),
690 struct psmouse *psmouse, bool set_properties)
691{
692 if (set_properties)
693 psmouse_apply_defaults(psmouse);
694
695 return detect(psmouse, set_properties);
696}
697
698/*
606 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol 699 * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
607 * the mouse may have. 700 * the mouse may have.
608 */ 701 */
@@ -616,7 +709,7 @@ static int psmouse_extensions(struct psmouse *psmouse,
616 * We always check for lifebook because it does not disturb mouse 709 * We always check for lifebook because it does not disturb mouse
617 * (it only checks DMI information). 710 * (it only checks DMI information).
618 */ 711 */
619 if (lifebook_detect(psmouse, set_properties) == 0) { 712 if (psmouse_do_detect(lifebook_detect, psmouse, set_properties) == 0) {
620 if (max_proto > PSMOUSE_IMEX) { 713 if (max_proto > PSMOUSE_IMEX) {
621 if (!set_properties || lifebook_init(psmouse) == 0) 714 if (!set_properties || lifebook_init(psmouse) == 0)
622 return PSMOUSE_LIFEBOOK; 715 return PSMOUSE_LIFEBOOK;
@@ -628,15 +721,18 @@ static int psmouse_extensions(struct psmouse *psmouse,
628 * upsets the thinkingmouse). 721 * upsets the thinkingmouse).
629 */ 722 */
630 723
631 if (max_proto > PSMOUSE_IMEX && thinking_detect(psmouse, set_properties) == 0) 724 if (max_proto > PSMOUSE_IMEX &&
725 psmouse_do_detect(thinking_detect, psmouse, set_properties) == 0) {
632 return PSMOUSE_THINKPS; 726 return PSMOUSE_THINKPS;
727 }
633 728
634/* 729/*
635 * Try Synaptics TouchPad. Note that probing is done even if Synaptics protocol 730 * Try Synaptics TouchPad. Note that probing is done even if Synaptics protocol
636 * support is disabled in config - we need to know if it is synaptics so we 731 * support is disabled in config - we need to know if it is synaptics so we
637 * can reset it properly after probing for intellimouse. 732 * can reset it properly after probing for intellimouse.
638 */ 733 */
639 if (max_proto > PSMOUSE_PS2 && synaptics_detect(psmouse, set_properties) == 0) { 734 if (max_proto > PSMOUSE_PS2 &&
735 psmouse_do_detect(synaptics_detect, psmouse, set_properties) == 0) {
640 synaptics_hardware = true; 736 synaptics_hardware = true;
641 737
642 if (max_proto > PSMOUSE_IMEX) { 738 if (max_proto > PSMOUSE_IMEX) {
@@ -667,7 +763,8 @@ static int psmouse_extensions(struct psmouse *psmouse,
667 */ 763 */
668 if (max_proto > PSMOUSE_IMEX) { 764 if (max_proto > PSMOUSE_IMEX) {
669 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); 765 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
670 if (alps_detect(psmouse, set_properties) == 0) { 766 if (psmouse_do_detect(alps_detect,
767 psmouse, set_properties) == 0) {
671 if (!set_properties || alps_init(psmouse) == 0) 768 if (!set_properties || alps_init(psmouse) == 0)
672 return PSMOUSE_ALPS; 769 return PSMOUSE_ALPS;
673/* 770/*
@@ -681,7 +778,7 @@ static int psmouse_extensions(struct psmouse *psmouse,
681 * Try OLPC HGPK touchpad. 778 * Try OLPC HGPK touchpad.
682 */ 779 */
683 if (max_proto > PSMOUSE_IMEX && 780 if (max_proto > PSMOUSE_IMEX &&
684 hgpk_detect(psmouse, set_properties) == 0) { 781 psmouse_do_detect(hgpk_detect, psmouse, set_properties) == 0) {
685 if (!set_properties || hgpk_init(psmouse) == 0) 782 if (!set_properties || hgpk_init(psmouse) == 0)
686 return PSMOUSE_HGPK; 783 return PSMOUSE_HGPK;
687/* 784/*
@@ -694,7 +791,7 @@ static int psmouse_extensions(struct psmouse *psmouse,
694 * Try Elantech touchpad. 791 * Try Elantech touchpad.
695 */ 792 */
696 if (max_proto > PSMOUSE_IMEX && 793 if (max_proto > PSMOUSE_IMEX &&
697 elantech_detect(psmouse, set_properties) == 0) { 794 psmouse_do_detect(elantech_detect, psmouse, set_properties) == 0) {
698 if (!set_properties || elantech_init(psmouse) == 0) 795 if (!set_properties || elantech_init(psmouse) == 0)
699 return PSMOUSE_ELANTECH; 796 return PSMOUSE_ELANTECH;
700/* 797/*
@@ -703,18 +800,21 @@ static int psmouse_extensions(struct psmouse *psmouse,
703 max_proto = PSMOUSE_IMEX; 800 max_proto = PSMOUSE_IMEX;
704 } 801 }
705 802
706
707 if (max_proto > PSMOUSE_IMEX) { 803 if (max_proto > PSMOUSE_IMEX) {
708 if (genius_detect(psmouse, set_properties) == 0) 804 if (psmouse_do_detect(genius_detect,
805 psmouse, set_properties) == 0)
709 return PSMOUSE_GENPS; 806 return PSMOUSE_GENPS;
710 807
711 if (ps2pp_init(psmouse, set_properties) == 0) 808 if (psmouse_do_detect(ps2pp_init,
809 psmouse, set_properties) == 0)
712 return PSMOUSE_PS2PP; 810 return PSMOUSE_PS2PP;
713 811
714 if (trackpoint_detect(psmouse, set_properties) == 0) 812 if (psmouse_do_detect(trackpoint_detect,
813 psmouse, set_properties) == 0)
715 return PSMOUSE_TRACKPOINT; 814 return PSMOUSE_TRACKPOINT;
716 815
717 if (touchkit_ps2_detect(psmouse, set_properties) == 0) 816 if (psmouse_do_detect(touchkit_ps2_detect,
817 psmouse, set_properties) == 0)
718 return PSMOUSE_TOUCHKIT_PS2; 818 return PSMOUSE_TOUCHKIT_PS2;
719 } 819 }
720 820
@@ -723,7 +823,8 @@ static int psmouse_extensions(struct psmouse *psmouse,
723 * Trackpoint devices (causing TP_READ_ID command to time out). 823 * Trackpoint devices (causing TP_READ_ID command to time out).
724 */ 824 */
725 if (max_proto > PSMOUSE_IMEX) { 825 if (max_proto > PSMOUSE_IMEX) {
726 if (fsp_detect(psmouse, set_properties) == 0) { 826 if (psmouse_do_detect(fsp_detect,
827 psmouse, set_properties) == 0) {
727 if (!set_properties || fsp_init(psmouse) == 0) 828 if (!set_properties || fsp_init(psmouse) == 0)
728 return PSMOUSE_FSP; 829 return PSMOUSE_FSP;
729/* 830/*
@@ -741,17 +842,23 @@ static int psmouse_extensions(struct psmouse *psmouse,
741 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); 842 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
742 psmouse_reset(psmouse); 843 psmouse_reset(psmouse);
743 844
744 if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse, set_properties) == 0) 845 if (max_proto >= PSMOUSE_IMEX &&
846 psmouse_do_detect(im_explorer_detect,
847 psmouse, set_properties) == 0) {
745 return PSMOUSE_IMEX; 848 return PSMOUSE_IMEX;
849 }
746 850
747 if (max_proto >= PSMOUSE_IMPS && intellimouse_detect(psmouse, set_properties) == 0) 851 if (max_proto >= PSMOUSE_IMPS &&
852 psmouse_do_detect(intellimouse_detect,
853 psmouse, set_properties) == 0) {
748 return PSMOUSE_IMPS; 854 return PSMOUSE_IMPS;
855 }
749 856
750/* 857/*
751 * Okay, all failed, we have a standard mouse here. The number of the buttons 858 * Okay, all failed, we have a standard mouse here. The number of the buttons
752 * is still a question, though. We assume 3. 859 * is still a question, though. We assume 3.
753 */ 860 */
754 ps2bare_detect(psmouse, set_properties); 861 psmouse_do_detect(ps2bare_detect, psmouse, set_properties);
755 862
756 if (synaptics_hardware) { 863 if (synaptics_hardware) {
757/* 864/*
@@ -965,39 +1072,6 @@ static int psmouse_probe(struct psmouse *psmouse)
965} 1072}
966 1073
967/* 1074/*
968 * Here we set the mouse resolution.
969 */
970
971void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
972{
973 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
974 unsigned char p;
975
976 if (resolution == 0 || resolution > 200)
977 resolution = 200;
978
979 p = params[resolution / 50];
980 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
981 psmouse->resolution = 25 << p;
982}
983
984/*
985 * Here we set the mouse report rate.
986 */
987
988static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
989{
990 static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
991 unsigned char r;
992 int i = 0;
993
994 while (rates[i] > rate) i++;
995 r = rates[i];
996 ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE);
997 psmouse->rate = r;
998}
999
1000/*
1001 * psmouse_initialize() initializes the mouse to a sane state. 1075 * psmouse_initialize() initializes the mouse to a sane state.
1002 */ 1076 */
1003 1077
@@ -1042,16 +1116,6 @@ static void psmouse_deactivate(struct psmouse *psmouse)
1042 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 1116 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1043} 1117}
1044 1118
1045/*
1046 * psmouse_poll() - default poll handler. Everyone except for ALPS uses it.
1047 */
1048
1049static int psmouse_poll(struct psmouse *psmouse)
1050{
1051 return ps2_command(&psmouse->ps2dev, psmouse->packet,
1052 PSMOUSE_CMD_POLL | (psmouse->pktsize << 8));
1053}
1054
1055 1119
1056/* 1120/*
1057 * psmouse_resync() attempts to re-validate current protocol. 1121 * psmouse_resync() attempts to re-validate current protocol.
@@ -1252,18 +1316,9 @@ static int psmouse_switch_protocol(struct psmouse *psmouse,
1252 1316
1253 input_dev->dev.parent = &psmouse->ps2dev.serio->dev; 1317 input_dev->dev.parent = &psmouse->ps2dev.serio->dev;
1254 1318
1255 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
1256 input_dev->keybit[BIT_WORD(BTN_MOUSE)] =
1257 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
1258 input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
1259
1260 psmouse->set_rate = psmouse_set_rate;
1261 psmouse->set_resolution = psmouse_set_resolution;
1262 psmouse->poll = psmouse_poll;
1263 psmouse->protocol_handler = psmouse_process_byte;
1264 psmouse->pktsize = 3;
1265
1266 if (proto && (proto->detect || proto->init)) { 1319 if (proto && (proto->detect || proto->init)) {
1320 psmouse_apply_defaults(psmouse);
1321
1267 if (proto->detect && proto->detect(psmouse, true) < 0) 1322 if (proto->detect && proto->detect(psmouse, true) < 0)
1268 return -1; 1323 return -1;
1269 1324