Skip to content

Commit 74047ea

Browse files
M-Vaittinenjwrdegoede
authored andcommitted
extcon: extcon-max77693.c: Fix potential work-queue cancellation race
The extcon IRQ schedules a work item. IRQ is requested using devm while WQ is cancelld at remove(). This mixing of devm and manual unwinding has potential case where the WQ has been emptied (.remove() was ran) but devm unwinding of IRQ was not yet done. It may be possible the IRQ is triggered at this point scheduling new work item to the already flushed queue. According to the input documentation the input device allocated by devm_input_allocate_device() does not need to be explicitly unregistered. Use the new devm_work_autocancel() and remove the remove() to simplify the code. Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Chanwoo Choi <cw00.choi@samsung.com> Link: https://lore.kernel.org/r/cbe8205eed8276f6e6db5003cfe51b8b0d4ac966.1623146580.git.matti.vaittinen@fi.rohmeurope.com Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent 14ad768 commit 74047ea

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

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);

0 commit comments

Comments
 (0)