Commit 52e4f1d6 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: dm355evm_keys - switch to using managed resources

Using devm_* APIs simpifies error handling and device teardown.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent fc2a6e50
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
struct dm355evm_keys { struct dm355evm_keys {
struct input_dev *input; struct input_dev *input;
struct device *dev; struct device *dev;
int irq;
}; };
/* These initial keycodes can be remapped */ /* These initial keycodes can be remapped */
...@@ -176,71 +175,49 @@ static int dm355evm_keys_probe(struct platform_device *pdev) ...@@ -176,71 +175,49 @@ static int dm355evm_keys_probe(struct platform_device *pdev)
{ {
struct dm355evm_keys *keys; struct dm355evm_keys *keys;
struct input_dev *input; struct input_dev *input;
int status; int irq;
int error;
/* allocate instance struct and input dev */ keys = devm_kzalloc(&pdev->dev, sizeof (*keys), GFP_KERNEL);
keys = kzalloc(sizeof *keys, GFP_KERNEL); if (!keys)
input = input_allocate_device(); return -ENOMEM;
if (!keys || !input) {
status = -ENOMEM; input = devm_input_allocate_device(&pdev->dev);
goto fail1; if (!input)
} return -ENOMEM;
keys->dev = &pdev->dev; keys->dev = &pdev->dev;
keys->input = input; 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->name = "DM355 EVM Controls";
input->phys = "dm355evm/input0"; input->phys = "dm355evm/input0";
input->dev.parent = &pdev->dev;
input->id.bustype = BUS_I2C; input->id.bustype = BUS_I2C;
input->id.product = 0x0355; input->id.product = 0x0355;
input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV); input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV);
status = sparse_keymap_setup(input, dm355evm_keys, NULL); error = sparse_keymap_setup(input, dm355evm_keys, NULL);
if (status) if (error)
goto fail1; return error;
/* REVISIT: flush the event queue? */ /* REVISIT: flush the event queue? */
status = request_threaded_irq(keys->irq, NULL, dm355evm_keys_irq, /* 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, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
dev_name(&pdev->dev), keys); dev_name(&pdev->dev), keys);
if (status < 0) if (error)
goto fail1; return error;
/* register */ /* register */
status = input_register_device(input); error = input_register_device(input);
if (status < 0) if (error)
goto fail2; return error;
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);
return 0; return 0;
} }
...@@ -256,7 +233,6 @@ static int dm355evm_keys_remove(struct platform_device *pdev) ...@@ -256,7 +233,6 @@ static int dm355evm_keys_remove(struct platform_device *pdev)
*/ */
static struct platform_driver dm355evm_keys_driver = { static struct platform_driver dm355evm_keys_driver = {
.probe = dm355evm_keys_probe, .probe = dm355evm_keys_probe,
.remove = dm355evm_keys_remove,
.driver = { .driver = {
.name = "dm355evm_keys", .name = "dm355evm_keys",
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment