Input: cobalt_btns - convert to use managed resources
This simplifies error handling and allows to remove cobalt_buttons_remove() method. Link: https://lore.kernel.org/r/20191017204217.106453-12-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
Родитель
4a767ec368
Коммит
4d69ca90de
|
@ -5,6 +5,7 @@
|
|||
* Copyright (C) 2007-2008 Yoichi Yuasa <yuasa@linux-mips.org>
|
||||
*/
|
||||
#include <linux/input-polldev.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
@ -26,7 +27,6 @@ static const unsigned short cobalt_map[] = {
|
|||
};
|
||||
|
||||
struct buttons_dev {
|
||||
struct input_polled_dev *poll_dev;
|
||||
unsigned short keymap[ARRAY_SIZE(cobalt_map)];
|
||||
int count[ARRAY_SIZE(cobalt_map)];
|
||||
void __iomem *reg;
|
||||
|
@ -67,15 +67,24 @@ static int cobalt_buttons_probe(struct platform_device *pdev)
|
|||
struct resource *res;
|
||||
int error, i;
|
||||
|
||||
bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL);
|
||||
poll_dev = input_allocate_polled_device();
|
||||
if (!bdev || !poll_dev) {
|
||||
error = -ENOMEM;
|
||||
goto err_free_mem;
|
||||
}
|
||||
bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL);
|
||||
if (!bdev)
|
||||
return -ENOMEM;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
if (!res)
|
||||
return -EBUSY;
|
||||
|
||||
bdev->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
|
||||
if (!bdev->reg)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(bdev->keymap, cobalt_map, sizeof(bdev->keymap));
|
||||
|
||||
poll_dev = devm_input_allocate_polled_device(&pdev->dev);
|
||||
if (!poll_dev)
|
||||
return -ENOMEM;
|
||||
|
||||
poll_dev->private = bdev;
|
||||
poll_dev->poll = handle_buttons;
|
||||
poll_dev->poll_interval = BUTTONS_POLL_INTERVAL;
|
||||
|
@ -84,7 +93,6 @@ static int cobalt_buttons_probe(struct platform_device *pdev)
|
|||
input->name = "Cobalt buttons";
|
||||
input->phys = "cobalt/input0";
|
||||
input->id.bustype = BUS_HOST;
|
||||
input->dev.parent = &pdev->dev;
|
||||
|
||||
input->keycode = bdev->keymap;
|
||||
input->keycodemax = ARRAY_SIZE(bdev->keymap);
|
||||
|
@ -96,39 +104,9 @@ static int cobalt_buttons_probe(struct platform_device *pdev)
|
|||
__set_bit(bdev->keymap[i], input->keybit);
|
||||
__clear_bit(KEY_RESERVED, input->keybit);
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
if (!res) {
|
||||
error = -EBUSY;
|
||||
goto err_free_mem;
|
||||
}
|
||||
|
||||
bdev->poll_dev = poll_dev;
|
||||
bdev->reg = ioremap(res->start, resource_size(res));
|
||||
dev_set_drvdata(&pdev->dev, bdev);
|
||||
|
||||
error = input_register_polled_device(poll_dev);
|
||||
if (error)
|
||||
goto err_iounmap;
|
||||
|
||||
return 0;
|
||||
|
||||
err_iounmap:
|
||||
iounmap(bdev->reg);
|
||||
err_free_mem:
|
||||
input_free_polled_device(poll_dev);
|
||||
kfree(bdev);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int cobalt_buttons_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct buttons_dev *bdev = dev_get_drvdata(dev);
|
||||
|
||||
input_unregister_polled_device(bdev->poll_dev);
|
||||
input_free_polled_device(bdev->poll_dev);
|
||||
iounmap(bdev->reg);
|
||||
kfree(bdev);
|
||||
return error;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -141,7 +119,6 @@ MODULE_ALIAS("platform:Cobalt buttons");
|
|||
|
||||
static struct platform_driver cobalt_buttons_driver = {
|
||||
.probe = cobalt_buttons_probe,
|
||||
.remove = cobalt_buttons_remove,
|
||||
.driver = {
|
||||
.name = "Cobalt buttons",
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче