Commit 94f31542 authored by Hans de Goede's avatar Hans de Goede

Merge tag 'devm-helpers-v5.14-1' into review-hans

Signed tag for the immutable devm-helpers branch for merging
into the extcon and pdx86 trees.
parents aa2ddd24 87ee8de2
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// Chanwoo Choi <cw00.choi@samsung.com> // Chanwoo Choi <cw00.choi@samsung.com>
// Krzysztof Kozlowski <krzk@kernel.org> // Krzysztof Kozlowski <krzk@kernel.org>
#include <linux/devm-helpers.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/i2c.h> #include <linux/i2c.h>
...@@ -673,7 +674,10 @@ static int max14577_muic_probe(struct platform_device *pdev) ...@@ -673,7 +674,10 @@ static int max14577_muic_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, info); platform_set_drvdata(pdev, info);
mutex_init(&info->mutex); mutex_init(&info->mutex);
INIT_WORK(&info->irq_work, max14577_muic_irq_work); ret = devm_work_autocancel(&pdev->dev, &info->irq_work,
max14577_muic_irq_work);
if (ret)
return ret;
switch (max14577->dev_type) { switch (max14577->dev_type) {
case MAXIM_DEVICE_TYPE_MAX77836: case MAXIM_DEVICE_TYPE_MAX77836:
...@@ -766,15 +770,6 @@ static int max14577_muic_probe(struct platform_device *pdev) ...@@ -766,15 +770,6 @@ static int max14577_muic_probe(struct platform_device *pdev)
return ret; return ret;
} }
static int max14577_muic_remove(struct platform_device *pdev)
{
struct max14577_muic_info *info = platform_get_drvdata(pdev);
cancel_work_sync(&info->irq_work);
return 0;
}
static const struct platform_device_id max14577_muic_id[] = { static const struct platform_device_id max14577_muic_id[] = {
{ "max14577-muic", MAXIM_DEVICE_TYPE_MAX14577, }, { "max14577-muic", MAXIM_DEVICE_TYPE_MAX14577, },
{ "max77836-muic", MAXIM_DEVICE_TYPE_MAX77836, }, { "max77836-muic", MAXIM_DEVICE_TYPE_MAX77836, },
...@@ -797,7 +792,6 @@ static struct platform_driver max14577_muic_driver = { ...@@ -797,7 +792,6 @@ static struct platform_driver max14577_muic_driver = {
.of_match_table = of_max14577_muic_dt_match, .of_match_table = of_max14577_muic_dt_match,
}, },
.probe = max14577_muic_probe, .probe = max14577_muic_probe,
.remove = max14577_muic_remove,
.id_table = max14577_muic_id, .id_table = max14577_muic_id,
}; };
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// Copyright (C) 2012 Samsung Electrnoics // Copyright (C) 2012 Samsung Electrnoics
// Chanwoo Choi <cw00.choi@samsung.com> // Chanwoo Choi <cw00.choi@samsung.com>
#include <linux/devm-helpers.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/i2c.h> #include <linux/i2c.h>
...@@ -1127,7 +1128,10 @@ static int max77693_muic_probe(struct platform_device *pdev) ...@@ -1127,7 +1128,10 @@ static int max77693_muic_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, info); platform_set_drvdata(pdev, info);
mutex_init(&info->mutex); mutex_init(&info->mutex);
INIT_WORK(&info->irq_work, max77693_muic_irq_work); ret = devm_work_autocancel(&pdev->dev, &info->irq_work,
max77693_muic_irq_work);
if (ret)
return ret;
/* Support irq domain for MAX77693 MUIC device */ /* Support irq domain for MAX77693 MUIC device */
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) { for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
...@@ -1254,22 +1258,11 @@ static int max77693_muic_probe(struct platform_device *pdev) ...@@ -1254,22 +1258,11 @@ static int max77693_muic_probe(struct platform_device *pdev)
return ret; return ret;
} }
static int max77693_muic_remove(struct platform_device *pdev)
{
struct max77693_muic_info *info = platform_get_drvdata(pdev);
cancel_work_sync(&info->irq_work);
input_unregister_device(info->dock);
return 0;
}
static struct platform_driver max77693_muic_driver = { static struct platform_driver max77693_muic_driver = {
.driver = { .driver = {
.name = DEV_NAME, .name = DEV_NAME,
}, },
.probe = max77693_muic_probe, .probe = max77693_muic_probe,
.remove = max77693_muic_remove,
}; };
module_platform_driver(max77693_muic_driver); module_platform_driver(max77693_muic_driver);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// Copyright (C) 2012 Samsung Electronics // Copyright (C) 2012 Samsung Electronics
// Donggeun Kim <dg77.kim@samsung.com> // Donggeun Kim <dg77.kim@samsung.com>
#include <linux/devm-helpers.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/i2c.h> #include <linux/i2c.h>
...@@ -650,27 +651,30 @@ static int max8997_muic_probe(struct platform_device *pdev) ...@@ -650,27 +651,30 @@ static int max8997_muic_probe(struct platform_device *pdev)
mutex_init(&info->mutex); mutex_init(&info->mutex);
INIT_WORK(&info->irq_work, max8997_muic_irq_work); INIT_WORK(&info->irq_work, max8997_muic_irq_work);
ret = devm_work_autocancel(&pdev->dev, &info->irq_work,
max8997_muic_irq_work);
if (ret)
return ret;
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) { for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
struct max8997_muic_irq *muic_irq = &muic_irqs[i]; struct max8997_muic_irq *muic_irq = &muic_irqs[i];
unsigned int virq = 0; unsigned int virq = 0;
virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq); virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq);
if (!virq) { if (!virq)
ret = -EINVAL; return -EINVAL;
goto err_irq;
}
muic_irq->virq = virq; muic_irq->virq = virq;
ret = request_threaded_irq(virq, NULL, ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
max8997_muic_irq_handler, max8997_muic_irq_handler,
IRQF_NO_SUSPEND, IRQF_NO_SUSPEND,
muic_irq->name, info); muic_irq->name, info);
if (ret) { if (ret) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"failed: irq request (IRQ: %d, error :%d)\n", "failed: irq request (IRQ: %d, error :%d)\n",
muic_irq->irq, ret); muic_irq->irq, ret);
goto err_irq; return ret;
} }
} }
...@@ -678,14 +682,13 @@ static int max8997_muic_probe(struct platform_device *pdev) ...@@ -678,14 +682,13 @@ static int max8997_muic_probe(struct platform_device *pdev)
info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable); info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable);
if (IS_ERR(info->edev)) { if (IS_ERR(info->edev)) {
dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
ret = PTR_ERR(info->edev); return PTR_ERR(info->edev);
goto err_irq;
} }
ret = devm_extcon_dev_register(&pdev->dev, info->edev); ret = devm_extcon_dev_register(&pdev->dev, info->edev);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to register extcon device\n"); dev_err(&pdev->dev, "failed to register extcon device\n");
goto err_irq; return ret;
} }
if (pdata && pdata->muic_pdata) { if (pdata && pdata->muic_pdata) {
...@@ -756,23 +759,6 @@ static int max8997_muic_probe(struct platform_device *pdev) ...@@ -756,23 +759,6 @@ static int max8997_muic_probe(struct platform_device *pdev)
delay_jiffies); delay_jiffies);
return 0; return 0;
err_irq:
while (--i >= 0)
free_irq(muic_irqs[i].virq, info);
return ret;
}
static int max8997_muic_remove(struct platform_device *pdev)
{
struct max8997_muic_info *info = platform_get_drvdata(pdev);
int i;
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
free_irq(muic_irqs[i].virq, info);
cancel_work_sync(&info->irq_work);
return 0;
} }
static struct platform_driver max8997_muic_driver = { static struct platform_driver max8997_muic_driver = {
...@@ -780,7 +766,6 @@ static struct platform_driver max8997_muic_driver = { ...@@ -780,7 +766,6 @@ static struct platform_driver max8997_muic_driver = {
.name = DEV_NAME, .name = DEV_NAME,
}, },
.probe = max8997_muic_probe, .probe = max8997_muic_probe,
.remove = max8997_muic_remove,
}; };
module_platform_driver(max8997_muic_driver); module_platform_driver(max8997_muic_driver);
......
...@@ -51,4 +51,29 @@ static inline int devm_delayed_work_autocancel(struct device *dev, ...@@ -51,4 +51,29 @@ static inline int devm_delayed_work_autocancel(struct device *dev,
return devm_add_action(dev, devm_delayed_work_drop, w); return devm_add_action(dev, devm_delayed_work_drop, w);
} }
static inline void devm_work_drop(void *res)
{
cancel_work_sync(res);
}
/**
* devm_work_autocancel - Resource-managed work allocation
* @dev: Device which lifetime work is bound to
* @w: Work to be added (and automatically cancelled)
* @worker: Worker function
*
* Initialize work which is automatically cancelled when driver is detached.
* A few drivers need to queue work which must be cancelled before driver
* is detached to avoid accessing removed resources.
* devm_work_autocancel() can be used to omit the explicit
* cancelleation when driver is detached.
*/
static inline int devm_work_autocancel(struct device *dev,
struct work_struct *w,
work_func_t worker)
{
INIT_WORK(w, worker);
return devm_add_action(dev, devm_work_drop, w);
}
#endif #endif
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