Commit 9e085dd0 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: sgi_btns - switch to using managed resources

Switching to devm API allows to clean up error handling paths and drop
the remove() method.

Link: https://lore.kernel.org/r/20191017204217.106453-14-dmitry.torokhov@gmail.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 5d96738d
...@@ -45,7 +45,6 @@ static const unsigned short sgi_map[] = { ...@@ -45,7 +45,6 @@ static const unsigned short sgi_map[] = {
}; };
struct buttons_dev { struct buttons_dev {
struct input_polled_dev *poll_dev;
unsigned short keymap[ARRAY_SIZE(sgi_map)]; unsigned short keymap[ARRAY_SIZE(sgi_map)];
int count[ARRAY_SIZE(sgi_map)]; int count[ARRAY_SIZE(sgi_map)];
}; };
...@@ -84,12 +83,13 @@ static int sgi_buttons_probe(struct platform_device *pdev) ...@@ -84,12 +83,13 @@ static int sgi_buttons_probe(struct platform_device *pdev)
struct input_dev *input; struct input_dev *input;
int error, i; int error, i;
bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL); bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL);
poll_dev = input_allocate_polled_device(); if (!bdev)
if (!bdev || !poll_dev) { return -ENOMEM;
error = -ENOMEM;
goto err_free_mem; poll_dev = devm_input_allocate_polled_device(&pdev->dev);
} if (!poll_dev)
return -ENOMEM;
memcpy(bdev->keymap, sgi_map, sizeof(bdev->keymap)); memcpy(bdev->keymap, sgi_map, sizeof(bdev->keymap));
...@@ -101,7 +101,6 @@ static int sgi_buttons_probe(struct platform_device *pdev) ...@@ -101,7 +101,6 @@ static int sgi_buttons_probe(struct platform_device *pdev)
input->name = "SGI buttons"; input->name = "SGI buttons";
input->phys = "sgi/input0"; input->phys = "sgi/input0";
input->id.bustype = BUS_HOST; input->id.bustype = BUS_HOST;
input->dev.parent = &pdev->dev;
input->keycode = bdev->keymap; input->keycode = bdev->keymap;
input->keycodemax = ARRAY_SIZE(bdev->keymap); input->keycodemax = ARRAY_SIZE(bdev->keymap);
...@@ -113,35 +112,15 @@ static int sgi_buttons_probe(struct platform_device *pdev) ...@@ -113,35 +112,15 @@ static int sgi_buttons_probe(struct platform_device *pdev)
__set_bit(bdev->keymap[i], input->keybit); __set_bit(bdev->keymap[i], input->keybit);
__clear_bit(KEY_RESERVED, input->keybit); __clear_bit(KEY_RESERVED, input->keybit);
bdev->poll_dev = poll_dev;
platform_set_drvdata(pdev, bdev);
error = input_register_polled_device(poll_dev); error = input_register_polled_device(poll_dev);
if (error) if (error)
goto err_free_mem; return error;
return 0;
err_free_mem:
input_free_polled_device(poll_dev);
kfree(bdev);
return error;
}
static int sgi_buttons_remove(struct platform_device *pdev)
{
struct buttons_dev *bdev = platform_get_drvdata(pdev);
input_unregister_polled_device(bdev->poll_dev);
input_free_polled_device(bdev->poll_dev);
kfree(bdev);
return 0; return 0;
} }
static struct platform_driver sgi_buttons_driver = { static struct platform_driver sgi_buttons_driver = {
.probe = sgi_buttons_probe, .probe = sgi_buttons_probe,
.remove = sgi_buttons_remove,
.driver = { .driver = {
.name = "sgibtns", .name = "sgibtns",
}, },
......
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