From a64cb9bf0eb1bcdfac19eb8ef8b056e8e89c1ef4 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 5 Nov 2012 10:32:55 -0800 Subject: [PATCH] --- yaml --- r: 346943 b: refs/heads/master c: 5383116b86d8e877684770d05acd1dda62be102d h: refs/heads/master i: 346941: 0301f2de6ac64c1ce0eb5852509f9a36657752d4 346939: 03d189c64c10b390935d3a0d60b54c76288f7084 346935: f9d0331d31fd09fb0cbf11829b4c1b210b5bf9f5 346927: 687b20ef402299c769574bedd89f9c96e15c7c2b 346911: 830aa00cf836db334ca2db22e5f6694426dc2b85 346879: ecedc3942fbe01d459dae66aa7ea1a03021ea154 v: v3 --- [refs] | 2 +- trunk/drivers/input/matrix-keymap.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index a01d0506b80d..7da77284e446 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 544a46c917fcf0a439cc0c428d76ba731a380cae +refs/heads/master: 5383116b86d8e877684770d05acd1dda62be102d diff --git a/trunk/drivers/input/matrix-keymap.c b/trunk/drivers/input/matrix-keymap.c index 443ad64b7f2a..419cb6b88e2a 100644 --- a/trunk/drivers/input/matrix-keymap.c +++ b/trunk/drivers/input/matrix-keymap.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -122,6 +123,11 @@ static int matrix_keypad_parse_of_keymap(const char *propname, * it will attempt load the keymap from property specified by @keymap_name * argument (or "linux,keymap" if @keymap_name is %NULL). * + * If @keymap is %NULL the function will automatically allocate managed + * block of memory to store the keymap. This memory will be associated with + * the parent device and automatically freed when device unbinds from the + * driver. + * * Callers are expected to set up input_dev->dev.parent before calling this * function. */ @@ -132,12 +138,27 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, struct input_dev *input_dev) { unsigned int row_shift = get_count_order(cols); + size_t max_keys = rows << row_shift; int i; int error; + if (WARN_ON(!input_dev->dev.parent)) + return -EINVAL; + + if (!keymap) { + keymap = devm_kzalloc(input_dev->dev.parent, + max_keys * sizeof(*keymap), + GFP_KERNEL); + if (!keymap) { + dev_err(input_dev->dev.parent, + "Unable to allocate memory for keymap"); + return -ENOMEM; + } + } + input_dev->keycode = keymap; input_dev->keycodesize = sizeof(*keymap); - input_dev->keycodemax = rows << row_shift; + input_dev->keycodemax = max_keys; __set_bit(EV_KEY, input_dev->evbit);