Input: max8925_onkey - switch to using managed resources
Let's switch the driver to use managed resources, this will simplify error handling and driver unbinding logic. Signed-off-by: Himangi Saraogi <himangi774@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
5ac66de574
commit
04115e410c
|
@ -26,6 +26,7 @@
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
#include <linux/mfd/max8925.h>
|
#include <linux/mfd/max8925.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
#include <linux/device.h>
|
||||||
|
|
||||||
#define SW_INPUT (1 << 7) /* 0/1 -- up/down */
|
#define SW_INPUT (1 << 7) /* 0/1 -- up/down */
|
||||||
#define HARDRESET_EN (1 << 7)
|
#define HARDRESET_EN (1 << 7)
|
||||||
|
@ -81,12 +82,14 @@ static int max8925_onkey_probe(struct platform_device *pdev)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
info = kzalloc(sizeof(struct max8925_onkey_info), GFP_KERNEL);
|
info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_onkey_info),
|
||||||
input = input_allocate_device();
|
GFP_KERNEL);
|
||||||
if (!info || !input) {
|
if (!info)
|
||||||
error = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_free_mem;
|
|
||||||
}
|
input = devm_input_allocate_device(&pdev->dev);
|
||||||
|
if (!input)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
info->idev = input;
|
info->idev = input;
|
||||||
info->i2c = chip->i2c;
|
info->i2c = chip->i2c;
|
||||||
|
@ -100,54 +103,33 @@ static int max8925_onkey_probe(struct platform_device *pdev)
|
||||||
input->dev.parent = &pdev->dev;
|
input->dev.parent = &pdev->dev;
|
||||||
input_set_capability(input, EV_KEY, KEY_POWER);
|
input_set_capability(input, EV_KEY, KEY_POWER);
|
||||||
|
|
||||||
error = request_threaded_irq(irq[0], NULL, max8925_onkey_handler,
|
error = devm_request_threaded_irq(&pdev->dev, irq[0], NULL,
|
||||||
IRQF_ONESHOT, "onkey-down", info);
|
max8925_onkey_handler, IRQF_ONESHOT,
|
||||||
|
"onkey-down", info);
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
|
dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
|
||||||
irq[0], error);
|
irq[0], error);
|
||||||
goto err_free_mem;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = request_threaded_irq(irq[1], NULL, max8925_onkey_handler,
|
error = devm_request_threaded_irq(&pdev->dev, irq[1], NULL,
|
||||||
IRQF_ONESHOT, "onkey-up", info);
|
max8925_onkey_handler, IRQF_ONESHOT,
|
||||||
|
"onkey-up", info);
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
|
dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
|
||||||
irq[1], error);
|
irq[1], error);
|
||||||
goto err_free_irq0;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = input_register_device(info->idev);
|
error = input_register_device(info->idev);
|
||||||
if (error) {
|
if (error) {
|
||||||
dev_err(chip->dev, "Can't register input device: %d\n", error);
|
dev_err(chip->dev, "Can't register input device: %d\n", error);
|
||||||
goto err_free_irq1;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, info);
|
platform_set_drvdata(pdev, info);
|
||||||
device_init_wakeup(&pdev->dev, 1);
|
device_init_wakeup(&pdev->dev, 1);
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err_free_irq1:
|
|
||||||
free_irq(irq[1], info);
|
|
||||||
err_free_irq0:
|
|
||||||
free_irq(irq[0], info);
|
|
||||||
err_free_mem:
|
|
||||||
input_free_device(input);
|
|
||||||
kfree(info);
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int max8925_onkey_remove(struct platform_device *pdev)
|
|
||||||
{
|
|
||||||
struct max8925_onkey_info *info = platform_get_drvdata(pdev);
|
|
||||||
struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
|
|
||||||
|
|
||||||
free_irq(info->irq[0] + chip->irq_base, info);
|
|
||||||
free_irq(info->irq[1] + chip->irq_base, info);
|
|
||||||
input_unregister_device(info->idev);
|
|
||||||
kfree(info);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +172,6 @@ static struct platform_driver max8925_onkey_driver = {
|
||||||
.pm = &max8925_onkey_pm_ops,
|
.pm = &max8925_onkey_pm_ops,
|
||||||
},
|
},
|
||||||
.probe = max8925_onkey_probe,
|
.probe = max8925_onkey_probe,
|
||||||
.remove = max8925_onkey_remove,
|
|
||||||
};
|
};
|
||||||
module_platform_driver(max8925_onkey_driver);
|
module_platform_driver(max8925_onkey_driver);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue