Commit 16ff7cb1848a8898ff19f77b4a9632a73ff98457
1 parent
91c5d67f17
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
Input: tca8418-keypad - switch to using managed resources
Let's switch to using devm_*() interfaces to manage our resources, thus will simplify error unwinding a bit. Reviewed-by: Alban Bedel <alban.bedel@avionic-design.de> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Showing 1 changed file with 25 additions and 53 deletions Side-by-side Diff
drivers/input/keyboard/tca8418_keypad.c
... | ... | @@ -111,14 +111,10 @@ |
111 | 111 | #define KEY_EVENT_VALUE 0x80 |
112 | 112 | |
113 | 113 | struct tca8418_keypad { |
114 | - unsigned int irq; | |
115 | - unsigned int row_shift; | |
116 | - | |
117 | 114 | struct i2c_client *client; |
118 | 115 | struct input_dev *input; |
119 | 116 | |
120 | - /* Flexible array member, must be at end of struct */ | |
121 | - unsigned short keymap[]; | |
117 | + unsigned int row_shift; | |
122 | 118 | }; |
123 | 119 | |
124 | 120 | /* |
... | ... | @@ -163,6 +159,8 @@ |
163 | 159 | |
164 | 160 | static void tca8418_read_keypad(struct tca8418_keypad *keypad_data) |
165 | 161 | { |
162 | + struct input_dev *input = keypad_data->input; | |
163 | + unsigned short *keymap = input->keycode; | |
166 | 164 | int error, col, row; |
167 | 165 | u8 reg, state, code; |
168 | 166 | |
... | ... | @@ -181,9 +179,8 @@ |
181 | 179 | col = (col) ? col - 1 : TCA8418_MAX_COLS - 1; |
182 | 180 | |
183 | 181 | code = MATRIX_SCAN_CODE(row, col, keypad_data->row_shift); |
184 | - input_event(keypad_data->input, EV_MSC, MSC_SCAN, code); | |
185 | - input_report_key(keypad_data->input, | |
186 | - keypad_data->keymap[code], state); | |
182 | + input_event(input, EV_MSC, MSC_SCAN, code); | |
183 | + input_report_key(input, keymap[code], state); | |
187 | 184 | |
188 | 185 | /* Read for next loop */ |
189 | 186 | error = tca8418_read_byte(keypad_data, REG_KEY_EVENT_A, ®); |
... | ... | @@ -193,7 +190,7 @@ |
193 | 190 | dev_err(&keypad_data->client->dev, |
194 | 191 | "unable to read REG_KEY_EVENT_A\n"); |
195 | 192 | |
196 | - input_sync(keypad_data->input); | |
193 | + input_sync(input); | |
197 | 194 | } |
198 | 195 | |
199 | 196 | /* |
... | ... | @@ -275,6 +272,7 @@ |
275 | 272 | u32 rows = 0, cols = 0; |
276 | 273 | bool rep = false; |
277 | 274 | bool irq_is_gpio = false; |
275 | + int irq; | |
278 | 276 | int error, row_shift, max_keys; |
279 | 277 | |
280 | 278 | /* Copy the platform data */ |
... | ... | @@ -315,9 +313,8 @@ |
315 | 313 | row_shift = get_count_order(cols); |
316 | 314 | max_keys = rows << row_shift; |
317 | 315 | |
318 | - /* Allocate memory for keypad_data, keymap and input device */ | |
319 | - keypad_data = kzalloc(sizeof(*keypad_data) + | |
320 | - max_keys * sizeof(keypad_data->keymap[0]), GFP_KERNEL); | |
316 | + /* Allocate memory for keypad_data and input device */ | |
317 | + keypad_data = devm_kzalloc(dev, sizeof(*keypad_data), GFP_KERNEL); | |
321 | 318 | if (!keypad_data) |
322 | 319 | return -ENOMEM; |
323 | 320 | |
324 | 321 | |
325 | 322 | |
326 | 323 | |
327 | 324 | |
... | ... | @@ -327,29 +324,26 @@ |
327 | 324 | /* Initialize the chip or fail if chip isn't present */ |
328 | 325 | error = tca8418_configure(keypad_data, rows, cols); |
329 | 326 | if (error < 0) |
330 | - goto fail1; | |
327 | + return error; | |
331 | 328 | |
332 | 329 | /* Configure input device */ |
333 | - input = input_allocate_device(); | |
334 | - if (!input) { | |
335 | - error = -ENOMEM; | |
336 | - goto fail1; | |
337 | - } | |
330 | + input = devm_input_allocate_device(dev); | |
331 | + if (!input) | |
332 | + return -ENOMEM; | |
333 | + | |
338 | 334 | keypad_data->input = input; |
339 | 335 | |
340 | 336 | input->name = client->name; |
341 | - input->dev.parent = &client->dev; | |
342 | - | |
343 | 337 | input->id.bustype = BUS_I2C; |
344 | 338 | input->id.vendor = 0x0001; |
345 | 339 | input->id.product = 0x001; |
346 | 340 | input->id.version = 0x0001; |
347 | 341 | |
348 | 342 | error = matrix_keypad_build_keymap(keymap_data, NULL, rows, cols, |
349 | - keypad_data->keymap, input); | |
343 | + NULL, input); | |
350 | 344 | if (error) { |
351 | 345 | dev_err(dev, "Failed to build keymap\n"); |
352 | - goto fail2; | |
346 | + return error; | |
353 | 347 | } |
354 | 348 | |
355 | 349 | if (rep) |
356 | 350 | |
357 | 351 | |
358 | 352 | |
359 | 353 | |
360 | 354 | |
361 | 355 | |
362 | 356 | |
... | ... | @@ -358,52 +352,31 @@ |
358 | 352 | |
359 | 353 | input_set_drvdata(input, keypad_data); |
360 | 354 | |
355 | + irq = client->irq; | |
361 | 356 | if (irq_is_gpio) |
362 | - client->irq = gpio_to_irq(client->irq); | |
357 | + irq = gpio_to_irq(irq); | |
363 | 358 | |
364 | - error = request_threaded_irq(client->irq, NULL, tca8418_irq_handler, | |
365 | - IRQF_TRIGGER_FALLING | | |
366 | - IRQF_SHARED | | |
367 | - IRQF_ONESHOT, | |
368 | - client->name, keypad_data); | |
359 | + error = devm_request_threaded_irq(dev, irq, NULL, tca8418_irq_handler, | |
360 | + IRQF_TRIGGER_FALLING | | |
361 | + IRQF_SHARED | | |
362 | + IRQF_ONESHOT, | |
363 | + client->name, keypad_data); | |
369 | 364 | if (error) { |
370 | 365 | dev_err(dev, "Unable to claim irq %d; error %d\n", |
371 | 366 | client->irq, error); |
372 | - goto fail2; | |
367 | + return error; | |
373 | 368 | } |
374 | 369 | |
375 | 370 | error = input_register_device(input); |
376 | 371 | if (error) { |
377 | 372 | dev_err(dev, "Unable to register input device, error: %d\n", |
378 | 373 | error); |
379 | - goto fail3; | |
374 | + return error; | |
380 | 375 | } |
381 | 376 | |
382 | - i2c_set_clientdata(client, keypad_data); | |
383 | 377 | return 0; |
384 | - | |
385 | -fail3: | |
386 | - free_irq(client->irq, keypad_data); | |
387 | -fail2: | |
388 | - input_free_device(input); | |
389 | -fail1: | |
390 | - kfree(keypad_data); | |
391 | - return error; | |
392 | 378 | } |
393 | 379 | |
394 | -static int tca8418_keypad_remove(struct i2c_client *client) | |
395 | -{ | |
396 | - struct tca8418_keypad *keypad_data = i2c_get_clientdata(client); | |
397 | - | |
398 | - free_irq(keypad_data->client->irq, keypad_data); | |
399 | - | |
400 | - input_unregister_device(keypad_data->input); | |
401 | - | |
402 | - kfree(keypad_data); | |
403 | - | |
404 | - return 0; | |
405 | -} | |
406 | - | |
407 | 380 | static const struct i2c_device_id tca8418_id[] = { |
408 | 381 | { TCA8418_NAME, 8418, }, |
409 | 382 | { } |
... | ... | @@ -425,7 +398,6 @@ |
425 | 398 | .of_match_table = of_match_ptr(tca8418_dt_ids), |
426 | 399 | }, |
427 | 400 | .probe = tca8418_keypad_probe, |
428 | - .remove = tca8418_keypad_remove, | |
429 | 401 | .id_table = tca8418_id, |
430 | 402 | }; |
431 | 403 |