diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2017-03-08 09:36:23 -0800 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2017-03-09 10:06:19 -0800 |
commit | 52e4f1d601daaee0bad6b22765befc21b180d701 (patch) | |
tree | 93f0701cd11f6e7892841cad59f02deeb5632e89 /drivers/input/misc | |
parent | fc2a6e5048c6812253590b8ae26eed3236b25eac (diff) | |
download | lwn-52e4f1d601daaee0bad6b22765befc21b180d701.tar.gz lwn-52e4f1d601daaee0bad6b22765befc21b180d701.zip |
Input: dm355evm_keys - switch to using managed resources
Using devm_* APIs simpifies error handling and device teardown.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/misc')
-rw-r--r-- | drivers/input/misc/dm355evm_keys.c | 76 |
1 files changed, 26 insertions, 50 deletions
diff --git a/drivers/input/misc/dm355evm_keys.c b/drivers/input/misc/dm355evm_keys.c index 5db493dfe509..bab256ef32b9 100644 --- a/drivers/input/misc/dm355evm_keys.c +++ b/drivers/input/misc/dm355evm_keys.c @@ -32,7 +32,6 @@ struct dm355evm_keys { struct input_dev *input; struct device *dev; - int irq; }; /* These initial keycodes can be remapped */ @@ -176,71 +175,49 @@ static int dm355evm_keys_probe(struct platform_device *pdev) { struct dm355evm_keys *keys; struct input_dev *input; - int status; + int irq; + int error; - /* allocate instance struct and input dev */ - keys = kzalloc(sizeof *keys, GFP_KERNEL); - input = input_allocate_device(); - if (!keys || !input) { - status = -ENOMEM; - goto fail1; - } + keys = devm_kzalloc(&pdev->dev, sizeof (*keys), GFP_KERNEL); + if (!keys) + return -ENOMEM; + + input = devm_input_allocate_device(&pdev->dev); + if (!input) + return -ENOMEM; keys->dev = &pdev->dev; keys->input = input; - /* set up "threaded IRQ handler" */ - status = platform_get_irq(pdev, 0); - if (status < 0) - goto fail1; - keys->irq = status; - input->name = "DM355 EVM Controls"; input->phys = "dm355evm/input0"; - input->dev.parent = &pdev->dev; input->id.bustype = BUS_I2C; input->id.product = 0x0355; input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV); - status = sparse_keymap_setup(input, dm355evm_keys, NULL); - if (status) - goto fail1; + error = sparse_keymap_setup(input, dm355evm_keys, NULL); + if (error) + return error; /* REVISIT: flush the event queue? */ - status = request_threaded_irq(keys->irq, NULL, dm355evm_keys_irq, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - dev_name(&pdev->dev), keys); - if (status < 0) - goto fail1; - - /* register */ - status = input_register_device(input); - if (status < 0) - goto fail2; - - platform_set_drvdata(pdev, keys); - - return 0; - -fail2: - free_irq(keys->irq, keys); -fail1: - input_free_device(input); - kfree(keys); - dev_err(&pdev->dev, "can't register, err %d\n", status); - - return status; -} + /* set up "threaded IRQ handler" */ + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; -static int dm355evm_keys_remove(struct platform_device *pdev) -{ - struct dm355evm_keys *keys = platform_get_drvdata(pdev); + error = devm_request_threaded_irq(&pdev->dev, irq, + NULL, dm355evm_keys_irq, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + dev_name(&pdev->dev), keys); + if (error) + return error; - free_irq(keys->irq, keys); - input_unregister_device(keys->input); - kfree(keys); + /* register */ + error = input_register_device(input); + if (error) + return error; return 0; } @@ -256,7 +233,6 @@ static int dm355evm_keys_remove(struct platform_device *pdev) */ static struct platform_driver dm355evm_keys_driver = { .probe = dm355evm_keys_probe, - .remove = dm355evm_keys_remove, .driver = { .name = "dm355evm_keys", }, |