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>
This commit is contained in:
parent
fc2a6e5048
commit
52e4f1d601
@ -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;
|
||||
/* set up "threaded IRQ handler" */
|
||||
irq = platform_get_irq(pdev, 0);
|
||||
if (irq < 0)
|
||||
return irq;
|
||||
|
||||
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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
static int dm355evm_keys_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct dm355evm_keys *keys = platform_get_drvdata(pdev);
|
||||
|
||||
free_irq(keys->irq, keys);
|
||||
input_unregister_device(keys->input);
|
||||
kfree(keys);
|
||||
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",
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user