2023-07-14 08:17:08

by 李扬韬

[permalink] [raw]
Subject: [PATCH 2/8] Input: amikbd - convert to use devm_* api

Use devm_* api to simplify code, this makes it unnecessary to explicitly
release resources.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/input/keyboard/amikbd.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index a20a4e186639..4cbac79f5a4b 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -193,10 +193,11 @@ static irqreturn_t amikbd_interrupt(int irq, void *data)

static int __init amikbd_probe(struct platform_device *pdev)
{
+ struct device *device = &pdev->dev;
struct input_dev *dev;
int i, err;

- dev = input_allocate_device();
+ dev = devm_input_allocate_device(device);
if (!dev) {
dev_err(&pdev->dev, "Not enough memory for input device\n");
return -ENOMEM;
@@ -218,35 +219,21 @@ static int __init amikbd_probe(struct platform_device *pdev)
amikbd_init_console_keymaps();

ciaa.cra &= ~0x41; /* serial data in, turn off TA */
- err = request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
- dev);
+ err = devm_request_irq(device, IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
+ dev);
if (err)
- goto fail2;
+ return err;

err = input_register_device(dev);
if (err)
- goto fail3;
+ return err;

platform_set_drvdata(pdev, dev);

return 0;
-
- fail3: free_irq(IRQ_AMIGA_CIAA_SP, dev);
- fail2: input_free_device(dev);
- return err;
-}
-
-static int __exit amikbd_remove(struct platform_device *pdev)
-{
- struct input_dev *dev = platform_get_drvdata(pdev);
-
- free_irq(IRQ_AMIGA_CIAA_SP, dev);
- input_unregister_device(dev);
- return 0;
}

static struct platform_driver amikbd_driver = {
- .remove = __exit_p(amikbd_remove),
.driver = {
.name = "amiga-keyboard",
},
--
2.39.0



2023-07-24 05:39:48

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 2/8] Input: amikbd - convert to use devm_* api

On Fri, Jul 14, 2023 at 04:06:05PM +0800, Yangtao Li wrote:
> Use devm_* api to simplify code, this makes it unnecessary to explicitly
> release resources.

Applied with minor changes, thank you.

--
Dmitry