Skip to content

Commit 87ee8de

Browse files
M-Vaittinenjwrdegoede
authored andcommitted
extcon: extcon-max8997: Simplify driver using devm
Simplify driver by switching to use the resource managed IRQ requesting and resource managed work-queue initialization. Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Chanwoo Choi <cw00.choi@samsung.com> Link: https://lore.kernel.org/r/61190cc280a63baeb05ec570282bb3677bee8e7b.1623146580.git.matti.vaittinen@fi.rohmeurope.com Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent 610bdc0 commit 87ee8de

1 file changed

Lines changed: 16 additions & 31 deletions

File tree

drivers/extcon/extcon-max8997.c

Lines changed: 16 additions & 31 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) {
@@ -733,7 +736,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
733736
2, info->status);
734737
if (ret) {
735738
dev_err(info->dev, "failed to read MUIC register\n");
736-
goto err_irq;
739+
return ret;
737740
}
738741
cable_type = max8997_muic_get_cable_type(info,
739742
MAX8997_CABLE_GROUP_ADC, &attached);
@@ -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);

0 commit comments

Comments
 (0)