Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: psmouse - use switch statement in psmouse_process_byte()

Instead of a series mostly exclusive "if" statements testing protocol type
of the mouse let's use "switch" statement.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Marcin Sochacki <msochacki+kernel@gmail.com>
Tested-by: Till <till2.schaefer@uni-dortmund.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+32 -35
+32 -35
drivers/input/mouse/psmouse-base.c
··· 138 138 if (psmouse->pktcnt < psmouse->pktsize) 139 139 return PSMOUSE_GOOD_DATA; 140 140 141 - /* 142 - * Full packet accumulated, process it 143 - */ 141 + /* Full packet accumulated, process it */ 144 142 145 - /* 146 - * Scroll wheel on IntelliMice, scroll buttons on NetMice 147 - */ 148 - 149 - if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS) 143 + switch (psmouse->type) { 144 + case PSMOUSE_IMPS: 145 + /* IntelliMouse has scroll wheel */ 150 146 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); 147 + break; 151 148 152 - /* 153 - * Scroll wheel and buttons on IntelliMouse Explorer 154 - */ 155 - 156 - if (psmouse->type == PSMOUSE_IMEX) { 149 + case PSMOUSE_IMEX: 150 + /* Scroll wheel and buttons on IntelliMouse Explorer */ 157 151 switch (packet[3] & 0xC0) { 158 152 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */ 159 153 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); ··· 162 168 input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1); 163 169 break; 164 170 } 165 - } 171 + break; 166 172 167 - /* 168 - * Extra buttons on Genius NewNet 3D 169 - */ 173 + case PSMOUSE_GENPS: 174 + /* Report scroll buttons on NetMice */ 175 + input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); 170 176 171 - if (psmouse->type == PSMOUSE_GENPS) { 177 + /* Extra buttons on Genius NewNet 3D */ 172 178 input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1); 173 179 input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1); 174 - } 180 + break; 175 181 176 - /* 177 - * Extra button on ThinkingMouse 178 - */ 179 - if (psmouse->type == PSMOUSE_THINKPS) { 182 + case PSMOUSE_THINKPS: 183 + /* Extra button on ThinkingMouse */ 180 184 input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1); 181 - /* Without this bit of weirdness moving up gives wildly high Y changes. */ 182 - packet[1] |= (packet[0] & 0x40) << 1; 183 - } 184 185 185 - /* 186 - * Cortron PS2 Trackball reports SIDE button on the 4th bit of the first 187 - * byte. 188 - */ 189 - if (psmouse->type == PSMOUSE_CORTRON) { 186 + /* 187 + * Without this bit of weirdness moving up gives wildly 188 + * high Y changes. 189 + */ 190 + packet[1] |= (packet[0] & 0x40) << 1; 191 + break; 192 + 193 + case PSMOUSE_CORTRON: 194 + /* 195 + * Cortron PS2 Trackball reports SIDE button in the 196 + * 4th bit of the first byte. 197 + */ 190 198 input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1); 191 199 packet[0] |= 0x08; 200 + break; 201 + 202 + default: 203 + break; 192 204 } 193 205 194 - /* 195 - * Generic PS/2 Mouse 196 - */ 197 - 206 + /* Generic PS/2 Mouse */ 198 207 input_report_key(dev, BTN_LEFT, packet[0] & 1); 199 208 input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); 200 209 input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);