Skip to content

Commit 94f3154

Browse files
committed
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.
2 parents aa2ddd2 + 87ee8de commit 94f3154

4 files changed

Lines changed: 50 additions & 53 deletions

File tree

drivers/extcon/extcon-max14577.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Chanwoo Choi <cw00.choi@samsung.com>
77
// Krzysztof Kozlowski <krzk@kernel.org>
88

9+
#include <linux/devm-helpers.h>
910
#include <linux/kernel.h>
1011
#include <linux/module.h>
1112
#include <linux/i2c.h>
@@ -673,7 +674,10 @@ static int max14577_muic_probe(struct platform_device *pdev)
673674
platform_set_drvdata(pdev, info);
674675
mutex_init(&info->mutex);
675676

676-
INIT_WORK(&info->irq_work, max14577_muic_irq_work);
677+
ret = devm_work_autocancel(&pdev->dev, &info->irq_work,
678+
max14577_muic_irq_work);
679+
if (ret)
680+
return ret;
677681

678682
switch (max14577->dev_type) {
679683
case MAXIM_DEVICE_TYPE_MAX77836:
@@ -766,15 +770,6 @@ static int max14577_muic_probe(struct platform_device *pdev)
766770
return ret;
767771
}
768772

769-
static int max14577_muic_remove(struct platform_device *pdev)
770-
{
771-
struct max14577_muic_info *info = platform_get_drvdata(pdev);
772-
773-
cancel_work_sync(&info->irq_work);
774-
775-
return 0;
776-
}
777-
778773
static const struct platform_device_id max14577_muic_id[] = {
779774
{ "max14577-muic", MAXIM_DEVICE_TYPE_MAX14577, },
780775
{ "max77836-muic", MAXIM_DEVICE_TYPE_MAX77836, },
@@ -797,7 +792,6 @@ static struct platform_driver max14577_muic_driver = {
797792
.of_match_table = of_max14577_muic_dt_match,
798793
},
799794
.probe = max14577_muic_probe,
800-
.remove = max14577_muic_remove,
801795
.id_table = max14577_muic_id,
802796
};
803797

drivers/extcon/extcon-max77693.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Copyright (C) 2012 Samsung Electrnoics
66
// Chanwoo Choi <cw00.choi@samsung.com>
77

8+
#include <linux/devm-helpers.h>
89
#include <linux/kernel.h>
910
#include <linux/module.h>
1011
#include <linux/i2c.h>
@@ -1127,7 +1128,10 @@ static int max77693_muic_probe(struct platform_device *pdev)
11271128
platform_set_drvdata(pdev, info);
11281129
mutex_init(&info->mutex);
11291130

1130-
INIT_WORK(&info->irq_work, max77693_muic_irq_work);
1131+
ret = devm_work_autocancel(&pdev->dev, &info->irq_work,
1132+
max77693_muic_irq_work);
1133+
if (ret)
1134+
return ret;
11311135

11321136
/* Support irq domain for MAX77693 MUIC device */
11331137
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
@@ -1254,22 +1258,11 @@ static int max77693_muic_probe(struct platform_device *pdev)
12541258
return ret;
12551259
}
12561260

1257-
static int max77693_muic_remove(struct platform_device *pdev)
1258-
{
1259-
struct max77693_muic_info *info = platform_get_drvdata(pdev);
1260-
1261-
cancel_work_sync(&info->irq_work);
1262-
input_unregister_device(info->dock);
1263-
1264-
return 0;
1265-
}
1266-
12671261
static struct platform_driver max77693_muic_driver = {
12681262
.driver = {
12691263
.name = DEV_NAME,
12701264
},
12711265
.probe = max77693_muic_probe,
1272-
.remove = max77693_muic_remove,
12731266
};
12741267

12751268
module_platform_driver(max77693_muic_driver);

drivers/extcon/extcon-max8997.c

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Copyright (C) 2012 Samsung Electronics
66
// Donggeun Kim <dg77.kim@samsung.com>
77

