diff options
| author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-04-21 01:33:08 -0400 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-04-21 02:06:49 -0400 |
| commit | 01111fcd42b050bdb7113a7c2c0aed2eaef67b53 (patch) | |
| tree | f6ecbee8e3962c8ff7c07c3f3997658fe5038707 /drivers/input | |
| parent | 0508c19a6fddd1ba5495004370e4fc2fd4a7d33a (diff) | |
Input: matrix-keypad - allocate keycodes with keypad structure
Instead of allocating and managing keymap separately from the keypad
structure stick it at the end as a variable-length array.
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
| -rw-r--r-- | drivers/input/keyboard/matrix_keypad.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 8714d680e2ed..a4ff08caa44b 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c | |||
| @@ -27,7 +27,6 @@ | |||
| 27 | struct matrix_keypad { | 27 | struct matrix_keypad { |
| 28 | const struct matrix_keypad_platform_data *pdata; | 28 | const struct matrix_keypad_platform_data *pdata; |
| 29 | struct input_dev *input_dev; | 29 | struct input_dev *input_dev; |
| 30 | unsigned short *keycodes; | ||
| 31 | unsigned int row_shift; | 30 | unsigned int row_shift; |
| 32 | 31 | ||
| 33 | DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS); | 32 | DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS); |
| @@ -38,6 +37,8 @@ struct matrix_keypad { | |||
| 38 | bool scan_pending; | 37 | bool scan_pending; |
| 39 | bool stopped; | 38 | bool stopped; |
| 40 | bool gpio_all_disabled; | 39 | bool gpio_all_disabled; |
| 40 | |||
| 41 | unsigned short keycodes[]; | ||
| 41 | }; | 42 | }; |
| 42 | 43 | ||
| 43 | /* | 44 | /* |
| @@ -381,8 +382,8 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
| 381 | const struct matrix_keymap_data *keymap_data; | 382 | const struct matrix_keymap_data *keymap_data; |
| 382 | struct matrix_keypad *keypad; | 383 | struct matrix_keypad *keypad; |
| 383 | struct input_dev *input_dev; | 384 | struct input_dev *input_dev; |
| 384 | unsigned short *keycodes; | ||
| 385 | unsigned int row_shift; | 385 | unsigned int row_shift; |
| 386 | size_t keymap_size; | ||
| 386 | int err; | 387 | int err; |
| 387 | 388 | ||
| 388 | pdata = pdev->dev.platform_data; | 389 | pdata = pdev->dev.platform_data; |
| @@ -398,20 +399,18 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
| 398 | } | 399 | } |
| 399 | 400 | ||
| 400 | row_shift = get_count_order(pdata->num_col_gpios); | 401 | row_shift = get_count_order(pdata->num_col_gpios); |
| 401 | 402 | keymap_size = (pdata->num_row_gpios << row_shift) * | |
| 402 | keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL); | 403 | sizeof(keypad->keycodes[0]); |
| 403 | keycodes = kzalloc((pdata->num_row_gpios << row_shift) * | 404 | keypad = kzalloc(sizeof(struct matrix_keypad) + keymap_size, |
| 404 | sizeof(*keycodes), | 405 | GFP_KERNEL); |
| 405 | GFP_KERNEL); | ||
| 406 | input_dev = input_allocate_device(); | 406 | input_dev = input_allocate_device(); |
| 407 | if (!keypad || !keycodes || !input_dev) { | 407 | if (!keypad || !input_dev) { |
| 408 | err = -ENOMEM; | 408 | err = -ENOMEM; |
| 409 | goto err_free_mem; | 409 | goto err_free_mem; |
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | keypad->input_dev = input_dev; | 412 | keypad->input_dev = input_dev; |
| 413 | keypad->pdata = pdata; | 413 | keypad->pdata = pdata; |
| 414 | keypad->keycodes = keycodes; | ||
| 415 | keypad->row_shift = row_shift; | 414 | keypad->row_shift = row_shift; |
| 416 | keypad->stopped = true; | 415 | keypad->stopped = true; |
| 417 | INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); | 416 | INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); |
| @@ -426,8 +425,8 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
| 426 | input_dev->open = matrix_keypad_start; | 425 | input_dev->open = matrix_keypad_start; |
| 427 | input_dev->close = matrix_keypad_stop; | 426 | input_dev->close = matrix_keypad_stop; |
| 428 | 427 | ||
| 429 | input_dev->keycode = keycodes; | 428 | input_dev->keycode = keypad->keycodes; |
| 430 | input_dev->keycodesize = sizeof(*keycodes); | 429 | input_dev->keycodesize = sizeof(keypad->keycodes[0]); |
| 431 | input_dev->keycodemax = pdata->num_row_gpios << row_shift; | 430 | input_dev->keycodemax = pdata->num_row_gpios << row_shift; |
| 432 | 431 | ||
| 433 | matrix_keypad_build_keymap(keymap_data, row_shift, | 432 | matrix_keypad_build_keymap(keymap_data, row_shift, |
| @@ -451,7 +450,6 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) | |||
| 451 | 450 | ||
| 452 | err_free_mem: | 451 | err_free_mem: |
| 453 | input_free_device(input_dev); | 452 | input_free_device(input_dev); |
| 454 | kfree(keycodes); | ||
| 455 | kfree(keypad); | 453 | kfree(keypad); |
| 456 | return err; | 454 | return err; |
| 457 | } | 455 | } |
| @@ -479,7 +477,6 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev) | |||
| 479 | 477 | ||
| 480 | input_unregister_device(keypad->input_dev); | 478 | input_unregister_device(keypad->input_dev); |
| 481 | platform_set_drvdata(pdev, NULL); | 479 | platform_set_drvdata(pdev, NULL); |
| 482 | kfree(keypad->keycodes); | ||
| 483 | kfree(keypad); | 480 | kfree(keypad); |
| 484 | 481 | ||
| 485 | return 0; | 482 | return 0; |
