Commit 01111fcd authored by Dmitry Torokhov's avatar Dmitry Torokhov

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: default avatarDmitry Torokhov <dtor@mail.ru>
parent 0508c19a
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
struct matrix_keypad { struct matrix_keypad {
const struct matrix_keypad_platform_data *pdata; const struct matrix_keypad_platform_data *pdata;
struct input_dev *input_dev; struct input_dev *input_dev;
unsigned short *keycodes;
unsigned int row_shift; unsigned int row_shift;
DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS); DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS);
...@@ -38,6 +37,8 @@ struct matrix_keypad { ...@@ -38,6 +37,8 @@ struct matrix_keypad {
bool scan_pending; bool scan_pending;
bool stopped; bool stopped;
bool gpio_all_disabled; bool gpio_all_disabled;
unsigned short keycodes[];
}; };
/* /*
...@@ -381,8 +382,8 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) ...@@ -381,8 +382,8 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
const struct matrix_keymap_data *keymap_data; const struct matrix_keymap_data *keymap_data;
struct matrix_keypad *keypad; struct matrix_keypad *keypad;
struct input_dev *input_dev; struct input_dev *input_dev;
unsigned short *keycodes;
unsigned int row_shift; unsigned int row_shift;
size_t keymap_size;
int err; int err;
pdata = pdev->dev.platform_data; pdata = pdev->dev.platform_data;
...@@ -398,20 +399,18 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) ...@@ -398,20 +399,18 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
} }
row_shift = get_count_order(pdata->num_col_gpios); row_shift = get_count_order(pdata->num_col_gpios);
keymap_size = (pdata->num_row_gpios << row_shift) *
keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL); sizeof(keypad->keycodes[0]);
keycodes = kzalloc((pdata->num_row_gpios << row_shift) * keypad = kzalloc(sizeof(struct matrix_keypad) + keymap_size,
sizeof(*keycodes),
GFP_KERNEL); GFP_KERNEL);
input_dev = input_allocate_device(); input_dev = input_allocate_device();
if (!keypad || !keycodes || !input_dev) { if (!keypad || !input_dev) {
err = -ENOMEM; err = -ENOMEM;
goto err_free_mem; goto err_free_mem;
} }
keypad->input_dev = input_dev; keypad->input_dev = input_dev;
keypad->pdata = pdata; keypad->pdata = pdata;
keypad->keycodes = keycodes;
keypad->row_shift = row_shift; keypad->row_shift = row_shift;
keypad->stopped = true; keypad->stopped = true;
INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan);
...@@ -426,8 +425,8 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) ...@@ -426,8 +425,8 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
input_dev->open = matrix_keypad_start; input_dev->open = matrix_keypad_start;
input_dev->close = matrix_keypad_stop; input_dev->close = matrix_keypad_stop;
input_dev->keycode = keycodes; input_dev->keycode = keypad->keycodes;
input_dev->keycodesize = sizeof(*keycodes); input_dev->keycodesize = sizeof(keypad->keycodes[0]);
input_dev->keycodemax = pdata->num_row_gpios << row_shift; input_dev->keycodemax = pdata->num_row_gpios << row_shift;
matrix_keypad_build_keymap(keymap_data, row_shift, matrix_keypad_build_keymap(keymap_data, row_shift,
...@@ -451,7 +450,6 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev) ...@@ -451,7 +450,6 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
err_free_mem: err_free_mem:
input_free_device(input_dev); input_free_device(input_dev);
kfree(keycodes);
kfree(keypad); kfree(keypad);
return err; return err;
} }
...@@ -479,7 +477,6 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev) ...@@ -479,7 +477,6 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev)
input_unregister_device(keypad->input_dev); input_unregister_device(keypad->input_dev);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
kfree(keypad->keycodes);
kfree(keypad); kfree(keypad);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment