Skip to contentSkip to conversation

counter/ftm-quaddec: Use device-managed registration API

PATCH Superseded Chuhong Yuan 2 participants 2 messages Jul 25, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 counter/ftm-quaddec: Use device-managed registration API

Make use of devm_counter_register.
Then we can remove redundant unregistration API
usage to make code simpler.

---
 drivers/counter/ftm-quaddec.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/counter/ftm-quaddec.c +1 -3
index 68a9b7393457..bccbca8681b6 100644
@@ -317,7 +317,7 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 
 	ftm_quaddec_init(ftm);
 
-	ret = counter_register(&ftm->counter);
+	ret = devm_counter_register(&pdev->dev, &ftm->counter);
 	if (ret)
 		ftm_quaddec_disable(ftm);
 
@@ -328,8 +328,6 @@ static int ftm_quaddec_remove(struct platform_device *pdev)
 {
 	struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
 
-	counter_unregister(&ftm->counter);
-
 	ftm_quaddec_disable(ftm);
 
 	return 0;
Signature · 1 line
2.20.1
#1 lore raw

Hello,

Comments inline

Quoted 24 lines · Chuhong Yuan

Make use of devm_counter_register.
Then we can remove redundant unregistration API
usage to make code simpler.

---
 drivers/counter/ftm-quaddec.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/counter/ftm-quaddec.c +1 -1
index 68a9b7393457..bccbca8681b6 100644
@@ -317,7 +317,7 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 
        ftm_quaddec_init(ftm);
 
-       ret = counter_register(&ftm->counter);
+       ret = devm_counter_register(&pdev->dev, &ftm->counter);
        if (ret)
                ftm_quaddec_disable(ftm);
 

drivers/counter/ftm-quaddec.c static int ftm_quaddec_remove(struct platform_device *pdev) · line 332

Quoted 5 lines
drivers/counter/ftm-quaddec.c +0 -2
@@ -328,8 +328,6 @@ static int ftm_quaddec_remove(struct platform_device *pdev)
 {
        struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
 
-       counter_unregister(&ftm->counter);
-

The orders of (de)initialization should be kept symmetrical. In this case, now that counter_unregister() will be called via devm, it will be executed after ftm_quaddec_remove()

This introduces a race condition where the ftm-quaddec is disabled but the counter entry itself is not.

Somebody else (William?) should confirm this.

Quoted 6 lines
drivers/counter/ftm-quaddec.c +0 -1
        ftm_quaddec_disable(ftm);
 
        return 0;
--

2.20.1