Skip to contentSkip to conversation

watchdog: dw: use devm_watchdog_register_device()

PATCH In review Jisheng Zhang 2 participants 4 messages Jan 25, 2019 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: dw: use devm_watchdog_register_device()

Use devm_watchdog_register_device() to simplify the code.

---
 drivers/watchdog/dw_wdt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/dw_wdt.c +1 -2
index 501aebb5b81f..c053c2de5c2f 100644
@@ -303,7 +303,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 
 	watchdog_set_restart_priority(wdd, 128);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(wdd);
 	if (ret)
 		goto out_disable_clk;
 
@@ -318,7 +318,6 @@ static int dw_wdt_drv_remove(struct platform_device *pdev)
 {
 	struct dw_wdt *dw_wdt = platform_get_drvdata(pdev);
 
-	watchdog_unregister_device(&dw_wdt->wdd);
 	reset_control_assert(dw_wdt->rst);
 	clk_disable_unprepare(dw_wdt->clk);
 
Signature · 1 line
2.20.1
maintainer
#1 lore raw

Hi,

Quoted 22 lines · Jisheng Zhang

Use devm_watchdog_register_device() to simplify the code.

---
  drivers/watchdog/dw_wdt.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/dw_wdt.c +1 -1
index 501aebb5b81f..c053c2de5c2f 100644
@@ -303,7 +303,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 
  	watchdog_set_restart_priority(wdd, 128);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(wdd);
  	if (ret)
  		goto out_disable_clk;
 

drivers/watchdog/dw_wdt.c static int dw_wdt_drv_remove(struct platform_device *pdev) · line 323

Quoted 7 lines
drivers/watchdog/dw_wdt.c +0 -1
@@ -318,7 +318,6 @@ static int dw_wdt_drv_remove(struct platform_device *pdev)
  {
  	struct dw_wdt *dw_wdt = platform_get_drvdata(pdev);
 
-	watchdog_unregister_device(&dw_wdt->wdd);
  	reset_control_assert(dw_wdt->rst);
  	clk_disable_unprepare(dw_wdt->clk);
 

Unfortunately it isn't that easy. The other two calls have to be executed after unregistering the watchdog, meaning you would have to add devm_add_action() in the probe function to call them.

Guenter

#2 lore raw

Hi,

Quoted 27 lines · On Fri, 25 Jan 2019 00:04:25 -0800 Guenter Roeck wrote:

Hi,

Quoted 24 lines · Jisheng Zhang

Use devm_watchdog_register_device() to simplify the code.

---
  drivers/watchdog/dw_wdt.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/dw_wdt.c +1 -1
index 501aebb5b81f..c053c2de5c2f 100644
@@ -303,7 +303,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 
  	watchdog_set_restart_priority(wdd, 128);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(wdd);
  	if (ret)
  		goto out_disable_clk;
 
@@ -318,7 +318,6 @@ static int dw_wdt_drv_remove(struct platform_device *pdev)
  {
  	struct dw_wdt *dw_wdt = platform_get_drvdata(pdev);
 
Quoted 8 lines

drivers/watchdog/dw_wdt.c static int dw_wdt_drv_remove(struct platform_device *pdev) · line 323

Quoted 5 lines
drivers/watchdog/dw_wdt.c +0 -1
-	watchdog_unregister_device(&dw_wdt->wdd);
  	reset_control_assert(dw_wdt->rst);
  	clk_disable_unprepare(dw_wdt->clk);
 

Unfortunately it isn't that easy. The other two calls have to be executed after unregistering the watchdog, meaning you would have to add devm_add_action() in the probe function to call them.

do you mean reset_control_asser() and the clk_disable_unprepare()? If yes, does unregister the watchdog could trigger any register access? Per my understanding, there's no register access path in the unregister. Am I missing somthing?

Thanks

maintainer
#3 lore raw
Quoted 40 lines · Jisheng Zhang

Hi,

Quoted 27 lines · On Fri, 25 Jan 2019 00:04:25 -0800 Guenter Roeck wrote:

Hi,

Quoted 24 lines · Jisheng Zhang

Use devm_watchdog_register_device() to simplify the code.

---
   drivers/watchdog/dw_wdt.c | 3 +--
   1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/dw_wdt.c +1 -1
index 501aebb5b81f..c053c2de5c2f 100644
@@ -303,7 +303,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 
   	watchdog_set_restart_priority(wdd, 128);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(wdd);
   	if (ret)
   		goto out_disable_clk;
 
@@ -318,7 +318,6 @@ static int dw_wdt_drv_remove(struct platform_device *pdev)
   {
   	struct dw_wdt *dw_wdt = platform_get_drvdata(pdev);
 
Quoted 8 lines

drivers/watchdog/dw_wdt.c static int dw_wdt_drv_remove(struct platform_device *pdev) · line 323

Quoted 5 lines
drivers/watchdog/dw_wdt.c +0 -1
-	watchdog_unregister_device(&dw_wdt->wdd);
   	reset_control_assert(dw_wdt->rst);
   	clk_disable_unprepare(dw_wdt->clk);
 

Unfortunately it isn't that easy. The other two calls have to be executed after unregistering the watchdog, meaning you would have to add devm_add_action() in the probe function to call them.

Quoted 1 line

do you mean reset_control_asser() and the clk_disable_unprepare()? If yes,

Yes.

Quoted 4 lines

does unregister the watchdog could trigger any register access? Per my understanding, there's no register access path in the unregister. Am I missing somthing?

If the watchdog is unregistered last, it would be still accessible via its device nodes, even though the clock has been reset, and even though the HW has been put in reset. This would be racy.

Guenter