Commit 40a6bb10 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: matrix-keymap - switch to using __free() cleanup facility

Use __free(kfree) cleanup facility in matrix_keypad_parse_keymap() to
automatically free temporarily allocated memory.
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/ZspoEPdTcH-hpciy@google.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 739b847d
...@@ -73,10 +73,9 @@ static int matrix_keypad_parse_keymap(const char *propname, ...@@ -73,10 +73,9 @@ static int matrix_keypad_parse_keymap(const char *propname,
struct device *dev = input_dev->dev.parent; struct device *dev = input_dev->dev.parent;
unsigned int row_shift = get_count_order(cols); unsigned int row_shift = get_count_order(cols);
unsigned int max_keys = rows << row_shift; unsigned int max_keys = rows << row_shift;
u32 *keys;
int i; int i;
int size; int size;
int retval; int error;
if (!propname) if (!propname)
propname = "linux,keymap"; propname = "linux,keymap";
...@@ -94,30 +93,24 @@ static int matrix_keypad_parse_keymap(const char *propname, ...@@ -94,30 +93,24 @@ static int matrix_keypad_parse_keymap(const char *propname,
return -EINVAL; return -EINVAL;
} }
keys = kmalloc_array(size, sizeof(u32), GFP_KERNEL); u32 *keys __free(kfree) = kmalloc_array(size, sizeof(*keys), GFP_KERNEL);
if (!keys) if (!keys)
return -ENOMEM; return -ENOMEM;
retval = device_property_read_u32_array(dev, propname, keys, size); error = device_property_read_u32_array(dev, propname, keys, size);
if (retval) { if (error) {
dev_err(dev, "failed to read %s property: %d\n", dev_err(dev, "failed to read %s property: %d\n",
propname, retval); propname, error);
goto out; return error;
} }
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
if (!matrix_keypad_map_key(input_dev, rows, cols, if (!matrix_keypad_map_key(input_dev, rows, cols,
row_shift, keys[i])) { row_shift, keys[i]))
retval = -EINVAL; return -EINVAL;
goto out;
}
} }
retval = 0; return 0;
out:
kfree(keys);
return retval;
} }
/** /**
......
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