Skip to content

Commit 4d69ca9

Browse files
committed
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/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 4a767ec commit 4d69ca9

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

drivers/input/misc/cobalt_btns.c

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright (C) 2007-2008 Yoichi Yuasa <[email protected]>
66
*/
77
#include <linux/input-polldev.h>
8+
#include <linux/io.h>
89
#include <linux/ioport.h>
910
#include <linux/module.h>
1011
#include <linux/platform_device.h>
@@ -26,7 +27,6 @@ static const unsigned short cobalt_map[] = {
2627
};
2728

2829
struct buttons_dev {
29-
struct input_polled_dev *poll_dev;
3030
unsigned short keymap[ARRAY_SIZE(cobalt_map)];
3131
int count[ARRAY_SIZE(cobalt_map)];
3232
void __iomem *reg;
@@ -67,15 +67,24 @@ static int cobalt_buttons_probe(struct platform_device *pdev)
6767
struct resource *res;
6868
int error, i;
6969

70-
bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL);
71-
poll_dev = input_allocate_polled_device();
72-
if (!bdev || !poll_dev) {
73-
error = -ENOMEM;
74-
goto err_free_mem;
75-
}
70+
bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL);
71+
if (!bdev)
72+
return -ENOMEM;
73+
74+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
75+
if (!res)
76+
return -EBUSY;
77+
78+
bdev->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
79+
if (!bdev->reg)
80+
return -ENOMEM;
7681

7782
memcpy(bdev->keymap, cobalt_map, sizeof(bdev->keymap));
7883

84+
poll_dev = devm_input_allocate_polled_device(&pdev->dev);
85+
if (!poll_dev)
86+
return -ENOMEM;
87+
7988
poll_dev->private = bdev;
8089
poll_dev->poll = handle_buttons;
8190
poll_dev->poll_interval = BUTTONS_POLL_INTERVAL;
@@ -84,7 +93,6 @@ static int cobalt_buttons_probe(struct platform_device *pdev)
8493
input->name = "Cobalt buttons";
8594
input->phys = "cobalt/input0";
8695
input->id.bustype = BUS_HOST;
87-
input->dev.parent = &pdev->dev;
8896

8997
input->keycode = bdev->keymap;
9098
input->keycodemax = ARRAY_SIZE(bdev->keymap);
@@ -96,39 +104,9 @@ static int cobalt_buttons_probe(struct platform_device *pdev)
96104
__set_bit(bdev->keymap[i], input->keybit);
97105
__clear_bit(KEY_RESERVED, input->keybit);
98106

99-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
100-
if (!res) {
101-
error = -EBUSY;
102-
goto err_free_mem;
103-
}
104-
105-
bdev->poll_dev = poll_dev;
106-
bdev->reg = ioremap(res->start, resource_size(res));
107-
dev_set_drvdata(&pdev->dev, bdev);
108-
109107
error = input_register_polled_device(poll_dev);
110108
if (error)
111-
goto err_iounmap;
112-
113-
return 0;
114-
115-
err_iounmap:
116-
iounmap(bdev->reg);
117-
err_free_mem:
118-
input_free_polled_device(poll_dev);
119-
kfree(bdev);
120-
return error;
121-
}
122-
123-
static int cobalt_buttons_remove(struct platform_device *pdev)
124-
{
125-
struct device *dev = &pdev->dev;
126-
struct buttons_dev *bdev = dev_get_drvdata(dev);
127-
128-
input_unregister_polled_device(bdev->poll_dev);
129-
input_free_polled_device(bdev->poll_dev);
130-
iounmap(bdev->reg);
131-
kfree(bdev);
109+
return error;
132110

133111
return 0;
134112
}
@@ -141,7 +119,6 @@ MODULE_ALIAS("platform:Cobalt buttons");
141119

142120
static struct platform_driver cobalt_buttons_driver = {
143121
.probe = cobalt_buttons_probe,
144-
.remove = cobalt_buttons_remove,
145122
.driver = {
146123
.name = "Cobalt buttons",
147124
},

0 commit comments

Comments
 (0)