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

Input: lifebook - clean up code

- use u8 instead of unsigned char for byte data
- use input_set_capability() instead of manipulating capabilities bits
directly
- do not abuse -1 as error code, propagate errors from various calls.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+29 -21
+29 -21
drivers/input/mouse/lifebook.c
··· 17 17 #include <linux/libps2.h> 18 18 #include <linux/dmi.h> 19 19 #include <linux/slab.h> 20 + #include <linux/types.h> 20 21 21 22 #include "psmouse.h" 22 23 #include "lifebook.h" ··· 137 136 struct lifebook_data *priv = psmouse->private; 138 137 struct input_dev *dev1 = psmouse->dev; 139 138 struct input_dev *dev2 = priv ? priv->dev2 : NULL; 140 - unsigned char *packet = psmouse->packet; 139 + u8 *packet = psmouse->packet; 141 140 bool relative_packet = packet[0] & 0x08; 142 141 143 142 if (relative_packet || !lifebook_use_6byte_proto) { ··· 202 201 static int lifebook_absolute_mode(struct psmouse *psmouse) 203 202 { 204 203 struct ps2dev *ps2dev = &psmouse->ps2dev; 205 - unsigned char param; 204 + u8 param; 205 + int error; 206 206 207 - if (psmouse_reset(psmouse)) 208 - return -1; 207 + error = psmouse_reset(psmouse); 208 + if (error) 209 + return error; 209 210 210 211 /* 211 212 * Enable absolute output -- ps2_command fails always but if ··· 223 220 static void lifebook_relative_mode(struct psmouse *psmouse) 224 221 { 225 222 struct ps2dev *ps2dev = &psmouse->ps2dev; 226 - unsigned char param = 0x06; 223 + u8 param = 0x06; 227 224 228 225 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES); 229 226 } 230 227 231 228 static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution) 232 229 { 233 - static const unsigned char params[] = { 0, 1, 2, 2, 3 }; 234 - unsigned char p; 230 + static const u8 params[] = { 0, 1, 2, 2, 3 }; 231 + u8 p; 235 232 236 233 if (resolution == 0 || resolution > 400) 237 234 resolution = 400; ··· 256 253 int lifebook_detect(struct psmouse *psmouse, bool set_properties) 257 254 { 258 255 if (!lifebook_present) 259 - return -1; 256 + return -ENXIO; 260 257 261 258 if (desired_serio_phys && 262 259 strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys)) 263 - return -1; 260 + return -ENXIO; 264 261 265 262 if (set_properties) { 266 263 psmouse->vendor = "Fujitsu"; ··· 293 290 dev2->id.version = 0x0000; 294 291 dev2->dev.parent = &psmouse->ps2dev.serio->dev; 295 292 296 - dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 297 - dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 298 - dev2->keybit[BIT_WORD(BTN_LEFT)] = 299 - BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); 293 + input_set_capability(dev2, EV_REL, REL_X); 294 + input_set_capability(dev2, EV_REL, REL_Y); 295 + input_set_capability(dev2, EV_KEY, BTN_LEFT); 296 + input_set_capability(dev2, EV_KEY, BTN_RIGHT); 300 297 301 298 error = input_register_device(priv->dev2); 302 299 if (error) ··· 315 312 { 316 313 struct input_dev *dev1 = psmouse->dev; 317 314 int max_coord = lifebook_use_6byte_proto ? 4096 : 1024; 315 + int error; 318 316 319 - if (lifebook_absolute_mode(psmouse)) 320 - return -1; 317 + error = lifebook_absolute_mode(psmouse); 318 + if (error) 319 + return error; 321 320 322 - dev1->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); 323 - dev1->relbit[0] = 0; 324 - dev1->keybit[BIT_WORD(BTN_MOUSE)] = 0; 325 - dev1->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 321 + /* Clear default capabilities */ 322 + bitmap_zero(dev1->evbit, EV_CNT); 323 + bitmap_zero(dev1->relbit, REL_CNT); 324 + bitmap_zero(dev1->keybit, KEY_CNT); 325 + 326 + input_set_capability(dev1, EV_KEY, BTN_TOUCH); 326 327 input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0); 327 328 input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0); 328 329 329 330 if (!desired_serio_phys) { 330 - if (lifebook_create_relative_device(psmouse)) { 331 + error = lifebook_create_relative_device(psmouse); 332 + if (error) { 331 333 lifebook_relative_mode(psmouse); 332 - return -1; 334 + return error; 333 335 } 334 336 } 335 337