8+
#include <linux/devm-helpers.h>
89
#include <linux/kernel.h>
910
#include <linux/module.h>
1011
#include <linux/i2c.h>
@@ -650,42 +651,44 @@ static int max8997_muic_probe(struct platform_device *pdev)
650651
mutex_init(&info->mutex);
651652

652653
INIT_WORK(&info->irq_work, max8997_muic_irq_work);
654+
ret = devm_work_autocancel(&pdev->dev, &info->irq_work,
655+
max8997_muic_irq_work);
656+
if (ret)
657+
return ret;
653658

654659
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
655660
struct max8997_muic_irq *muic_irq = &muic_irqs[i];
656661
unsigned int virq = 0;
657662

658663
virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq);
659-
if (!virq) {
660-
ret = -EINVAL;
661-
goto err_irq;
662-
}
664+
if (!virq)
665+
return -EINVAL;
666+
663667
muic_irq->virq = virq;
664668

665-
ret = request_threaded_irq(virq, NULL,
666-
max8997_muic_irq_handler,
667-
IRQF_NO_SUSPEND,
668-
muic_irq->name, info);
669+
ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
670+
max8997_muic_irq_handler,
671+
IRQF_NO_SUSPEND,
672+
muic_irq->name, info);
669673
if (ret) {
670674
dev_err(&pdev->dev,
671675
"failed: irq request (IRQ: %d, error :%d)\n",
672676
muic_irq->irq, ret);
673-
goto err_irq;
677+
return ret;
674678
}
675679
}
676680

677681
/* External connector */
678682
info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable);
679683
if (IS_ERR(info->edev)) {
680684
dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
681-
ret = PTR_ERR(info->edev);
682-
goto err_irq;
685+
return PTR_ERR(info->edev);
683686
}
684687

685688
ret = devm_extcon_dev_register(&pdev->dev, info->edev);
686689
if (ret) {
687690
dev_err(&pdev->dev, "failed to register extcon device\n");
688-
goto err_irq;
691+
return ret;
689692
}
690693

691694
if (pdata && pdata->muic_pdata) {
@@ -756,31 +759,13 @@ static int max8997_muic_probe(struct platform_device *pdev)
756759
delay_jiffies);
757760

758761
return 0;
759-
760-
err_irq:
761-
while (--i >= 0)
762-
free_irq(muic_irqs[i].virq, info);
763-
return ret;
764-
}
765-
766-
static int max8997_muic_remove(struct platform_device *pdev)
767-
{
768-
struct max8997_muic_info *info = platform_get_drvdata(pdev);
769-
int i;
770-
771-
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
772-
free_irq(muic_irqs[i].virq, info);
773-
cancel_work_sync(&info->irq_work);
774-
775-
return 0;
776762
}
777763

778764
static struct platform_driver max8997_muic_driver = {
779765
.driver = {
780766
.name = DEV_NAME,
781767
},
782768
.probe = max8997_muic_probe,
783-
.remove = max8997_muic_remove,
784769
};
785770

786771
module_platform_driver(max8997_muic_driver);

include/linux/devm-helpers.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,29 @@ static inline int devm_delayed_work_autocancel(struct device *dev,
5151
return devm_add_action(dev, devm_delayed_work_drop, w);
5252
}
5353

54+
static inline void devm_work_drop(void *res)
55+
{
56+
cancel_work_sync(res);
57+
}
58+
59+
/**
60+
* devm_work_autocancel - Resource-managed work allocation
61+
* @dev: Device which lifetime work is bound to
62+
* @w: Work to be added (and automatically cancelled)
63+
* @worker: Worker function
64+
*
65+
* Initialize work which is automatically cancelled when driver is detached.
66+
* A few drivers need to queue work which must be cancelled before driver
67+
* is detached to avoid accessing removed resources.
68+
* devm_work_autocancel() can be used to omit the explicit
69+
* cancelleation when driver is detached.
70+
*/
71+
static inline int devm_work_autocancel(struct device *dev,
72+
struct work_struct *w,
73+
work_func_t worker)
74+
{
75+
INIT_WORK(w, worker);
76+
return devm_add_action(dev, devm_work_drop, w);
77+
}
78+
5479
#endif

0 commit comments

Comments
 (0)