diff options
Diffstat (limited to 'drivers/input/matrix-keymap.c')
-rw-r--r-- | drivers/input/matrix-keymap.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/drivers/input/matrix-keymap.c b/drivers/input/matrix-keymap.c index d88d9be1d1b7..3ae496ea5fe6 100644 --- a/drivers/input/matrix-keymap.c +++ b/drivers/input/matrix-keymap.c | |||
@@ -18,6 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
21 | #include <linux/gfp.h> | ||
21 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
22 | #include <linux/types.h> | 23 | #include <linux/types.h> |
23 | #include <linux/input.h> | 24 | #include <linux/input.h> |
@@ -123,6 +124,11 @@ static int matrix_keypad_parse_of_keymap(const char *propname, | |||
123 | * it will attempt load the keymap from property specified by @keymap_name | 124 | * it will attempt load the keymap from property specified by @keymap_name |
124 | * argument (or "linux,keymap" if @keymap_name is %NULL). | 125 | * argument (or "linux,keymap" if @keymap_name is %NULL). |
125 | * | 126 | * |
127 | * If @keymap is %NULL the function will automatically allocate managed | ||
128 | * block of memory to store the keymap. This memory will be associated with | ||
129 | * the parent device and automatically freed when device unbinds from the | ||
130 | * driver. | ||
131 | * | ||
126 | * Callers are expected to set up input_dev->dev.parent before calling this | 132 | * Callers are expected to set up input_dev->dev.parent before calling this |
127 | * function. | 133 | * function. |
128 | */ | 134 | */ |
@@ -133,12 +139,27 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, | |||
133 | struct input_dev *input_dev) | 139 | struct input_dev *input_dev) |
134 | { | 140 | { |
135 | unsigned int row_shift = get_count_order(cols); | 141 | unsigned int row_shift = get_count_order(cols); |
142 | size_t max_keys = rows << row_shift; | ||
136 | int i; | 143 | int i; |
137 | int error; | 144 | int error; |
138 | 145 | ||
146 | if (WARN_ON(!input_dev->dev.parent)) | ||
147 | return -EINVAL; | ||
148 | |||
149 | if (!keymap) { | ||
150 | keymap = devm_kzalloc(input_dev->dev.parent, | ||
151 | max_keys * sizeof(*keymap), | ||
152 | GFP_KERNEL); | ||
153 | if (!keymap) { | ||
154 | dev_err(input_dev->dev.parent, | ||
155 | "Unable to allocate memory for keymap"); | ||
156 | return -ENOMEM; | ||
157 | } | ||
158 | } | ||
159 | |||
139 | input_dev->keycode = keymap; | 160 | input_dev->keycode = keymap; |
140 | input_dev->keycodesize = sizeof(*keymap); | 161 | input_dev->keycodesize = sizeof(*keymap); |
141 | input_dev->keycodemax = rows << row_shift; | 162 | input_dev->keycodemax = max_keys; |
142 | 163 | ||
143 | __set_bit(EV_KEY, input_dev->evbit); | 164 | __set_bit(EV_KEY, input_dev->evbit); |
144 | 165 | ||