linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/62] watchdog: Convert to use device managed functions
@ 2017-01-10 23:34 Guenter Roeck
  2017-01-10 23:34 ` [PATCH 01/62] watchdog: asm9260_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (31 more replies)
  0 siblings, 32 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts
used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches.

To reproduce this series of patches, checkout the tree above, then run
the following commands from the Linux source tree.

sh ~coccinelle-patches/watchdog/make.sh
sh ~coccinelle-patches/watchdog/do-commit.sh

The patch series is based on the following tree and branch.

git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
	watchdog-next

----------------------------------------------------------------
Guenter Roeck (62):
      watchdog: asm9260_wdt: Convert to use device managed functions and other improvements
      watchdog: aspeed_wdt: Convert to use device managed functions
      watchdog: at91sam9_wdt: Convert to use device managed functions
      watchdog: atlas7_wdt: Convert to use device managed functions and other improvements
      watchdog: bcm2835_wdt: Convert to use device managed functions and other improvements
      watchdog: bcm47xx_wdt: Convert to use device managed functions
      watchdog: bcm7038_wdt: Convert to use device managed functions and other improvements
      watchdog: bcm_kona_wdt: Convert to use device managed functions and other improvements
      watchdog: cadence_wdt: Convert to use device managed functions and other improvements
      watchdog: coh901327_wdt: Convert to use device managed functions
      watchdog: da9052_wdt: Convert to use device managed functions
      watchdog: da9055_wdt: Convert to use device managed functions
      watchdog: da9062_wdt: Convert to use device managed functions
      watchdog: da9063_wdt: Convert to use device managed functions
      watchdog: davinci_wdt: Convert to use device managed functions and other improvements
      watchdog: digicolor_wdt: Convert to use device managed functions and other improvements
      watchdog: dw_wdt: Convert to use device managed functions
      watchdog: ep93xx_wdt: Convert to use device managed functions
      watchdog: gpio_wdt: Convert to use device managed functions
      watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot
      watchdog: imgpdc_wdt: Convert to use device managed functions and other improvements
      watchdog: imx2_wdt: Convert to use device managed functions
      watchdog: intel-mid_wdt: Convert to use device managed functions
      watchdog: jz4740_wdt: Convert to use device managed functions
      watchdog: kempld_wdt: Convert to use device managed functions and other improvements
      watchdog: loongson1_wdt: Convert to use device managed functions
      watchdog: lpc18xx_wdt: Convert to use device managed functions and other improvements
      watchdog: max63xx_wdt: Convert to use device managed functions
      watchdog: max77620_wdt: Convert to use device managed functions
      watchdog: mena21_wdt: Convert to use device managed functions and other improvements
      watchdog: menf21bmc_wdt: Convert to use device managed functions
      watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
      watchdog: meson_wdt: Convert to use device managed functions and other improvements
      watchdog: moxart_wdt: Convert to use device managed functions
      watchdog: mpc8xxx_wdt: Convert to use device managed functions
      watchdog: mt7621_wdt: Convert to use device managed functions and other improvements
      watchdog: mtk_wdt: Convert to use device managed functions and other improvements
      watchdog: nic7018_wdt: Convert to use device managed functions
      watchdog: of_xilinx_wdt: Convert to use device managed functions
      watchdog: omap_wdt: Convert to use device managed functions
      watchdog: orion_wdt: Convert to use device managed functions and other improvements
      watchdog: pic32-dmt: Convert to use device managed functions
      watchdog: pic32-wdt: Convert to use device managed functions
      watchdog: pnx4008_wdt: Convert to use device managed functions
      watchdog: qcom-wdt: Convert to use device managed functions
      watchdog: renesas_wdt: Convert to use device managed functions
      watchdog: retu_wdt: Convert to use device managed functions and other improvements
      watchdog: rt2880_wdt: Convert to use device managed functions and other improvements
      watchdog: sama5d4_wdt: Convert to use device managed functions
      watchdog: sbsa_gwdt: Convert to use device managed functions and other improvements
      watchdog: shwdt: Convert to use device managed functions and other improvements
      watchdog: sirfsoc_wdt: Convert to use device managed functions and other improvements
      watchdog: st_lpc_wdt: Convert to use device managed functions
      watchdog: stmp3xxx_rtc_wdt: Convert to use device managed functions
      watchdog: sunxi_wdt: Convert to use device managed functions and other improvements
      watchdog: tangox_wdt: Convert to use device managed functions
      watchdog: tegra_wdt: Convert to use device managed functions
      watchdog: ts4800_wdt: Convert to use device managed functions
      watchdog: twl4030_wdt: Convert to use device managed functions
      watchdog: txx9wdt: Convert to use device managed functions and other improvements
      watchdog: ux500_wdt: Convert to use device managed functions
      watchdog: wm831x_wdt: Convert to use device managed functions

 drivers/watchdog/asm9260_wdt.c      | 37 ++++++----------
 drivers/watchdog/aspeed_wdt.c       | 14 +-----
 drivers/watchdog/at91sam9_wdt.c     | 48 +++++++-------------
 drivers/watchdog/atlas7_wdt.c       | 43 +++++-------------
 drivers/watchdog/bcm2835_wdt.c      | 27 ++++--------
 drivers/watchdog/bcm47xx_wdt.c      | 31 +++++--------
 drivers/watchdog/bcm7038_wdt.c      | 25 +++++------
 drivers/watchdog/bcm_kona_wdt.c     | 14 ++----
 drivers/watchdog/cadence_wdt.c      | 35 ++++-----------
 drivers/watchdog/coh901327_wdt.c    | 33 +++++---------
 drivers/watchdog/da9052_wdt.c       | 32 ++++----------
 drivers/watchdog/da9055_wdt.c       | 17 +-------
 drivers/watchdog/da9062_wdt.c       | 18 +-------
 drivers/watchdog/da9063_wdt.c       | 18 +-------
 drivers/watchdog/davinci_wdt.c      | 28 +++++-------
 drivers/watchdog/digicolor_wdt.c    | 48 +++++---------------
 drivers/watchdog/dw_wdt.c           | 32 ++++----------
 drivers/watchdog/ep93xx_wdt.c       |  9 +---
 drivers/watchdog/gpio_wdt.c         | 23 ++++------
 drivers/watchdog/iTCO_wdt.c         |  9 +---
 drivers/watchdog/imgpdc_wdt.c       | 42 +++++++-----------
 drivers/watchdog/imx2_wdt.c         | 15 +++----
 drivers/watchdog/intel-mid_wdt.c    | 11 +----
 drivers/watchdog/jz4740_wdt.c       | 22 +++-------
 drivers/watchdog/kempld_wdt.c       | 12 +----
 drivers/watchdog/loongson1_wdt.c    | 31 ++++---------
 drivers/watchdog/lpc18xx_wdt.c      | 58 ++++++++-----------------
 drivers/watchdog/max63xx_wdt.c      | 12 +----
 drivers/watchdog/max77620_wdt.c     |  3 +-
 drivers/watchdog/mena21_wdt.c       | 24 +---------
 drivers/watchdog/menf21bmc_wdt.c    | 15 +------
 drivers/watchdog/meson_gxbb_wdt.c   | 38 +++++-----------
 drivers/watchdog/meson_wdt.c        | 23 +---------
 drivers/watchdog/moxart_wdt.c       |  5 +--
 drivers/watchdog/mpc8xxx_wdt.c      | 25 +++++------
 drivers/watchdog/mt7621_wdt.c       | 17 +-------
 drivers/watchdog/mtk_wdt.c          | 22 +---------
 drivers/watchdog/nic7018_wdt.c      |  4 +-
 drivers/watchdog/of_xilinx_wdt.c    | 28 ++++--------
 drivers/watchdog/omap_wdt.c         |  3 +-
 drivers/watchdog/orion_wdt.c        | 87 +++++++++++++++++--------------------
 drivers/watchdog/pic32-dmt.c        | 29 ++++---------
 drivers/watchdog/pic32-wdt.c        | 34 ++++-----------
 drivers/watchdog/pnx4008_wdt.c      | 23 +++-------
 drivers/watchdog/qcom-wdt.c         | 27 ++++--------
 drivers/watchdog/renesas_wdt.c      |  6 +--
 drivers/watchdog/retu_wdt.c         | 21 +++------
 drivers/watchdog/rt2880_wdt.c       | 17 +-------
 drivers/watchdog/sama5d4_wdt.c      |  4 +-
 drivers/watchdog/sbsa_gwdt.c        | 21 +--------
 drivers/watchdog/shwdt.c            | 11 +----
 drivers/watchdog/sirfsoc_wdt.c      | 13 ++----
 drivers/watchdog/st_lpc_wdt.c       | 11 ++---
 drivers/watchdog/stmp3xxx_rtc_wdt.c |  3 +-
 drivers/watchdog/sunxi_wdt.c        | 24 +---------
 drivers/watchdog/tangox_wdt.c       | 22 ++++------
 drivers/watchdog/tegra_wdt.c        |  4 +-
 drivers/watchdog/ts4800_wdt.c       | 14 +-----
 drivers/watchdog/twl4030_wdt.c      | 17 +-------
 drivers/watchdog/txx9wdt.c          | 46 +++++++-------------
 drivers/watchdog/ux500_wdt.c        | 10 +----
 drivers/watchdog/wm831x_wdt.c       | 31 +++----------
 62 files changed, 387 insertions(+), 1039 deletions(-)

^ permalink raw reply	[flat|nested] 98+ messages in thread

* [PATCH 01/62] watchdog: asm9260_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 02/62] watchdog: aspeed_wdt: Convert to use device managed functions Guenter Roeck
                   ` (30 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/asm9260_wdt.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/drivers/watchdog/asm9260_wdt.c b/drivers/watchdog/asm9260_wdt.c
index 028feb6f6e53..828ca7d5e671 100644
--- a/drivers/watchdog/asm9260_wdt.c
+++ b/drivers/watchdog/asm9260_wdt.c
@@ -219,26 +219,32 @@ static int asm9260_wdt_get_dt_clks(struct asm9260_wdt_priv *priv)
 		dev_err(priv->dev, "Failed to enable ahb_clk!\n");
 		return err;
 	}
+	err = devm_add_action_or_reset(priv->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       priv->clk_ahb);
+	if (err)
+		return err;
 
 	err = clk_set_rate(priv->clk, CLOCK_FREQ);
 	if (err) {
-		clk_disable_unprepare(priv->clk_ahb);
 		dev_err(priv->dev, "Failed to set rate!\n");
 		return err;
 	}
 
 	err = clk_prepare_enable(priv->clk);
 	if (err) {
-		clk_disable_unprepare(priv->clk_ahb);
 		dev_err(priv->dev, "Failed to enable clk!\n");
 		return err;
 	}
+	err = devm_add_action_or_reset(priv->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       priv->clk);
+	if (err)
+		return err;
 
 	/* wdt has internal divider */
 	clk = clk_get_rate(priv->clk);
 	if (!clk) {
-		clk_disable_unprepare(priv->clk);
-		clk_disable_unprepare(priv->clk_ahb);
 		dev_err(priv->dev, "Failed, clk is 0!\n");
 		return -EINVAL;
 	}
@@ -335,27 +341,16 @@ static int asm9260_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_restart_priority(wdd, 128);
 
-	ret = watchdog_register_device(wdd);
+	watchdog_stop_on_reboot(wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, wdd);
 	if (ret)
-		goto clk_off;
+		return ret;
 
 	platform_set_drvdata(pdev, priv);
 
 	dev_info(&pdev->dev, "Watchdog enabled (timeout: %d sec, mode: %s)\n",
 		 wdd->timeout, mode_name[priv->mode]);
 	return 0;
-
-clk_off:
-	clk_disable_unprepare(priv->clk);
-	clk_disable_unprepare(priv->clk_ahb);
-	return ret;
-}
-
-static void asm9260_wdt_shutdown(struct platform_device *pdev)
-{
-	struct asm9260_wdt_priv *priv = platform_get_drvdata(pdev);
-
-	asm9260_wdt_disable(&priv->wdd);
 }
 
 static int asm9260_wdt_remove(struct platform_device *pdev)
@@ -364,11 +359,6 @@ static int asm9260_wdt_remove(struct platform_device *pdev)
 
 	asm9260_wdt_disable(&priv->wdd);
 
-	watchdog_unregister_device(&priv->wdd);
-
-	clk_disable_unprepare(priv->clk);
-	clk_disable_unprepare(priv->clk_ahb);
-
 	return 0;
 }
 
@@ -385,7 +375,6 @@ static struct platform_driver asm9260_wdt_driver = {
 	},
 	.probe = asm9260_wdt_probe,
 	.remove = asm9260_wdt_remove,
-	.shutdown = asm9260_wdt_shutdown,
 };
 module_platform_driver(asm9260_wdt_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 02/62] watchdog: aspeed_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
  2017-01-10 23:34 ` [PATCH 01/62] watchdog: asm9260_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-11  5:18   ` Joel Stanley
  2017-01-10 23:34 ` [PATCH 03/62] watchdog: at91sam9_wdt: " Guenter Roeck
                   ` (29 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Joel Stanley

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Joel Stanley <joel@jms.id.au>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/aspeed_wdt.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c
index f5ad8023c2e6..1c652582de40 100644
--- a/drivers/watchdog/aspeed_wdt.c
+++ b/drivers/watchdog/aspeed_wdt.c
@@ -136,15 +136,6 @@ static const struct watchdog_info aspeed_wdt_info = {
 	.identity	= KBUILD_MODNAME,
 };
 
-static int aspeed_wdt_remove(struct platform_device *pdev)
-{
-	struct aspeed_wdt *wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&wdt->wdd);
-
-	return 0;
-}
-
 static int aspeed_wdt_probe(struct platform_device *pdev)
 {
 	struct aspeed_wdt *wdt;
@@ -187,20 +178,17 @@ static int aspeed_wdt_probe(struct platform_device *pdev)
 		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
 	}
 
-	ret = watchdog_register_device(&wdt->wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register\n");
 		return ret;
 	}
 
-	platform_set_drvdata(pdev, wdt);
-
 	return 0;
 }
 
 static struct platform_driver aspeed_watchdog_driver = {
 	.probe = aspeed_wdt_probe,
-	.remove = aspeed_wdt_remove,
 	.driver = {
 		.name = KBUILD_MODNAME,
 		.of_match_table = of_match_ptr(aspeed_wdt_of_table),
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 03/62] watchdog: at91sam9_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
  2017-01-10 23:34 ` [PATCH 01/62] watchdog: asm9260_wdt: Convert to use device managed functions and other improvements Guenter Roeck
  2017-01-10 23:34 ` [PATCH 02/62] watchdog: aspeed_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 04/62] watchdog: atlas7_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (28 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Replace request_irq, request_threaded_irq, and request_any_context_irq
  with their device managed equivalent
- Drop platform_set_drvdata()
- Call del_timer() using devm_add_action()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/at91sam9_wdt.c | 48 ++++++++++++++---------------------------
 1 file changed, 16 insertions(+), 32 deletions(-)

diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index 7e6acaf3ece4..7c3c3554348d 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -209,10 +209,9 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt)
 			 "min heartbeat and max heartbeat might be too close for the system to handle it correctly\n");
 
 	if ((tmp & AT91_WDT_WDFIEN) && wdt->irq) {
-		err = request_irq(wdt->irq, wdt_interrupt,
-				  IRQF_SHARED | IRQF_IRQPOLL |
-				  IRQF_NO_SUSPEND,
-				  pdev->name, wdt);
+		err = devm_request_irq(&pdev->dev, wdt->irq, wdt_interrupt,
+				IRQF_SHARED | IRQF_IRQPOLL | IRQF_NO_SUSPEND,
+				pdev->name, wdt);
 		if (err)
 			return err;
 	}
@@ -223,6 +222,10 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt)
 			 tmp & wdt->mr_mask, wdt->mr & wdt->mr_mask);
 
 	setup_timer(&wdt->timer, at91_ping, (unsigned long)wdt);
+	err = devm_add_action(&pdev->dev, (void(*)(void *))del_timer,
+			       &wdt->timer);
+	if (err)
+		return err;
 
 	/*
 	 * Use min_heartbeat the first time to avoid spurious watchdog reset:
@@ -237,17 +240,13 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt)
 	if (watchdog_init_timeout(&wdt->wdd, 0, dev))
 		watchdog_init_timeout(&wdt->wdd, heartbeat, dev);
 	watchdog_set_nowayout(&wdt->wdd, wdt->nowayout);
-	err = watchdog_register_device(&wdt->wdd);
+	err = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
 	if (err)
-		goto out_stop_timer;
+		return err;
 
 	wdt->next_heartbeat = jiffies + wdt->wdd.timeout * HZ;
 
 	return 0;
-
-out_stop_timer:
-	del_timer(&wdt->timer);
-	return err;
 }
 
 /* ......................................................................... */
@@ -363,40 +362,26 @@ static int __init at91wdt_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Could not enable slow clock\n");
 		return err;
 	}
+	err = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       wdt->sclk);
+	if (err)
+		return err;
 
 	if (pdev->dev.of_node) {
 		err = of_at91wdt_init(pdev->dev.of_node, wdt);
 		if (err)
-			goto err_clk;
+			return err;
 	}
 
 	err = at91_wdt_init(pdev, wdt);
 	if (err)
-		goto err_clk;
-
-	platform_set_drvdata(pdev, wdt);
+		return err;
 
 	pr_info("enabled (heartbeat=%d sec, nowayout=%d)\n",
 		wdt->wdd.timeout, wdt->nowayout);
 
 	return 0;
-
-err_clk:
-	clk_disable_unprepare(wdt->sclk);
-
-	return err;
-}
-
-static int __exit at91wdt_remove(struct platform_device *pdev)
-{
-	struct at91wdt *wdt = platform_get_drvdata(pdev);
-	watchdog_unregister_device(&wdt->wdd);
-
-	pr_warn("I quit now, hardware will probably reboot!\n");
-	del_timer(&wdt->timer);
-	clk_disable_unprepare(wdt->sclk);
-
-	return 0;
 }
 
 #if defined(CONFIG_OF)
@@ -409,7 +394,6 @@ MODULE_DEVICE_TABLE(of, at91_wdt_dt_ids);
 #endif
 
 static struct platform_driver at91wdt_driver = {
-	.remove		= __exit_p(at91wdt_remove),
 	.driver		= {
 		.name	= "at91_wdt",
 		.of_match_table = of_match_ptr(at91_wdt_dt_ids),
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 04/62] watchdog: atlas7_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (2 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 03/62] watchdog: at91sam9_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 05/62] watchdog: bcm2835_wdt: " Guenter Roeck
                   ` (27 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)'
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/atlas7_wdt.c | 43 ++++++++++++-------------------------------
 1 file changed, 12 insertions(+), 31 deletions(-)

diff --git a/drivers/watchdog/atlas7_wdt.c b/drivers/watchdog/atlas7_wdt.c
index ed80734befae..62b75d34f1a0 100644
--- a/drivers/watchdog/atlas7_wdt.c
+++ b/drivers/watchdog/atlas7_wdt.c
@@ -127,7 +127,6 @@ static const struct of_device_id atlas7_wdt_ids[] = {
 
 static int atlas7_wdt_probe(struct platform_device *pdev)
 {
-	struct device_node *np = pdev->dev.of_node;
 	struct atlas7_wdog *wdt;
 	struct resource *res;
 	struct clk *clk;
@@ -141,23 +140,26 @@ static int atlas7_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(wdt->base))
 		return PTR_ERR(wdt->base);
 
-	clk = of_clk_get(np, 0);
+	clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 	ret = clk_prepare_enable(clk);
 	if (ret) {
 		dev_err(&pdev->dev, "clk enable failed\n");
-		goto err;
+		return ret;
 	}
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       clk);
+	if (ret)
+		return ret;
 
 	/* disable watchdog hardware */
 	writel(0, wdt->base + ATLAS7_WDT_CNT_CTRL);
 
 	wdt->tick_rate = clk_get_rate(clk);
-	if (!wdt->tick_rate) {
-		ret = -EINVAL;
-		goto err1;
-	}
+	if (!wdt->tick_rate)
+		return -EINVAL;
 
 	wdt->clk = clk;
 	atlas7_wdd.min_timeout = 1;
@@ -169,35 +171,15 @@ static int atlas7_wdt_probe(struct platform_device *pdev)
 	watchdog_set_drvdata(&atlas7_wdd, wdt);
 	platform_set_drvdata(pdev, &atlas7_wdd);
 
-	ret = watchdog_register_device(&atlas7_wdd);
-	if (ret)
-		goto err1;
-
-	return 0;
-
-err1:
-	clk_disable_unprepare(clk);
-err:
-	clk_put(clk);
-	return ret;
-}
-
-static void atlas7_wdt_shutdown(struct platform_device *pdev)
-{
-	struct watchdog_device *wdd = platform_get_drvdata(pdev);
-	struct atlas7_wdog *wdt = watchdog_get_drvdata(wdd);
-
-	atlas7_wdt_disable(wdd);
-	clk_disable_unprepare(wdt->clk);
+	watchdog_stop_on_reboot(&atlas7_wdd);
+	return devm_watchdog_register_device(&pdev->dev, &atlas7_wdd);
 }
 
 static int atlas7_wdt_remove(struct platform_device *pdev)
 {
 	struct watchdog_device *wdd = platform_get_drvdata(pdev);
-	struct atlas7_wdog *wdt = watchdog_get_drvdata(wdd);
 
-	atlas7_wdt_shutdown(pdev);
-	clk_put(wdt->clk);
+	atlas7_wdt_disable(wdd);
 	return 0;
 }
 
@@ -237,7 +219,6 @@ static struct platform_driver atlas7_wdt_driver = {
 	},
 	.probe = atlas7_wdt_probe,
 	.remove = atlas7_wdt_remove,
-	.shutdown = atlas7_wdt_shutdown,
 };
 module_platform_driver(atlas7_wdt_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 05/62] watchdog: bcm2835_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (3 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 04/62] watchdog: atlas7_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-14  6:27   ` Eric Anholt
  2017-01-10 23:34 ` [PATCH 06/62] watchdog: bcm47xx_wdt: Convert to use device managed functions Guenter Roeck
                   ` (26 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Stephen Warren,
	Lee Jones, Eric Anholt, Florian Fainelli, Ray Jui, Scott Branden,
	bcm-kernel-feedback-list, linux-arm-kernel, linux-rpi-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Replace of_iomap() with platform_get_resource() followed by
  devm_ioremap_resource()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Stephen Warren <swarren@wwwdotorg.org>
Cc: Lee Jones <lee@kernel.org>
Cc: Eric Anholt <eric@anholt.net>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: bcm-kernel-feedback-list@broadcom.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/bcm2835_wdt.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/drivers/watchdog/bcm2835_wdt.c b/drivers/watchdog/bcm2835_wdt.c
index 4e0adb6c88f0..496f6c106bb1 100644
--- a/drivers/watchdog/bcm2835_wdt.c
+++ b/drivers/watchdog/bcm2835_wdt.c
@@ -172,8 +172,8 @@ static void bcm2835_power_off(void)
 
 static int bcm2835_wdt_probe(struct platform_device *pdev)
 {
+	struct resource *res;
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;
 	struct bcm2835_wdt *wdt;
 	int err;
 
@@ -184,16 +184,15 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)
 
 	spin_lock_init(&wdt->lock);
 
-	wdt->base = of_iomap(np, 0);
-	if (!wdt->base) {
-		dev_err(dev, "Failed to remap watchdog regs");
-		return -ENODEV;
-	}
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	wdt->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(wdt->base))
+		return PTR_ERR(wdt->base);
 
 	watchdog_set_drvdata(&bcm2835_wdt_wdd, wdt);
 	watchdog_init_timeout(&bcm2835_wdt_wdd, heartbeat, dev);
 	watchdog_set_nowayout(&bcm2835_wdt_wdd, nowayout);
-	bcm2835_wdt_wdd.parent = &pdev->dev;
+	bcm2835_wdt_wdd.parent = dev;
 	if (bcm2835_wdt_is_running(wdt)) {
 		/*
 		 * The currently active timeout value (set by the
@@ -208,10 +207,10 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_restart_priority(&bcm2835_wdt_wdd, 128);
 
-	err = watchdog_register_device(&bcm2835_wdt_wdd);
+	watchdog_stop_on_reboot(&bcm2835_wdt_wdd);
+	err = devm_watchdog_register_device(dev, &bcm2835_wdt_wdd);
 	if (err) {
 		dev_err(dev, "Failed to register watchdog device");
-		iounmap(wdt->base);
 		return err;
 	}
 
@@ -224,21 +223,12 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)
 
 static int bcm2835_wdt_remove(struct platform_device *pdev)
 {
-	struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
-
 	if (pm_power_off == bcm2835_power_off)
 		pm_power_off = NULL;
-	watchdog_unregister_device(&bcm2835_wdt_wdd);
-	iounmap(wdt->base);
 
 	return 0;
 }
 
-static void bcm2835_wdt_shutdown(struct platform_device *pdev)
-{
-	bcm2835_wdt_stop(&bcm2835_wdt_wdd);
-}
-
 static const struct of_device_id bcm2835_wdt_of_match[] = {
 	{ .compatible = "brcm,bcm2835-pm-wdt", },
 	{},
@@ -248,7 +238,6 @@ MODULE_DEVICE_TABLE(of, bcm2835_wdt_of_match);
 static struct platform_driver bcm2835_wdt_driver = {
 	.probe		= bcm2835_wdt_probe,
 	.remove		= bcm2835_wdt_remove,
-	.shutdown	= bcm2835_wdt_shutdown,
 	.driver = {
 		.name =		"bcm2835-wdt",
 		.of_match_table = bcm2835_wdt_of_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 06/62] watchdog: bcm47xx_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (4 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 05/62] watchdog: bcm2835_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 07/62] watchdog: bcm7038_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (25 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Call del_timer_sync() using devm_add_action()
  Introduce helper function since we can not call del_timer_sync() directly
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/bcm47xx_wdt.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/drivers/watchdog/bcm47xx_wdt.c b/drivers/watchdog/bcm47xx_wdt.c
index 35725e21b18a..83455ca1712e 100644
--- a/drivers/watchdog/bcm47xx_wdt.c
+++ b/drivers/watchdog/bcm47xx_wdt.c
@@ -177,6 +177,11 @@ static struct watchdog_ops bcm47xx_wdt_soft_ops = {
 	.restart        = bcm47xx_wdt_restart,
 };
 
+static void __del_timer_sync_cb(void *t)
+{
+	del_timer_sync(t);
+}
+
 static int bcm47xx_wdt_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -192,6 +197,10 @@ static int bcm47xx_wdt_probe(struct platform_device *pdev)
 		wdt->wdd.ops = &bcm47xx_wdt_soft_ops;
 		setup_timer(&wdt->soft_timer, bcm47xx_wdt_soft_timer_tick,
 			    (long unsigned int)wdt);
+		ret = devm_add_action(&pdev->dev, __del_timer_sync_cb,
+				       &wdt->soft_timer);
+		if (ret)
+			return ret;
 	} else {
 		wdt->wdd.ops = &bcm47xx_wdt_hard_ops;
 	}
@@ -201,34 +210,19 @@ static int bcm47xx_wdt_probe(struct platform_device *pdev)
 	wdt->wdd.parent = &pdev->dev;
 	ret = wdt->wdd.ops->set_timeout(&wdt->wdd, timeout);
 	if (ret)
-		goto err_timer;
+		return ret;
 	watchdog_set_nowayout(&wdt->wdd, nowayout);
 	watchdog_set_restart_priority(&wdt->wdd, 64);
 	watchdog_stop_on_reboot(&wdt->wdd);
 
-	ret = watchdog_register_device(&wdt->wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
 	if (ret)
-		goto err_timer;
+		return ret;
 
 	dev_info(&pdev->dev, "BCM47xx Watchdog Timer enabled (%d seconds%s%s)\n",
 		timeout, nowayout ? ", nowayout" : "",
 		soft ? ", Software Timer" : "");
 	return 0;
-
-err_timer:
-	if (soft)
-		del_timer_sync(&wdt->soft_timer);
-
-	return ret;
-}
-
-static int bcm47xx_wdt_remove(struct platform_device *pdev)
-{
-	struct bcm47xx_wdt *wdt = dev_get_platdata(&pdev->dev);
-
-	watchdog_unregister_device(&wdt->wdd);
-
-	return 0;
 }
 
 static struct platform_driver bcm47xx_wdt_driver = {
@@ -236,7 +230,6 @@ static struct platform_driver bcm47xx_wdt_driver = {
 		.name	= "bcm47xx-wdt",
 	},
 	.probe		= bcm47xx_wdt_probe,
-	.remove		= bcm47xx_wdt_remove,
 };
 
 module_platform_driver(bcm47xx_wdt_driver);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 07/62] watchdog: bcm7038_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (5 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 06/62] watchdog: bcm47xx_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 08/62] watchdog: bcm_kona_wdt: " Guenter Roeck
                   ` (24 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Check return value from clk_prepare_enable()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/bcm7038_wdt.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/watchdog/bcm7038_wdt.c b/drivers/watchdog/bcm7038_wdt.c
index c1b8e534fb55..a17942e5e0a6 100644
--- a/drivers/watchdog/bcm7038_wdt.c
+++ b/drivers/watchdog/bcm7038_wdt.c
@@ -136,7 +136,14 @@ static int bcm7038_wdt_probe(struct platform_device *pdev)
 	wdt->clk = devm_clk_get(dev, NULL);
 	/* If unable to get clock, use default frequency */
 	if (!IS_ERR(wdt->clk)) {
-		clk_prepare_enable(wdt->clk);
+		err = clk_prepare_enable(wdt->clk);
+		if (err)
+			return err;
+		err = devm_add_action_or_reset(dev,
+					(void(*)(void *))clk_disable_unprepare,
+					wdt->clk);
+		if (err)
+			return err;
 		wdt->rate = clk_get_rate(wdt->clk);
 		/* Prevent divide-by-zero exception */
 		if (!wdt->rate)
@@ -154,10 +161,10 @@ static int bcm7038_wdt_probe(struct platform_device *pdev)
 	wdt->wdd.parent		= dev;
 	watchdog_set_drvdata(&wdt->wdd, wdt);
 
-	err = watchdog_register_device(&wdt->wdd);
+	watchdog_stop_on_reboot(&wdt->wdd);
+	err = devm_watchdog_register_device(dev, &wdt->wdd);
 	if (err) {
 		dev_err(dev, "Failed to register watchdog device\n");
-		clk_disable_unprepare(wdt->clk);
 		return err;
 	}
 
@@ -173,9 +180,6 @@ static int bcm7038_wdt_remove(struct platform_device *pdev)
 	if (!nowayout)
 		bcm7038_wdt_stop(&wdt->wdd);
 
-	watchdog_unregister_device(&wdt->wdd);
-	clk_disable_unprepare(wdt->clk);
-
 	return 0;
 }
 
@@ -204,14 +208,6 @@ static int bcm7038_wdt_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(bcm7038_wdt_pm_ops, bcm7038_wdt_suspend,
 			 bcm7038_wdt_resume);
 
-static void bcm7038_wdt_shutdown(struct platform_device *pdev)
-{
-	struct bcm7038_watchdog *wdt = platform_get_drvdata(pdev);
-
-	if (watchdog_active(&wdt->wdd))
-		bcm7038_wdt_stop(&wdt->wdd);
-}
-
 static const struct of_device_id bcm7038_wdt_match[] = {
 	{ .compatible = "brcm,bcm7038-wdt" },
 	{},
@@ -221,7 +217,6 @@ MODULE_DEVICE_TABLE(of, bcm7038_wdt_match);
 static struct platform_driver bcm7038_wdt_driver = {
 	.probe		= bcm7038_wdt_probe,
 	.remove		= bcm7038_wdt_remove,
-	.shutdown	= bcm7038_wdt_shutdown,
 	.driver		= {
 		.name		= "bcm7038-wdt",
 		.of_match_table	= bcm7038_wdt_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 08/62] watchdog: bcm_kona_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (6 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 07/62] watchdog: bcm7038_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 09/62] watchdog: cadence_wdt: " Guenter Roeck
                   ` (23 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Florian Fainelli,
	Ray Jui, Scott Branden, bcm-kernel-feedback-list

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: bcm-kernel-feedback-list@broadcom.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/bcm_kona_wdt.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/watchdog/bcm_kona_wdt.c b/drivers/watchdog/bcm_kona_wdt.c
index 76b00805cd87..4592a205d8f9 100644
--- a/drivers/watchdog/bcm_kona_wdt.c
+++ b/drivers/watchdog/bcm_kona_wdt.c
@@ -288,11 +288,6 @@ static struct watchdog_device bcm_kona_wdt_wdd = {
 	.timeout =	SECWDOG_MAX_COUNT >> SECWDOG_DEFAULT_RESOLUTION,
 };
 
-static void bcm_kona_wdt_shutdown(struct platform_device *pdev)
-{
-	bcm_kona_wdt_stop(&bcm_kona_wdt_wdd);
-}
-
 static int bcm_kona_wdt_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -319,7 +314,7 @@ static int bcm_kona_wdt_probe(struct platform_device *pdev)
 	spin_lock_init(&wdt->lock);
 	platform_set_drvdata(pdev, wdt);
 	watchdog_set_drvdata(&bcm_kona_wdt_wdd, wdt);
-	bcm_kona_wdt_wdd.parent = &pdev->dev;
+	bcm_kona_wdt_wdd.parent = dev;
 
 	ret = bcm_kona_wdt_set_timeout_reg(&bcm_kona_wdt_wdd, 0);
 	if (ret) {
@@ -327,7 +322,8 @@ static int bcm_kona_wdt_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = watchdog_register_device(&bcm_kona_wdt_wdd);
+	watchdog_stop_on_reboot(&bcm_kona_wdt_wdd);
+	ret = devm_watchdog_register_device(dev, &bcm_kona_wdt_wdd);
 	if (ret) {
 		dev_err(dev, "Failed to register watchdog device");
 		return ret;
@@ -342,8 +338,7 @@ static int bcm_kona_wdt_probe(struct platform_device *pdev)
 static int bcm_kona_wdt_remove(struct platform_device *pdev)
 {
 	bcm_kona_wdt_debug_exit(pdev);
-	bcm_kona_wdt_shutdown(pdev);
-	watchdog_unregister_device(&bcm_kona_wdt_wdd);
+	bcm_kona_wdt_stop(platform_get_drvdata(pdev));
 	dev_dbg(&pdev->dev, "Watchdog driver disabled");
 
 	return 0;
@@ -362,7 +357,6 @@ static struct platform_driver bcm_kona_wdt_driver = {
 		  },
 	.probe = bcm_kona_wdt_probe,
 	.remove = bcm_kona_wdt_remove,
-	.shutdown = bcm_kona_wdt_shutdown,
 };
 
 module_platform_driver(bcm_kona_wdt_driver);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 09/62] watchdog: cadence_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (7 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 08/62] watchdog: bcm_kona_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions Guenter Roeck
                   ` (22 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/cadence_wdt.c | 35 +++++++++--------------------------
 1 file changed, 9 insertions(+), 26 deletions(-)

diff --git a/drivers/watchdog/cadence_wdt.c b/drivers/watchdog/cadence_wdt.c
index 8d61e8bfe60b..a77c4be54da9 100644
--- a/drivers/watchdog/cadence_wdt.c
+++ b/drivers/watchdog/cadence_wdt.c
@@ -340,8 +340,7 @@ static int cdns_wdt_probe(struct platform_device *pdev)
 	wdt->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(wdt->clk)) {
 		dev_err(&pdev->dev, "input clock not found\n");
-		ret = PTR_ERR(wdt->clk);
-		return ret;
+		return PTR_ERR(wdt->clk);
 	}
 
 	ret = clk_prepare_enable(wdt->clk);
@@ -349,6 +348,11 @@ static int cdns_wdt_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "unable to enable clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       wdt->clk);
+	if (ret)
+		return ret;
 
 	clock_f = clk_get_rate(wdt->clk);
 	if (clock_f <= CDNS_WDT_CLK_75MHZ) {
@@ -361,10 +365,11 @@ static int cdns_wdt_probe(struct platform_device *pdev)
 
 	spin_lock_init(&wdt->io_lock);
 
-	ret = watchdog_register_device(cdns_wdt_device);
+	watchdog_stop_on_reboot(cdns_wdt_device);
+	ret = devm_watchdog_register_device(&pdev->dev, cdns_wdt_device);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to register wdt device\n");
-		goto err_clk_disable;
+		return ret;
 	}
 	platform_set_drvdata(pdev, wdt);
 
@@ -373,11 +378,6 @@ static int cdns_wdt_probe(struct platform_device *pdev)
 		 nowayout ? ", nowayout" : "");
 
 	return 0;
-
-err_clk_disable:
-	clk_disable_unprepare(wdt->clk);
-
-	return ret;
 }
 
 /**
@@ -393,27 +393,11 @@ static int cdns_wdt_remove(struct platform_device *pdev)
 	struct cdns_wdt *wdt = platform_get_drvdata(pdev);
 
 	cdns_wdt_stop(&wdt->cdns_wdt_device);
-	watchdog_unregister_device(&wdt->cdns_wdt_device);
-	clk_disable_unprepare(wdt->clk);
 
 	return 0;
 }
 
 /**
- * cdns_wdt_shutdown - Stop the device.
- *
- * @pdev: handle to the platform structure.
- *
- */
-static void cdns_wdt_shutdown(struct platform_device *pdev)
-{
-	struct cdns_wdt *wdt = platform_get_drvdata(pdev);
-
-	cdns_wdt_stop(&wdt->cdns_wdt_device);
-	clk_disable_unprepare(wdt->clk);
-}
-
-/**
  * cdns_wdt_suspend - Stop the device.
  *
  * @dev: handle to the device structure.
@@ -468,7 +452,6 @@ MODULE_DEVICE_TABLE(of, cdns_wdt_of_match);
 static struct platform_driver cdns_wdt_driver = {
 	.probe		= cdns_wdt_probe,
 	.remove		= cdns_wdt_remove,
-	.shutdown	= cdns_wdt_shutdown,
 	.driver		= {
 		.name	= "cdns-wdt",
 		.of_match_table = cdns_wdt_of_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (8 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 09/62] watchdog: cadence_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-11 15:48   ` Linus Walleij
  2017-01-10 23:34 ` [PATCH 11/62] watchdog: da9052_wdt: " Guenter Roeck
                   ` (21 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Linus Walleij,
	linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_clk_get() if the device parameter is not NULL
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Replace request_irq, request_threaded_irq, and request_any_context_irq
  with their device managed equivalent
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/coh901327_wdt.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/drivers/watchdog/coh901327_wdt.c b/drivers/watchdog/coh901327_wdt.c
index 38dd60f0cfcc..8b6f7f35c479 100644
--- a/drivers/watchdog/coh901327_wdt.c
+++ b/drivers/watchdog/coh901327_wdt.c
@@ -241,11 +241,7 @@ static struct watchdog_device coh901327_wdt = {
 
 static int __exit coh901327_remove(struct platform_device *pdev)
 {
-	watchdog_unregister_device(&coh901327_wdt);
 	coh901327_disable();
-	free_irq(irq, pdev);
-	clk_disable_unprepare(clk);
-	clk_put(clk);
 	return 0;
 }
 
@@ -263,7 +259,7 @@ static int __init coh901327_probe(struct platform_device *pdev)
 	if (IS_ERR(virtbase))
 		return PTR_ERR(virtbase);
 
-	clk = clk_get(dev, NULL);
+	clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(clk)) {
 		ret = PTR_ERR(clk);
 		dev_err(dev, "could not get clock\n");
@@ -272,8 +268,13 @@ static int __init coh901327_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(clk);
 	if (ret) {
 		dev_err(dev, "could not prepare and enable clock\n");
-		goto out_no_clk_enable;
+		return ret;
 	}
+	ret = devm_add_action_or_reset(dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       clk);
+	if (ret)
+		return ret;
 
 	val = readw(virtbase + U300_WDOG_SR);
 	switch (val) {
@@ -309,31 +310,21 @@ static int __init coh901327_probe(struct platform_device *pdev)
 	writew(U300_WDOG_SR_RESET_STATUS_RESET, virtbase + U300_WDOG_SR);
 
 	irq = platform_get_irq(pdev, 0);
-	if (request_irq(irq, coh901327_interrupt, 0,
-			DRV_NAME " Bark", pdev)) {
-		ret = -EIO;
-		goto out_no_irq;
-	}
+	if (devm_request_irq(dev, irq, coh901327_interrupt, 0,
+			     DRV_NAME " Bark", pdev))
+		return -EIO;
 
 	ret = watchdog_init_timeout(&coh901327_wdt, margin, dev);
 	if (ret < 0)
 		coh901327_wdt.timeout = 60;
 
 	coh901327_wdt.parent = dev;
-	ret = watchdog_register_device(&coh901327_wdt);
+	ret = devm_watchdog_register_device(dev, &coh901327_wdt);
 	if (ret)
-		goto out_no_wdog;
+		return ret;
 
 	dev_info(dev, "initialized. timer margin=%d sec\n", margin);
 	return 0;
-
-out_no_wdog:
-	free_irq(irq, pdev);
-out_no_irq:
-	clk_disable_unprepare(clk);
-out_no_clk_enable:
-	clk_put(clk);
-	return ret;
 }
 
 #ifdef CONFIG_PM
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 11/62] watchdog: da9052_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (9 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-17 14:12   ` Adam Thomson
  2017-01-10 23:34 ` [PATCH 12/62] watchdog: da9055_wdt: " Guenter Roeck
                   ` (20 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Support Opensource

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Support Opensource <support.opensource@diasemi.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/da9052_wdt.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)

diff --git a/drivers/watchdog/da9052_wdt.c b/drivers/watchdog/da9052_wdt.c
index d86a57e3d17d..d6d5006efa71 100644
--- a/drivers/watchdog/da9052_wdt.c
+++ b/drivers/watchdog/da9052_wdt.c
@@ -128,16 +128,14 @@ static int da9052_wdt_ping(struct watchdog_device *wdt_dev)
 	ret = da9052_reg_update(da9052, DA9052_CONTROL_D_REG,
 				DA9052_CONTROLD_WATCHDOG, 1 << 7);
 	if (ret < 0)
-		goto err_strobe;
+		return ret;
 
 	/*
 	 * FIXME: Reset the watchdog core, in general PMIC
 	 * is supposed to do this
 	 */
-	ret = da9052_reg_update(da9052, DA9052_CONTROL_D_REG,
-				DA9052_CONTROLD_WATCHDOG, 0 << 7);
-err_strobe:
-	return ret;
+	return da9052_reg_update(da9052, DA9052_CONTROL_D_REG,
+				 DA9052_CONTROLD_WATCHDOG, 0 << 7);
 }
 
 static const struct watchdog_info da9052_wdt_info = {
@@ -163,10 +161,8 @@ static int da9052_wdt_probe(struct platform_device *pdev)
 
 	driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data),
 				   GFP_KERNEL);
-	if (!driver_data) {
-		ret = -ENOMEM;
-		goto err;
-	}
+	if (!driver_data)
+		return -ENOMEM;
 	driver_data->da9052 = da9052;
 
 	da9052_wdt = &driver_data->wdt;
@@ -182,33 +178,21 @@ static int da9052_wdt_probe(struct platform_device *pdev)
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to disable watchdog bits, %d\n",
 			ret);
-		goto err;
+		return ret;
 	}
 
-	ret = watchdog_register_device(&driver_data->wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &driver_data->wdt);
 	if (ret != 0) {
 		dev_err(da9052->dev, "watchdog_register_device() failed: %d\n",
 			ret);
-		goto err;
+		return ret;
 	}
 
-	platform_set_drvdata(pdev, driver_data);
-err:
 	return ret;
 }
 
-static int da9052_wdt_remove(struct platform_device *pdev)
-{
-	struct da9052_wdt_data *driver_data = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&driver_data->wdt);
-
-	return 0;
-}
-
 static struct platform_driver da9052_wdt_driver = {
 	.probe = da9052_wdt_probe,
-	.remove = da9052_wdt_remove,
 	.driver = {
 		.name	= "da9052-watchdog",
 	},
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 12/62] watchdog: da9055_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (10 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 11/62] watchdog: da9052_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-17 13:58   ` Adam Thomson
  2017-01-10 23:34 ` [PATCH 13/62] watchdog: da9062_wdt: " Guenter Roeck
                   ` (19 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Support Opensource

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Support Opensource <support.opensource@diasemi.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/da9055_wdt.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/watchdog/da9055_wdt.c b/drivers/watchdog/da9055_wdt.c
index 4f30818cf93f..50bdd1022186 100644
--- a/drivers/watchdog/da9055_wdt.c
+++ b/drivers/watchdog/da9055_wdt.c
@@ -147,32 +147,19 @@ static int da9055_wdt_probe(struct platform_device *pdev)
 	ret = da9055_wdt_stop(da9055_wdt);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Failed to stop watchdog, %d\n", ret);
-		goto err;
+		return ret;
 	}
 
-	platform_set_drvdata(pdev, driver_data);
-
-	ret = watchdog_register_device(&driver_data->wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &driver_data->wdt);
 	if (ret != 0)
 		dev_err(da9055->dev, "watchdog_register_device() failed: %d\n",
 			ret);
 
-err:
 	return ret;
 }
 
-static int da9055_wdt_remove(struct platform_device *pdev)
-{
-	struct da9055_wdt_data *driver_data = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&driver_data->wdt);
-
-	return 0;
-}
-
 static struct platform_driver da9055_wdt_driver = {
 	.probe = da9055_wdt_probe,
-	.remove = da9055_wdt_remove,
 	.driver = {
 		.name	= "da9055-watchdog",
 	},
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 13/62] watchdog: da9062_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (11 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 12/62] watchdog: da9055_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-17 14:17   ` Adam Thomson
  2017-01-10 23:34 ` [PATCH 14/62] watchdog: da9063_wdt: " Guenter Roeck
                   ` (18 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Support Opensource

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop dev_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Support Opensource <support.opensource@diasemi.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/da9062_wdt.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/drivers/watchdog/da9062_wdt.c b/drivers/watchdog/da9062_wdt.c
index a02cee6820a1..9083d3d922b0 100644
--- a/drivers/watchdog/da9062_wdt.c
+++ b/drivers/watchdog/da9062_wdt.c
@@ -220,9 +220,8 @@ static int da9062_wdt_probe(struct platform_device *pdev)
 	wdt->wdtdev.parent = &pdev->dev;
 
 	watchdog_set_drvdata(&wdt->wdtdev, wdt);
-	dev_set_drvdata(&pdev->dev, wdt);
 
-	ret = watchdog_register_device(&wdt->wdtdev);
+	ret = devm_watchdog_register_device(&pdev->dev, &wdt->wdtdev);
 	if (ret < 0) {
 		dev_err(wdt->hw->dev,
 			"watchdog registration failed (%d)\n", ret);
@@ -231,24 +230,11 @@ static int da9062_wdt_probe(struct platform_device *pdev)
 
 	da9062_set_window_start(wdt);
 
-	ret = da9062_wdt_ping(&wdt->wdtdev);
-	if (ret < 0)
-		watchdog_unregister_device(&wdt->wdtdev);
-
-	return ret;
-}
-
-static int da9062_wdt_remove(struct platform_device *pdev)
-{
-	struct da9062_watchdog *wdt = dev_get_drvdata(&pdev->dev);
-
-	watchdog_unregister_device(&wdt->wdtdev);
-	return 0;
+	return da9062_wdt_ping(&wdt->wdtdev);
 }
 
 static struct platform_driver da9062_wdt_driver = {
 	.probe = da9062_wdt_probe,
-	.remove = da9062_wdt_remove,
 	.driver = {
 		.name = "da9062-watchdog",
 		.of_match_table = da9062_compatible_id_table,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 14/62] watchdog: da9063_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (12 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 13/62] watchdog: da9062_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-17 14:19   ` Adam Thomson
  2017-01-10 23:34 ` [PATCH 15/62] watchdog: davinci_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (17 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Support Opensource

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop unused variables
- Drop remove function
- Drop dev_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Support Opensource <support.opensource@diasemi.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/da9063_wdt.c | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c
index 5d6b4e5f7989..4691c5509129 100644
--- a/drivers/watchdog/da9063_wdt.c
+++ b/drivers/watchdog/da9063_wdt.c
@@ -151,7 +151,6 @@ static const struct watchdog_ops da9063_watchdog_ops = {
 
 static int da9063_wdt_probe(struct platform_device *pdev)
 {
-	int ret;
 	struct da9063 *da9063;
 	struct da9063_watchdog *wdt;
 
@@ -181,27 +180,12 @@ static int da9063_wdt_probe(struct platform_device *pdev)
 	watchdog_set_restart_priority(&wdt->wdtdev, 128);
 
 	watchdog_set_drvdata(&wdt->wdtdev, wdt);
-	dev_set_drvdata(&pdev->dev, wdt);
-
-	ret = watchdog_register_device(&wdt->wdtdev);
-	if (ret)
-		return ret;
-
-	return 0;
-}
-
-static int da9063_wdt_remove(struct platform_device *pdev)
-{
-	struct da9063_watchdog *wdt = dev_get_drvdata(&pdev->dev);
-
-	watchdog_unregister_device(&wdt->wdtdev);
 
-	return 0;
+	return devm_watchdog_register_device(&pdev->dev, &wdt->wdtdev);
 }
 
 static struct platform_driver da9063_wdt_driver = {
 	.probe = da9063_wdt_probe,
-	.remove = da9063_wdt_remove,
 	.driver = {
 		.name = DA9063_DRVNAME_WATCHDOG,
 	},
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 15/62] watchdog: davinci_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (13 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 14/62] watchdog: da9063_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 16/62] watchdog: digicolor_wdt: " Guenter Roeck
                   ` (16 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Check return value from clk_prepare_enable()
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/davinci_wdt.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/watchdog/davinci_wdt.c b/drivers/watchdog/davinci_wdt.c
index 0e731d797a2a..98427a30fb17 100644
--- a/drivers/watchdog/davinci_wdt.c
+++ b/drivers/watchdog/davinci_wdt.c
@@ -169,13 +169,18 @@ static int davinci_wdt_probe(struct platform_device *pdev)
 
 	if (IS_ERR(davinci_wdt->clk)) {
 		if (PTR_ERR(davinci_wdt->clk) != -EPROBE_DEFER)
-			dev_err(&pdev->dev, "failed to get clock node\n");
+			dev_err(dev, "failed to get clock node\n");
 		return PTR_ERR(davinci_wdt->clk);
 	}
 
-	clk_prepare_enable(davinci_wdt->clk);
-
-	platform_set_drvdata(pdev, davinci_wdt);
+	ret = clk_prepare_enable(davinci_wdt->clk);
+	if (ret)
+		return ret;
+	ret = devm_add_action_or_reset(dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       davinci_wdt->clk);
+	if (ret)
+		return ret;
 
 	wdd			= &davinci_wdt->wdd;
 	wdd->info		= &davinci_wdt_info;
@@ -183,7 +188,7 @@ static int davinci_wdt_probe(struct platform_device *pdev)
 	wdd->min_timeout	= 1;
 	wdd->max_timeout	= MAX_HEARTBEAT;
 	wdd->timeout		= DEFAULT_HEARTBEAT;
-	wdd->parent		= &pdev->dev;
+	wdd->parent		= dev;
 
 	watchdog_init_timeout(wdd, heartbeat, dev);
 
@@ -197,23 +202,13 @@ static int davinci_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(davinci_wdt->base))
 		return PTR_ERR(davinci_wdt->base);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(dev, wdd);
 	if (ret < 0)
 		dev_err(dev, "cannot register watchdog device\n");
 
 	return ret;
 }
 
-static int davinci_wdt_remove(struct platform_device *pdev)
-{
-	struct davinci_wdt_device *davinci_wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&davinci_wdt->wdd);
-	clk_disable_unprepare(davinci_wdt->clk);
-
-	return 0;
-}
-
 static const struct of_device_id davinci_wdt_of_match[] = {
 	{ .compatible = "ti,davinci-wdt", },
 	{},
@@ -226,7 +221,6 @@ static struct platform_driver platform_wdt_driver = {
 		.of_match_table = davinci_wdt_of_match,
 	},
 	.probe = davinci_wdt_probe,
-	.remove = davinci_wdt_remove,
 };
 
 module_platform_driver(platform_wdt_driver);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 16/62] watchdog: digicolor_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (14 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 15/62] watchdog: davinci_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-12 11:47   ` Baruch Siach
  2017-01-10 23:34 ` [PATCH 17/62] watchdog: dw_wdt: Convert to use device managed functions Guenter Roeck
                   ` (15 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Baruch Siach,
	linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Replace of_iomap() with platform_get_resource() followed by
  devm_ioremap_resource()
- Drop platform_set_drvdata()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/digicolor_wdt.c | 48 ++++++++++------------------------------
 1 file changed, 12 insertions(+), 36 deletions(-)

diff --git a/drivers/watchdog/digicolor_wdt.c b/drivers/watchdog/digicolor_wdt.c
index dfe72944822d..870694d9ebc7 100644
--- a/drivers/watchdog/digicolor_wdt.c
+++ b/drivers/watchdog/digicolor_wdt.c
@@ -119,62 +119,40 @@ static struct watchdog_device dc_wdt_wdd = {
 
 static int dc_wdt_probe(struct platform_device *pdev)
 {
+	struct resource *res;
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;
 	struct dc_wdt *wdt;
 	int ret;
 
 	wdt = devm_kzalloc(dev, sizeof(struct dc_wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
-	platform_set_drvdata(pdev, wdt);
 
-	wdt->base = of_iomap(np, 0);
-	if (!wdt->base) {
-		dev_err(dev, "Failed to remap watchdog regs");
-		return -ENODEV;
-	}
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	wdt->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(wdt->base))
+		return PTR_ERR(wdt->base);
 
-	wdt->clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(wdt->clk)) {
-		ret = PTR_ERR(wdt->clk);
-		goto err_iounmap;
-	}
+	wdt->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(wdt->clk))
+		return PTR_ERR(wdt->clk);
 	dc_wdt_wdd.max_timeout = U32_MAX / clk_get_rate(wdt->clk);
 	dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout;
-	dc_wdt_wdd.parent = &pdev->dev;
+	dc_wdt_wdd.parent = dev;
 
 	spin_lock_init(&wdt->lock);
 
 	watchdog_set_drvdata(&dc_wdt_wdd, wdt);
 	watchdog_set_restart_priority(&dc_wdt_wdd, 128);
 	watchdog_init_timeout(&dc_wdt_wdd, timeout, dev);
-	ret = watchdog_register_device(&dc_wdt_wdd);
+	watchdog_stop_on_reboot(&dc_wdt_wdd);
+	ret = devm_watchdog_register_device(dev, &dc_wdt_wdd);
 	if (ret) {
 		dev_err(dev, "Failed to register watchdog device");
-		goto err_iounmap;
+		return ret;
 	}
 
 	return 0;
-
-err_iounmap:
-	iounmap(wdt->base);
-	return ret;
-}
-
-static int dc_wdt_remove(struct platform_device *pdev)
-{
-	struct dc_wdt *wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&dc_wdt_wdd);
-	iounmap(wdt->base);
-
-	return 0;
-}
-
-static void dc_wdt_shutdown(struct platform_device *pdev)
-{
-	dc_wdt_stop(&dc_wdt_wdd);
 }
 
 static const struct of_device_id dc_wdt_of_match[] = {
@@ -185,8 +163,6 @@ MODULE_DEVICE_TABLE(of, dc_wdt_of_match);
 
 static struct platform_driver dc_wdt_driver = {
 	.probe		= dc_wdt_probe,
-	.remove		= dc_wdt_remove,
-	.shutdown	= dc_wdt_shutdown,
 	.driver = {
 		.name =		"digicolor-wdt",
 		.of_match_table = dc_wdt_of_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 17/62] watchdog: dw_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (15 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 16/62] watchdog: digicolor_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 18/62] watchdog: ep93xx_wdt: " Guenter Roeck
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/dw_wdt.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)

diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index 914da3a4d334..4d372fc36385 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -227,12 +227,15 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(dw_wdt->clk);
 	if (ret)
 		return ret;
+	ret = devm_add_action_or_reset(dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       dw_wdt->clk);
+	if (ret)
+		return ret;
 
 	dw_wdt->rate = clk_get_rate(dw_wdt->clk);
-	if (dw_wdt->rate == 0) {
-		ret = -EINVAL;
-		goto out_disable_clk;
-	}
+	if (dw_wdt->rate == 0)
+		return -EINVAL;
 
 	wdd = &dw_wdt->wdd;
 	wdd->info = &dw_wdt_ident;
@@ -263,25 +266,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
 
 	watchdog_set_restart_priority(wdd, 128);
 
-	ret = watchdog_register_device(wdd);
-	if (ret)
-		goto out_disable_clk;
-
-	return 0;
-
-out_disable_clk:
-	clk_disable_unprepare(dw_wdt->clk);
-	return ret;
-}
-
-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);
-	clk_disable_unprepare(dw_wdt->clk);
-
-	return 0;
+	return devm_watchdog_register_device(dev, wdd);
 }
 
 #ifdef CONFIG_OF
@@ -294,7 +279,6 @@ MODULE_DEVICE_TABLE(of, dw_wdt_of_match);
 
 static struct platform_driver dw_wdt_driver = {
 	.probe		= dw_wdt_drv_probe,
-	.remove		= dw_wdt_drv_remove,
 	.driver		= {
 		.name	= "dw_wdt",
 		.of_match_table = of_match_ptr(dw_wdt_of_match),
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 18/62] watchdog: ep93xx_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (16 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 17/62] watchdog: dw_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 19/62] watchdog: gpio_wdt: " Guenter Roeck
                   ` (13 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/ep93xx_wdt.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/watchdog/ep93xx_wdt.c b/drivers/watchdog/ep93xx_wdt.c
index 0a4d7cc05d54..343299e84445 100644
--- a/drivers/watchdog/ep93xx_wdt.c
+++ b/drivers/watchdog/ep93xx_wdt.c
@@ -138,7 +138,7 @@ static int ep93xx_wdt_probe(struct platform_device *pdev)
 
 	setup_timer(&timer, ep93xx_wdt_timer_ping, 1);
 
-	err = watchdog_register_device(&ep93xx_wdt_wdd);
+	err = devm_watchdog_register_device(&pdev->dev, &ep93xx_wdt_wdd);
 	if (err)
 		return err;
 
@@ -149,18 +149,11 @@ static int ep93xx_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int ep93xx_wdt_remove(struct platform_device *pdev)
-{
-	watchdog_unregister_device(&ep93xx_wdt_wdd);
-	return 0;
-}
-
 static struct platform_driver ep93xx_wdt_driver = {
 	.driver		= {
 		.name	= "ep93xx-wdt",
 	},
 	.probe		= ep93xx_wdt_probe,
-	.remove		= ep93xx_wdt_remove,
 };
 
 module_platform_driver(ep93xx_wdt_driver);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 19/62] watchdog: gpio_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (17 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 18/62] watchdog: ep93xx_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 20/62] watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot Guenter Roeck
                   ` (12 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Call del_timer_sync() using devm_add_action()
  Introduce helper function since we can not call del_timer_sync() directly
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/gpio_wdt.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/watchdog/gpio_wdt.c b/drivers/watchdog/gpio_wdt.c
index 93457cabc178..2c09e4d8e6e2 100644
--- a/drivers/watchdog/gpio_wdt.c
+++ b/drivers/watchdog/gpio_wdt.c
@@ -138,6 +138,11 @@ static const struct watchdog_ops gpio_wdt_ops = {
 	.set_timeout	= gpio_wdt_set_timeout,
 };
 
+static void __del_timer_sync_cb(void *t)
+{
+	del_timer_sync(t);
+}
+
 static int gpio_wdt_probe(struct platform_device *pdev)
 {
 	struct gpio_wdt_priv *priv;
@@ -151,8 +156,6 @@ static int gpio_wdt_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, priv);
-
 	priv->gpio = of_get_gpio_flags(pdev->dev.of_node, 0, &flags);
 	if (!gpio_is_valid(priv->gpio))
 		return priv->gpio;
@@ -203,10 +206,13 @@ static int gpio_wdt_probe(struct platform_device *pdev)
 		priv->wdd.timeout = SOFT_TIMEOUT_DEF;
 
 	setup_timer(&priv->timer, gpio_wdt_hwping, (unsigned long)&priv->wdd);
+	ret = devm_add_action(&pdev->dev, __del_timer_sync_cb, &priv->timer);
+	if (ret)
+		return ret;
 
 	watchdog_stop_on_reboot(&priv->wdd);
 
-	ret = watchdog_register_device(&priv->wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, &priv->wdd);
 	if (ret)
 		return ret;
 
@@ -216,16 +222,6 @@ static int gpio_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int gpio_wdt_remove(struct platform_device *pdev)
-{
-	struct gpio_wdt_priv *priv = platform_get_drvdata(pdev);
-
-	del_timer_sync(&priv->timer);
-	watchdog_unregister_device(&priv->wdd);
-
-	return 0;
-}
-
 static const struct of_device_id gpio_wdt_dt_ids[] = {
 	{ .compatible = "linux,wdt-gpio", },
 	{ }
@@ -238,7 +234,6 @@ static struct platform_driver gpio_wdt_driver = {
 		.of_match_table	= gpio_wdt_dt_ids,
 	},
 	.probe	= gpio_wdt_probe,
-	.remove	= gpio_wdt_remove,
 };
 
 #ifdef CONFIG_GPIO_WATCHDOG_ARCH_INITCALL
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 20/62] watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (18 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 19/62] watchdog: gpio_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-11 23:36   ` Andy Shevchenko
  2017-01-10 23:34 ` [PATCH 21/62] watchdog: imgpdc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (11 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

The shutdown function calls the stop function.
Call watchdog_stop_on_reboot() from probe instead.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/iTCO_wdt.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
index d8bb7bf5e669..3d0abc0d59b4 100644
--- a/drivers/watchdog/iTCO_wdt.c
+++ b/drivers/watchdog/iTCO_wdt.c
@@ -520,6 +520,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
 			WATCHDOG_TIMEOUT);
 	}
 
+	watchdog_stop_on_reboot(&p->wddev);
 	ret = devm_watchdog_register_device(dev, &p->wddev);
 	if (ret != 0) {
 		pr_err("cannot register watchdog device (err=%d)\n", ret);
@@ -543,13 +544,6 @@ static int iTCO_wdt_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static void iTCO_wdt_shutdown(struct platform_device *pdev)
-{
-	struct iTCO_wdt_private *p = platform_get_drvdata(pdev);
-
-	iTCO_wdt_stop(&p->wddev);
-}
-
 #ifdef CONFIG_PM_SLEEP
 /*
  * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
@@ -603,7 +597,6 @@ static const struct dev_pm_ops iTCO_wdt_pm = {
 static struct platform_driver iTCO_wdt_driver = {
 	.probe          = iTCO_wdt_probe,
 	.remove         = iTCO_wdt_remove,
-	.shutdown       = iTCO_wdt_shutdown,
 	.driver         = {
 		.name   = DRV_NAME,
 		.pm     = ITCO_WDT_PM_OPS,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 21/62] watchdog: imgpdc_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (19 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 20/62] watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 22/62] watchdog: imx2_wdt: Convert to use device managed functions Guenter Roeck
                   ` (10 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/imgpdc_wdt.c | 42 +++++++++++++++---------------------------
 1 file changed, 15 insertions(+), 27 deletions(-)

diff --git a/drivers/watchdog/imgpdc_wdt.c b/drivers/watchdog/imgpdc_wdt.c
index 6ed39dee995f..883bc27fecbf 100644
--- a/drivers/watchdog/imgpdc_wdt.c
+++ b/drivers/watchdog/imgpdc_wdt.c
@@ -211,25 +211,33 @@ static int pdc_wdt_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "could not prepare or enable sys clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       pdc_wdt->sys_clk);
+	if (ret)
+		return ret;
 
 	ret = clk_prepare_enable(pdc_wdt->wdt_clk);
 	if (ret) {
 		dev_err(&pdev->dev, "could not prepare or enable wdt clock\n");
-		goto disable_sys_clk;
+		return ret;
 	}
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       pdc_wdt->wdt_clk);
+	if (ret)
+		return ret;
 
 	/* We use the clock rate to calculate the max timeout */
 	clk_rate = clk_get_rate(pdc_wdt->wdt_clk);
 	if (clk_rate == 0) {
 		dev_err(&pdev->dev, "failed to get clock rate\n");
-		ret = -EINVAL;
-		goto disable_wdt_clk;
+		return -EINVAL;
 	}
 
 	if (order_base_2(clk_rate) > PDC_WDT_CONFIG_DELAY_MASK + 1) {
 		dev_err(&pdev->dev, "invalid clock rate\n");
-		ret = -EINVAL;
-		goto disable_wdt_clk;
+		return -EINVAL;
 	}
 
 	if (order_base_2(clk_rate) == 0)
@@ -284,24 +292,8 @@ static int pdc_wdt_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, pdc_wdt);
 
-	ret = watchdog_register_device(&pdc_wdt->wdt_dev);
-	if (ret)
-		goto disable_wdt_clk;
-
-	return 0;
-
-disable_wdt_clk:
-	clk_disable_unprepare(pdc_wdt->wdt_clk);
-disable_sys_clk:
-	clk_disable_unprepare(pdc_wdt->sys_clk);
-	return ret;
-}
-
-static void pdc_wdt_shutdown(struct platform_device *pdev)
-{
-	struct pdc_wdt_dev *pdc_wdt = platform_get_drvdata(pdev);
-
-	pdc_wdt_stop(&pdc_wdt->wdt_dev);
+	watchdog_stop_on_reboot(&pdc_wdt->wdt_dev);
+	return devm_watchdog_register_device(&pdev->dev, &pdc_wdt->wdt_dev);
 }
 
 static int pdc_wdt_remove(struct platform_device *pdev)
@@ -309,9 +301,6 @@ static int pdc_wdt_remove(struct platform_device *pdev)
 	struct pdc_wdt_dev *pdc_wdt = platform_get_drvdata(pdev);
 
 	pdc_wdt_stop(&pdc_wdt->wdt_dev);
-	watchdog_unregister_device(&pdc_wdt->wdt_dev);
-	clk_disable_unprepare(pdc_wdt->wdt_clk);
-	clk_disable_unprepare(pdc_wdt->sys_clk);
 
 	return 0;
 }
@@ -329,7 +318,6 @@ static struct platform_driver pdc_wdt_driver = {
 	},
 	.probe = pdc_wdt_probe,
 	.remove = pdc_wdt_remove,
-	.shutdown = pdc_wdt_shutdown,
 };
 module_platform_driver(pdc_wdt_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 22/62] watchdog: imx2_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (20 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 21/62] watchdog: imgpdc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 23/62] watchdog: intel-mid_wdt: " Guenter Roeck
                   ` (9 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/imx2_wdt.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index 4874b0f18650..8993351bc8df 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -287,6 +287,11 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(wdev->clk);
 	if (ret)
 		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       wdev->clk);
+	if (ret)
+		return ret;
 
 	regmap_read(wdev->regmap, IMX2_WDT_WRSR, &val);
 	wdog->bootstatus = val & IMX2_WDT_WRSR_TOUT ? WDIOF_CARDRESET : 0;
@@ -316,20 +321,16 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
 	 */
 	regmap_write(wdev->regmap, IMX2_WDT_WMCR, 0);
 
-	ret = watchdog_register_device(wdog);
+	ret = devm_watchdog_register_device(&pdev->dev, wdog);
 	if (ret) {
 		dev_err(&pdev->dev, "cannot register watchdog device\n");
-		goto disable_clk;
+		return ret;
 	}
 
 	dev_info(&pdev->dev, "timeout %d sec (nowayout=%d)\n",
 		 wdog->timeout, nowayout);
 
 	return 0;
-
-disable_clk:
-	clk_disable_unprepare(wdev->clk);
-	return ret;
 }
 
 static int __exit imx2_wdt_remove(struct platform_device *pdev)
@@ -337,8 +338,6 @@ static int __exit imx2_wdt_remove(struct platform_device *pdev)
 	struct watchdog_device *wdog = platform_get_drvdata(pdev);
 	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
 
-	watchdog_unregister_device(wdog);
-
 	if (imx2_wdt_is_running(wdev)) {
 		imx2_wdt_ping(wdog);
 		dev_crit(&pdev->dev, "Device removed: Expect reboot!\n");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 23/62] watchdog: intel-mid_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (21 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 22/62] watchdog: imx2_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-11 23:36   ` Andy Shevchenko
  2017-01-10 23:34 ` [PATCH 24/62] watchdog: jz4740_wdt: " Guenter Roeck
                   ` (8 subsequent siblings)
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/intel-mid_wdt.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/watchdog/intel-mid_wdt.c b/drivers/watchdog/intel-mid_wdt.c
index a4b729259b12..45e4d02221b5 100644
--- a/drivers/watchdog/intel-mid_wdt.c
+++ b/drivers/watchdog/intel-mid_wdt.c
@@ -137,7 +137,6 @@ static int mid_wdt_probe(struct platform_device *pdev)
 	wdt_dev->parent = &pdev->dev;
 
 	watchdog_set_drvdata(wdt_dev, &pdev->dev);
-	platform_set_drvdata(pdev, wdt_dev);
 
 	ret = devm_request_irq(&pdev->dev, pdata->irq, mid_wdt_irq,
 			       IRQF_SHARED | IRQF_NO_SUSPEND, "watchdog",
@@ -151,7 +150,7 @@ static int mid_wdt_probe(struct platform_device *pdev)
 	/* Make sure the watchdog is not running */
 	wdt_stop(wdt_dev);
 
-	ret = watchdog_register_device(wdt_dev);
+	ret = devm_watchdog_register_device(&pdev->dev, wdt_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "error registering watchdog device\n");
 		return ret;
@@ -162,16 +161,8 @@ static int mid_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int mid_wdt_remove(struct platform_device *pdev)
-{
-	struct watchdog_device *wd = platform_get_drvdata(pdev);
-	watchdog_unregister_device(wd);
-	return 0;
-}
-
 static struct platform_driver mid_wdt_driver = {
 	.probe		= mid_wdt_probe,
-	.remove		= mid_wdt_remove,
 	.driver		= {
 		.name	= "intel_mid_wdt",
 	},
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 24/62] watchdog: jz4740_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (22 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 23/62] watchdog: intel-mid_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 25/62] watchdog: kempld_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (7 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_clk_get() if the device parameter is not NULL
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/jz4740_wdt.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/drivers/watchdog/jz4740_wdt.c b/drivers/watchdog/jz4740_wdt.c
index 20627f22baf6..1d0c85aceaab 100644
--- a/drivers/watchdog/jz4740_wdt.c
+++ b/drivers/watchdog/jz4740_wdt.c
@@ -178,29 +178,21 @@ static int jz4740_wdt_probe(struct platform_device *pdev)
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	drvdata->base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(drvdata->base)) {
-		ret = PTR_ERR(drvdata->base);
-		goto err_out;
-	}
+	if (IS_ERR(drvdata->base))
+		return PTR_ERR(drvdata->base);
 
-	drvdata->rtc_clk = clk_get(&pdev->dev, "rtc");
+	drvdata->rtc_clk = devm_clk_get(&pdev->dev, "rtc");
 	if (IS_ERR(drvdata->rtc_clk)) {
 		dev_err(&pdev->dev, "cannot find RTC clock\n");
-		ret = PTR_ERR(drvdata->rtc_clk);
-		goto err_out;
+		return PTR_ERR(drvdata->rtc_clk);
 	}
 
-	ret = watchdog_register_device(&drvdata->wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &drvdata->wdt);
 	if (ret < 0)
-		goto err_disable_clk;
+		return ret;
 
 	platform_set_drvdata(pdev, drvdata);
 	return 0;
-
-err_disable_clk:
-	clk_put(drvdata->rtc_clk);
-err_out:
-	return ret;
 }
 
 static int jz4740_wdt_remove(struct platform_device *pdev)
@@ -208,8 +200,6 @@ static int jz4740_wdt_remove(struct platform_device *pdev)
 	struct jz4740_wdt_drvdata *drvdata = platform_get_drvdata(pdev);
 
 	jz4740_wdt_stop(&drvdata->wdt);
-	watchdog_unregister_device(&drvdata->wdt);
-	clk_put(drvdata->rtc_clk);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 25/62] watchdog: kempld_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (23 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 24/62] watchdog: jz4740_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 26/62] watchdog: loongson1_wdt: Convert to use device managed functions Guenter Roeck
                   ` (6 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/kempld_wdt.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/watchdog/kempld_wdt.c b/drivers/watchdog/kempld_wdt.c
index 73c46b3a09ab..440b34ba3017 100644
--- a/drivers/watchdog/kempld_wdt.c
+++ b/drivers/watchdog/kempld_wdt.c
@@ -490,7 +490,8 @@ static int kempld_wdt_probe(struct platform_device *pdev)
 	}
 
 	platform_set_drvdata(pdev, wdt_data);
-	ret = watchdog_register_device(wdd);
+	watchdog_stop_on_reboot(wdd);
+	ret = devm_watchdog_register_device(dev, wdd);
 	if (ret)
 		return ret;
 
@@ -499,13 +500,6 @@ static int kempld_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void kempld_wdt_shutdown(struct platform_device *pdev)
-{
-	struct kempld_wdt_data *wdt_data = platform_get_drvdata(pdev);
-
-	kempld_wdt_stop(&wdt_data->wdd);
-}
-
 static int kempld_wdt_remove(struct platform_device *pdev)
 {
 	struct kempld_wdt_data *wdt_data = platform_get_drvdata(pdev);
@@ -514,7 +508,6 @@ static int kempld_wdt_remove(struct platform_device *pdev)
 
 	if (!nowayout)
 		ret = kempld_wdt_stop(wdd);
-	watchdog_unregister_device(wdd);
 
 	return ret;
 }
@@ -566,7 +559,6 @@ static struct platform_driver kempld_wdt_driver = {
 	},
 	.probe		= kempld_wdt_probe,
 	.remove		= kempld_wdt_remove,
-	.shutdown	= kempld_wdt_shutdown,
 	.suspend	= kempld_wdt_suspend,
 	.resume		= kempld_wdt_resume,
 };
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 26/62] watchdog: loongson1_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (24 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 25/62] watchdog: kempld_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 27/62] watchdog: lpc18xx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (5 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Keguang Zhang, linux-mips

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Keguang Zhang <keguang.zhang@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/loongson1_wdt.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/drivers/watchdog/loongson1_wdt.c b/drivers/watchdog/loongson1_wdt.c
index 3aee50c64a36..36f0c7e02745 100644
--- a/drivers/watchdog/loongson1_wdt.c
+++ b/drivers/watchdog/loongson1_wdt.c
@@ -109,12 +109,15 @@ static int ls1x_wdt_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "clk enable failed\n");
 		return err;
 	}
+	err = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       drvdata->clk);
+	if (err)
+		return err;
 
 	clk_rate = clk_get_rate(drvdata->clk);
-	if (!clk_rate) {
-		err = -EINVAL;
-		goto err0;
-	}
+	if (!clk_rate)
+		return -EINVAL;
 	drvdata->clk_rate = clk_rate;
 
 	ls1x_wdt = &drvdata->wdt;
@@ -129,35 +132,19 @@ static int ls1x_wdt_probe(struct platform_device *pdev)
 	watchdog_set_nowayout(ls1x_wdt, nowayout);
 	watchdog_set_drvdata(ls1x_wdt, drvdata);
 
-	err = watchdog_register_device(&drvdata->wdt);
+	err = devm_watchdog_register_device(&pdev->dev, &drvdata->wdt);
 	if (err) {
 		dev_err(&pdev->dev, "failed to register watchdog device\n");
-		goto err0;
+		return err;
 	}
 
-	platform_set_drvdata(pdev, drvdata);
-
 	dev_info(&pdev->dev, "Loongson1 Watchdog driver registered\n");
 
 	return 0;
-err0:
-	clk_disable_unprepare(drvdata->clk);
-	return err;
-}
-
-static int ls1x_wdt_remove(struct platform_device *pdev)
-{
-	struct ls1x_wdt_drvdata *drvdata = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&drvdata->wdt);
-	clk_disable_unprepare(drvdata->clk);
-
-	return 0;
 }
 
 static struct platform_driver ls1x_wdt_driver = {
 	.probe = ls1x_wdt_probe,
-	.remove = ls1x_wdt_remove,
 	.driver = {
 		.name = "ls1x-wdt",
 	},
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 27/62] watchdog: lpc18xx_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (25 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 26/62] watchdog: loongson1_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 28/62] watchdog: max63xx_wdt: Convert to use device managed functions Guenter Roeck
                   ` (4 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Joachim Eastwood,
	linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Call del_timer() using devm_add_action()
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Joachim Eastwood <manabian@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/lpc18xx_wdt.c | 58 ++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 39 deletions(-)

diff --git a/drivers/watchdog/lpc18xx_wdt.c b/drivers/watchdog/lpc18xx_wdt.c
index 3b8bb59adf02..554030628caa 100644
--- a/drivers/watchdog/lpc18xx_wdt.c
+++ b/drivers/watchdog/lpc18xx_wdt.c
@@ -231,19 +231,28 @@ static int lpc18xx_wdt_probe(struct platform_device *pdev)
 		dev_err(dev, "could not prepare or enable sys clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       lpc18xx_wdt->reg_clk);
+	if (ret)
+		return ret;
 
 	ret = clk_prepare_enable(lpc18xx_wdt->wdt_clk);
 	if (ret) {
 		dev_err(dev, "could not prepare or enable wdt clock\n");
-		goto disable_reg_clk;
+		return ret;
 	}
+	ret = devm_add_action_or_reset(dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       lpc18xx_wdt->wdt_clk);
+	if (ret)
+		return ret;
 
 	/* We use the clock rate to calculate timeouts */
 	lpc18xx_wdt->clk_rate = clk_get_rate(lpc18xx_wdt->wdt_clk);
 	if (lpc18xx_wdt->clk_rate == 0) {
 		dev_err(dev, "failed to get clock rate\n");
-		ret = -EINVAL;
-		goto disable_wdt_clk;
+		return -EINVAL;
 	}
 
 	lpc18xx_wdt->wdt_dev.info = &lpc18xx_wdt_info;
@@ -269,44 +278,17 @@ static int lpc18xx_wdt_probe(struct platform_device *pdev)
 
 	setup_timer(&lpc18xx_wdt->timer, lpc18xx_wdt_timer_feed,
 		    (unsigned long)&lpc18xx_wdt->wdt_dev);
+	ret = devm_add_action(dev, (void(*)(void *))del_timer,
+			       &lpc18xx_wdt->timer);
+	if (ret)
+		return ret;
 
 	watchdog_set_nowayout(&lpc18xx_wdt->wdt_dev, nowayout);
 	watchdog_set_restart_priority(&lpc18xx_wdt->wdt_dev, 128);
 
-	platform_set_drvdata(pdev, lpc18xx_wdt);
-
-	ret = watchdog_register_device(&lpc18xx_wdt->wdt_dev);
-	if (ret)
-		goto disable_wdt_clk;
-
-	return 0;
-
-disable_wdt_clk:
-	clk_disable_unprepare(lpc18xx_wdt->wdt_clk);
-disable_reg_clk:
-	clk_disable_unprepare(lpc18xx_wdt->reg_clk);
-	return ret;
-}
-
-static void lpc18xx_wdt_shutdown(struct platform_device *pdev)
-{
-	struct lpc18xx_wdt_dev *lpc18xx_wdt = platform_get_drvdata(pdev);
-
-	lpc18xx_wdt_stop(&lpc18xx_wdt->wdt_dev);
-}
-
-static int lpc18xx_wdt_remove(struct platform_device *pdev)
-{
-	struct lpc18xx_wdt_dev *lpc18xx_wdt = platform_get_drvdata(pdev);
-
-	dev_warn(&pdev->dev, "I quit now, hardware will probably reboot!\n");
-	del_timer(&lpc18xx_wdt->timer);
-
-	watchdog_unregister_device(&lpc18xx_wdt->wdt_dev);
-	clk_disable_unprepare(lpc18xx_wdt->wdt_clk);
-	clk_disable_unprepare(lpc18xx_wdt->reg_clk);
-
-	return 0;
+	watchdog_stop_on_reboot(&lpc18xx_wdt->wdt_dev);
+	return devm_watchdog_register_device(dev,
+					     &lpc18xx_wdt->wdt_dev);
 }
 
 static const struct of_device_id lpc18xx_wdt_match[] = {
@@ -321,8 +303,6 @@ static struct platform_driver lpc18xx_wdt_driver = {
 		.of_match_table	= lpc18xx_wdt_match,
 	},
 	.probe = lpc18xx_wdt_probe,
-	.remove = lpc18xx_wdt_remove,
-	.shutdown = lpc18xx_wdt_shutdown,
 };
 module_platform_driver(lpc18xx_wdt_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 28/62] watchdog: max63xx_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (26 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 27/62] watchdog: lpc18xx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 29/62] watchdog: max77620_wdt: " Guenter Roeck
                   ` (3 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/max63xx_wdt.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/watchdog/max63xx_wdt.c b/drivers/watchdog/max63xx_wdt.c
index ac5840d9689a..140897ca1fe5 100644
--- a/drivers/watchdog/max63xx_wdt.c
+++ b/drivers/watchdog/max63xx_wdt.c
@@ -225,7 +225,6 @@ static int max63xx_wdt_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
-	platform_set_drvdata(pdev, &wdt->wdd);
 	watchdog_set_drvdata(&wdt->wdd, wdt);
 
 	wdt->wdd.parent = &pdev->dev;
@@ -235,7 +234,7 @@ static int max63xx_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_nowayout(&wdt->wdd, nowayout);
 
-	err = watchdog_register_device(&wdt->wdd);
+	err = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
 	if (err)
 		return err;
 
@@ -244,14 +243,6 @@ static int max63xx_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int max63xx_wdt_remove(struct platform_device *pdev)
-{
-	struct watchdog_device *wdd = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(wdd);
-	return 0;
-}
-
 static const struct platform_device_id max63xx_id_table[] = {
 	{ "max6369_wdt", (kernel_ulong_t)max6369_table, },
 	{ "max6370_wdt", (kernel_ulong_t)max6369_table, },
@@ -265,7 +256,6 @@ MODULE_DEVICE_TABLE(platform, max63xx_id_table);
 
 static struct platform_driver max63xx_wdt_driver = {
 	.probe		= max63xx_wdt_probe,
-	.remove		= max63xx_wdt_remove,
 	.id_table	= max63xx_id_table,
 	.driver		= {
 		.name	= "max63xx_wdt",
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 29/62] watchdog: max77620_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (27 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 28/62] watchdog: max63xx_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-10 23:34 ` [PATCH 30/62] watchdog: mena21_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (2 subsequent siblings)
  31 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/max77620_wdt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/watchdog/max77620_wdt.c b/drivers/watchdog/max77620_wdt.c
index 68c41fa2be27..fad139a2ebe6 100644
--- a/drivers/watchdog/max77620_wdt.c
+++ b/drivers/watchdog/max77620_wdt.c
@@ -182,7 +182,7 @@ static int max77620_wdt_probe(struct platform_device *pdev)
 	watchdog_set_nowayout(wdt_dev, nowayout);
 	watchdog_set_drvdata(wdt_dev, wdt);
 
-	ret = watchdog_register_device(wdt_dev);
+	ret = devm_watchdog_register_device(&pdev->dev, wdt_dev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "watchdog registration failed: %d\n", ret);
 		return ret;
@@ -196,7 +196,6 @@ static int max77620_wdt_remove(struct platform_device *pdev)
 	struct max77620_wdt *wdt = platform_get_drvdata(pdev);
 
 	max77620_wdt_stop(&wdt->wdt_dev);
-	watchdog_unregister_device(&wdt->wdt_dev);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 30/62] watchdog: mena21_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (28 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 29/62] watchdog: max77620_wdt: " Guenter Roeck
@ 2017-01-10 23:34 ` Guenter Roeck
  2017-01-13  8:08   ` Johannes Thumshirn
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
  31 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-10 23:34 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Johannes Thumshirn

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop unnecessary mutex_destroy() on allocated data
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Johannes Thumshirn <morbidrsa@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/mena21_wdt.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c
index af6a7c489f08..045201a6fdb3 100644
--- a/drivers/watchdog/mena21_wdt.c
+++ b/drivers/watchdog/mena21_wdt.c
@@ -212,34 +212,15 @@ static int a21_wdt_probe(struct platform_device *pdev)
 	drv->wdt = a21_wdt;
 	dev_set_drvdata(&pdev->dev, drv);
 
-	ret = watchdog_register_device(&a21_wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &a21_wdt);
 	if (ret) {
 		dev_err(&pdev->dev, "Cannot register watchdog device\n");
-		goto err_register_wd;
+		return ret;
 	}
 
 	dev_info(&pdev->dev, "MEN A21 watchdog timer driver enabled\n");
 
 	return 0;
-
-err_register_wd:
-	mutex_destroy(&drv->lock);
-
-	return ret;
-}
-
-static int a21_wdt_remove(struct platform_device *pdev)
-{
-	struct a21_wdt_drv *drv = dev_get_drvdata(&pdev->dev);
-
-	dev_warn(&pdev->dev,
-		"Unregistering A21 watchdog driver, board may reboot\n");
-
-	watchdog_unregister_device(&drv->wdt);
-
-	mutex_destroy(&drv->lock);
-
-	return 0;
 }
 
 static void a21_wdt_shutdown(struct platform_device *pdev)
@@ -257,7 +238,6 @@ MODULE_DEVICE_TABLE(of, a21_wdt_ids);
 
 static struct platform_driver a21_wdt_driver = {
 	.probe = a21_wdt_probe,
-	.remove = a21_wdt_remove,
 	.shutdown = a21_wdt_shutdown,
 	.driver = {
 		.name = "a21-watchdog",
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (29 preceding siblings ...)
  2017-01-10 23:34 ` [PATCH 30/62] watchdog: mena21_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  0:44 ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                     ` (19 more replies)
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
  31 siblings, 20 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Andreas Werner

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Andreas Werner <andreas.werner@men.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/menf21bmc_wdt.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/watchdog/menf21bmc_wdt.c b/drivers/watchdog/menf21bmc_wdt.c
index 3aefddebb386..8d0f60ee7a7c 100644
--- a/drivers/watchdog/menf21bmc_wdt.c
+++ b/drivers/watchdog/menf21bmc_wdt.c
@@ -155,7 +155,7 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = watchdog_register_device(&drv_data->wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &drv_data->wdt);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register Watchdog device\n");
 		return ret;
@@ -166,18 +166,6 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int menf21bmc_wdt_remove(struct platform_device *pdev)
-{
-	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
-
-	dev_warn(&pdev->dev,
-		 "Unregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
-
-	watchdog_unregister_device(&drv_data->wdt);
-
-	return 0;
-}
-
 static void menf21bmc_wdt_shutdown(struct platform_device *pdev)
 {
 	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
@@ -191,7 +179,6 @@ static struct  platform_driver menf21bmc_wdt = {
 		.name	= DEVNAME,
 	},
 	.probe		= menf21bmc_wdt_probe,
-	.remove		= menf21bmc_wdt_remove,
 	.shutdown	= menf21bmc_wdt_shutdown,
 };
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  8:42     ` Neil Armstrong
  2017-01-11 18:44     ` Kevin Hilman
  2017-01-11  0:44   ` [PATCH 33/62] watchdog: meson_wdt: " Guenter Roeck
                     ` (18 subsequent siblings)
  19 siblings, 2 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Carlo Caione,
	Kevin Hilman, linux-amlogic, linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Check return value from clk_prepare_enable()
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Carlo Caione <carlo@caione.org>
Cc: Kevin Hilman <khilman@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/meson_gxbb_wdt.c | 38 ++++++++++----------------------------
 1 file changed, 10 insertions(+), 28 deletions(-)

diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c
index 45d47664a00a..913d8a644460 100644
--- a/drivers/watchdog/meson_gxbb_wdt.c
+++ b/drivers/watchdog/meson_gxbb_wdt.c
@@ -203,7 +203,14 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(data->clk))
 		return PTR_ERR(data->clk);
 
-	clk_prepare_enable(data->clk);
+	ret = clk_prepare_enable(data->clk);
+	if (ret)
+		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       data->clk);
+	if (ret)
+		return ret;
 
 	platform_set_drvdata(pdev, data);
 
@@ -224,37 +231,12 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
 
 	meson_gxbb_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout);
 
-	ret = watchdog_register_device(&data->wdt_dev);
-	if (ret) {
-		clk_disable_unprepare(data->clk);
-		return ret;
-	}
-
-	return 0;
-}
-
-static int meson_gxbb_wdt_remove(struct platform_device *pdev)
-{
-	struct meson_gxbb_wdt *data = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&data->wdt_dev);
-
-	clk_disable_unprepare(data->clk);
-
-	return 0;
-}
-
-static void meson_gxbb_wdt_shutdown(struct platform_device *pdev)
-{
-	struct meson_gxbb_wdt *data = platform_get_drvdata(pdev);
-
-	meson_gxbb_wdt_stop(&data->wdt_dev);
+	watchdog_stop_on_reboot(&data->wdt_dev);
+	return devm_watchdog_register_device(&pdev->dev, &data->wdt_dev);
 }
 
 static struct platform_driver meson_gxbb_wdt_driver = {
 	.probe	= meson_gxbb_wdt_probe,
-	.remove	= meson_gxbb_wdt_remove,
-	.shutdown = meson_gxbb_wdt_shutdown,
 	.driver = {
 		.name = "meson-gxbb-wdt",
 		.pm = &meson_gxbb_wdt_pm_ops,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 33/62] watchdog: meson_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
  2017-01-11  0:44   ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11 18:45     ` Kevin Hilman
  2017-01-11  0:44   ` [PATCH 34/62] watchdog: moxart_wdt: Convert to use device managed functions Guenter Roeck
                     ` (17 subsequent siblings)
  19 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Carlo Caione,
	Kevin Hilman, linux-amlogic, linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Carlo Caione <carlo@caione.org>
Cc: Kevin Hilman <khilman@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/meson_wdt.c | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)

diff --git a/drivers/watchdog/meson_wdt.c b/drivers/watchdog/meson_wdt.c
index 56ea1caf71c3..491b9bf13d84 100644
--- a/drivers/watchdog/meson_wdt.c
+++ b/drivers/watchdog/meson_wdt.c
@@ -201,38 +201,19 @@ static int meson_wdt_probe(struct platform_device *pdev)
 
 	meson_wdt_stop(&meson_wdt->wdt_dev);
 
-	err = watchdog_register_device(&meson_wdt->wdt_dev);
+	watchdog_stop_on_reboot(&meson_wdt->wdt_dev);
+	err = devm_watchdog_register_device(&pdev->dev, &meson_wdt->wdt_dev);
 	if (err)
 		return err;
 
-	platform_set_drvdata(pdev, meson_wdt);
-
 	dev_info(&pdev->dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)",
 		 meson_wdt->wdt_dev.timeout, nowayout);
 
 	return 0;
 }
 
-static int meson_wdt_remove(struct platform_device *pdev)
-{
-	struct meson_wdt_dev *meson_wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&meson_wdt->wdt_dev);
-
-	return 0;
-}
-
-static void meson_wdt_shutdown(struct platform_device *pdev)
-{
-	struct meson_wdt_dev *meson_wdt = platform_get_drvdata(pdev);
-
-	meson_wdt_stop(&meson_wdt->wdt_dev);
-}
-
 static struct platform_driver meson_wdt_driver = {
 	.probe		= meson_wdt_probe,
-	.remove		= meson_wdt_remove,
-	.shutdown	= meson_wdt_shutdown,
 	.driver		= {
 		.name		= DRV_NAME,
 		.of_match_table	= meson_wdt_dt_ids,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 34/62] watchdog: moxart_wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
  2017-01-11  0:44   ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck
  2017-01-11  0:44   ` [PATCH 33/62] watchdog: meson_wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 35/62] watchdog: mpc8xxx_wdt: " Guenter Roeck
                     ` (16 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)'
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/moxart_wdt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/moxart_wdt.c b/drivers/watchdog/moxart_wdt.c
index 2c4a73d1e214..4e91c326e316 100644
--- a/drivers/watchdog/moxart_wdt.c
+++ b/drivers/watchdog/moxart_wdt.c
@@ -90,7 +90,6 @@ static int moxart_wdt_probe(struct platform_device *pdev)
 {
 	struct moxart_wdt_dev *moxart_wdt;
 	struct device *dev = &pdev->dev;
-	struct device_node *node = dev->of_node;
 	struct resource *res;
 	struct clk *clk;
 	int err;
@@ -108,7 +107,7 @@ static int moxart_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(moxart_wdt->base))
 		return PTR_ERR(moxart_wdt->base);
 
-	clk = of_clk_get(node, 0);
+	clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(clk)) {
 		pr_err("%s: of_clk_get failed\n", __func__);
 		return PTR_ERR(clk);
@@ -135,7 +134,7 @@ static int moxart_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_drvdata(&moxart_wdt->dev, moxart_wdt);
 
-	err = watchdog_register_device(&moxart_wdt->dev);
+	err = devm_watchdog_register_device(dev, &moxart_wdt->dev);
 	if (err)
 		return err;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 35/62] watchdog: mpc8xxx_wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (2 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 34/62] watchdog: moxart_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 36/62] watchdog: mt7621_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                     ` (15 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Call del_timer_sync() using devm_add_action()
  Introduce helper function since we can not call del_timer_sync() directly
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/mpc8xxx_wdt.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index 366e5c7e650b..262803fa413b 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -140,6 +140,11 @@ static struct watchdog_ops mpc8xxx_wdt_ops = {
 	.stop = mpc8xxx_wdt_stop,
 };
 
+static void __del_timer_sync_cb(void *t)
+{
+	del_timer_sync(t);
+}
+
 static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
 {
 	int ret;
@@ -175,6 +180,10 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
 	spin_lock_init(&ddata->lock);
 	setup_timer(&ddata->timer, mpc8xxx_wdt_timer_ping,
 		    (unsigned long)ddata);
+	ret = devm_add_action(&ofdev->dev, __del_timer_sync_cb,
+			       &ddata->timer);
+	if (ret)
+		return ret;
 
 	ddata->wdd.info = &mpc8xxx_wdt_info,
 	ddata->wdd.ops = &mpc8xxx_wdt_ops,
@@ -186,7 +195,7 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
 
 	watchdog_set_nowayout(&ddata->wdd, nowayout);
 
-	ret = watchdog_register_device(&ddata->wdd);
+	ret = devm_watchdog_register_device(&ofdev->dev, &ddata->wdd);
 	if (ret) {
 		pr_err("cannot register watchdog device (err=%d)\n", ret);
 		return ret;
@@ -203,19 +212,6 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
 	if (enabled)
 		mod_timer(&ddata->timer, jiffies);
 
-	platform_set_drvdata(ofdev, ddata);
-	return 0;
-}
-
-static int mpc8xxx_wdt_remove(struct platform_device *ofdev)
-{
-	struct mpc8xxx_wdt_ddata *ddata = platform_get_drvdata(ofdev);
-
-	pr_crit("Watchdog removed, expect the %s soon!\n",
-		reset ? "reset" : "machine check exception");
-	del_timer_sync(&ddata->timer);
-	watchdog_unregister_device(&ddata->wdd);
-
 	return 0;
 }
 
@@ -246,7 +242,6 @@ MODULE_DEVICE_TABLE(of, mpc8xxx_wdt_match);
 
 static struct platform_driver mpc8xxx_wdt_driver = {
 	.probe		= mpc8xxx_wdt_probe,
-	.remove		= mpc8xxx_wdt_remove,
 	.driver = {
 		.name = "mpc8xxx_wdt",
 		.of_match_table = mpc8xxx_wdt_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 36/62] watchdog: mt7621_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (3 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 35/62] watchdog: mpc8xxx_wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 37/62] watchdog: mtk_wdt: " Guenter Roeck
                     ` (14 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Matthias Brugger

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Matthias Brugger <matthias.bgg@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/mt7621_wdt.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/watchdog/mt7621_wdt.c b/drivers/watchdog/mt7621_wdt.c
index 2fb5a3085521..ba4a4e1a68e2 100644
--- a/drivers/watchdog/mt7621_wdt.c
+++ b/drivers/watchdog/mt7621_wdt.c
@@ -145,23 +145,12 @@ static int mt7621_wdt_probe(struct platform_device *pdev)
 			      &pdev->dev);
 	watchdog_set_nowayout(&mt7621_wdt_dev, nowayout);
 
-	ret = watchdog_register_device(&mt7621_wdt_dev);
+	watchdog_stop_on_reboot(&mt7621_wdt_dev);
+	ret = devm_watchdog_register_device(&pdev->dev, &mt7621_wdt_dev);
 
 	return 0;
 }
 
-static int mt7621_wdt_remove(struct platform_device *pdev)
-{
-	watchdog_unregister_device(&mt7621_wdt_dev);
-
-	return 0;
-}
-
-static void mt7621_wdt_shutdown(struct platform_device *pdev)
-{
-	mt7621_wdt_stop(&mt7621_wdt_dev);
-}
-
 static const struct of_device_id mt7621_wdt_match[] = {
 	{ .compatible = "mediatek,mt7621-wdt" },
 	{},
@@ -170,8 +159,6 @@ MODULE_DEVICE_TABLE(of, mt7621_wdt_match);
 
 static struct platform_driver mt7621_wdt_driver = {
 	.probe		= mt7621_wdt_probe,
-	.remove		= mt7621_wdt_remove,
-	.shutdown	= mt7621_wdt_shutdown,
 	.driver		= {
 		.name		= KBUILD_MODNAME,
 		.of_match_table	= mt7621_wdt_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 37/62] watchdog: mtk_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (4 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 36/62] watchdog: mt7621_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 38/62] watchdog: nic7018_wdt: Convert to use device managed functions Guenter Roeck
                     ` (13 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Matthias Brugger,
	linux-arm-kernel, linux-mediatek

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Matthias Brugger <matthias.bgg@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/mtk_wdt.c | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)

diff --git a/drivers/watchdog/mtk_wdt.c b/drivers/watchdog/mtk_wdt.c
index 7ed417a765c7..db2e70ed368b 100644
--- a/drivers/watchdog/mtk_wdt.c
+++ b/drivers/watchdog/mtk_wdt.c
@@ -192,7 +192,8 @@ static int mtk_wdt_probe(struct platform_device *pdev)
 
 	mtk_wdt_stop(&mtk_wdt->wdt_dev);
 
-	err = watchdog_register_device(&mtk_wdt->wdt_dev);
+	watchdog_stop_on_reboot(&mtk_wdt->wdt_dev);
+	err = devm_watchdog_register_device(&pdev->dev, &mtk_wdt->wdt_dev);
 	if (unlikely(err))
 		return err;
 
@@ -202,23 +203,6 @@ static int mtk_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void mtk_wdt_shutdown(struct platform_device *pdev)
-{
-	struct mtk_wdt_dev *mtk_wdt = platform_get_drvdata(pdev);
-
-	if (watchdog_active(&mtk_wdt->wdt_dev))
-		mtk_wdt_stop(&mtk_wdt->wdt_dev);
-}
-
-static int mtk_wdt_remove(struct platform_device *pdev)
-{
-	struct mtk_wdt_dev *mtk_wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&mtk_wdt->wdt_dev);
-
-	return 0;
-}
-
 #ifdef CONFIG_PM_SLEEP
 static int mtk_wdt_suspend(struct device *dev)
 {
@@ -256,8 +240,6 @@ static const struct dev_pm_ops mtk_wdt_pm_ops = {
 
 static struct platform_driver mtk_wdt_driver = {
 	.probe		= mtk_wdt_probe,
-	.remove		= mtk_wdt_remove,
-	.shutdown	= mtk_wdt_shutdown,
 	.driver		= {
 		.name		= DRV_NAME,
 		.pm		= &mtk_wdt_pm_ops,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 38/62] watchdog: nic7018_wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (5 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 37/62] watchdog: mtk_wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 39/62] watchdog: of_xilinx_wdt: " Guenter Roeck
                     ` (12 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/nic7018_wdt.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/watchdog/nic7018_wdt.c b/drivers/watchdog/nic7018_wdt.c
index dcd265685837..27b7c7737149 100644
--- a/drivers/watchdog/nic7018_wdt.c
+++ b/drivers/watchdog/nic7018_wdt.c
@@ -219,7 +219,7 @@ static int nic7018_probe(struct platform_device *pdev)
 	/* Unlock WDT register */
 	outb(UNLOCK, wdt->io_base + WDT_REG_LOCK);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(dev, wdd);
 	if (ret) {
 		outb(LOCK, wdt->io_base + WDT_REG_LOCK);
 		dev_err(dev, "failed to register watchdog\n");
@@ -235,8 +235,6 @@ static int nic7018_remove(struct platform_device *pdev)
 {
 	struct nic7018_wdt *wdt = platform_get_drvdata(pdev);
 
-	watchdog_unregister_device(&wdt->wdd);
-
 	/* Lock WDT register */
 	outb(LOCK, wdt->io_base + WDT_REG_LOCK);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 39/62] watchdog: of_xilinx_wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (6 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 38/62] watchdog: nic7018_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 40/62] watchdog: omap_wdt: " Guenter Roeck
                     ` (11 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Michal Simek,
	Sören Brinkmann, linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Michal Simek <michal.simek@xilinx.com>
Cc: "Sören Brinkmann" <soren.brinkmann@xilinx.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/of_xilinx_wdt.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
index fae7fe929ea3..277de711c31f 100644
--- a/drivers/watchdog/of_xilinx_wdt.c
+++ b/drivers/watchdog/of_xilinx_wdt.c
@@ -210,38 +210,27 @@ static int xwdt_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "unable to enable clock\n");
 		return rc;
 	}
+	rc = devm_add_action_or_reset(&pdev->dev,
+				      (void(*)(void *))clk_disable_unprepare,
+				      xdev->clk);
+	if (rc)
+		return rc;
 
 	rc = xwdt_selftest(xdev);
 	if (rc == XWT_TIMER_FAILED) {
 		dev_err(&pdev->dev, "SelfTest routine error\n");
-		goto err_clk_disable;
+		return rc;
 	}
 
-	rc = watchdog_register_device(xilinx_wdt_wdd);
+	rc = devm_watchdog_register_device(&pdev->dev, xilinx_wdt_wdd);
 	if (rc) {
 		dev_err(&pdev->dev, "Cannot register watchdog (err=%d)\n", rc);
-		goto err_clk_disable;
+		return rc;
 	}
 
 	dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
 		 xdev->base, xilinx_wdt_wdd->timeout);
 
-	platform_set_drvdata(pdev, xdev);
-
-	return 0;
-err_clk_disable:
-	clk_disable_unprepare(xdev->clk);
-
-	return rc;
-}
-
-static int xwdt_remove(struct platform_device *pdev)
-{
-	struct xwdt_device *xdev = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&xdev->xilinx_wdt_wdd);
-	clk_disable_unprepare(xdev->clk);
-
 	return 0;
 }
 
@@ -255,7 +244,6 @@ MODULE_DEVICE_TABLE(of, xwdt_of_match);
 
 static struct platform_driver xwdt_driver = {
 	.probe       = xwdt_probe,
-	.remove      = xwdt_remove,
 	.driver = {
 		.name  = WATCHDOG_NAME,
 		.of_match_table = xwdt_of_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 40/62] watchdog: omap_wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (7 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 39/62] watchdog: of_xilinx_wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 41/62] watchdog: orion_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                     ` (10 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/omap_wdt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c
index 1b02bfa81b29..b735d0b04af1 100644
--- a/drivers/watchdog/omap_wdt.c
+++ b/drivers/watchdog/omap_wdt.c
@@ -274,7 +274,7 @@ static int omap_wdt_probe(struct platform_device *pdev)
 	if (!early_enable)
 		omap_wdt_disable(wdev);
 
-	ret = watchdog_register_device(&wdev->wdog);
+	ret = devm_watchdog_register_device(&pdev->dev, &wdev->wdog);
 	if (ret) {
 		pm_runtime_disable(wdev->dev);
 		return ret;
@@ -309,7 +309,6 @@ static int omap_wdt_remove(struct platform_device *pdev)
 	struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
 
 	pm_runtime_disable(wdev->dev);
-	watchdog_unregister_device(&wdev->wdog);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 41/62] watchdog: orion_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (8 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 40/62] watchdog: omap_wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 42/62] watchdog: pic32-dmt: Convert to use device managed functions Guenter Roeck
                     ` (9 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_clk_get() if the device parameter is not NULL
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Replace 'of_clk_get_by_name(np, name)' with 'devm_clk_get(dev, name)'
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/orion_wdt.c | 87 ++++++++++++++++++++------------------------
 1 file changed, 39 insertions(+), 48 deletions(-)

diff --git a/drivers/watchdog/orion_wdt.c b/drivers/watchdog/orion_wdt.c
index 39be4dd8035e..8949c0b7498e 100644
--- a/drivers/watchdog/orion_wdt.c
+++ b/drivers/watchdog/orion_wdt.c
@@ -78,14 +78,17 @@ static int orion_wdt_clock_init(struct platform_device *pdev,
 {
 	int ret;
 
-	dev->clk = clk_get(&pdev->dev, NULL);
+	dev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk))
 		return PTR_ERR(dev->clk);
 	ret = clk_prepare_enable(dev->clk);
-	if (ret) {
-		clk_put(dev->clk);
+	if (ret)
+		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       dev->clk);
+	if (ret)
 		return ret;
-	}
 
 	dev->clk_rate = clk_get_rate(dev->clk);
 	return 0;
@@ -96,14 +99,17 @@ static int armada370_wdt_clock_init(struct platform_device *pdev,
 {
 	int ret;
 
-	dev->clk = clk_get(&pdev->dev, NULL);
+	dev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk))
 		return PTR_ERR(dev->clk);
 	ret = clk_prepare_enable(dev->clk);
-	if (ret) {
-		clk_put(dev->clk);
+	if (ret)
+		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       dev->clk);
+	if (ret)
 		return ret;
-	}
 
 	/* Setup watchdog input clock */
 	atomic_io_modify(dev->reg + TIMER_CTRL,
@@ -119,13 +125,16 @@ static int armada375_wdt_clock_init(struct platform_device *pdev,
 {
 	int ret;
 
-	dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed");
+	dev->clk = devm_clk_get(&pdev->dev, "fixed");
 	if (!IS_ERR(dev->clk)) {
 		ret = clk_prepare_enable(dev->clk);
-		if (ret) {
-			clk_put(dev->clk);
+		if (ret)
+			return ret;
+		ret = devm_add_action_or_reset(&pdev->dev,
+					(void(*)(void *))clk_disable_unprepare,
+					dev->clk);
+		if (ret)
 			return ret;
-		}
 
 		atomic_io_modify(dev->reg + TIMER_CTRL,
 				WDT_AXP_FIXED_ENABLE_BIT,
@@ -136,15 +145,18 @@ static int armada375_wdt_clock_init(struct platform_device *pdev,
 	}
 
 	/* Mandatory fallback for proper devicetree backward compatibility */
-	dev->clk = clk_get(&pdev->dev, NULL);
+	dev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk))
 		return PTR_ERR(dev->clk);
 
 	ret = clk_prepare_enable(dev->clk);
-	if (ret) {
-		clk_put(dev->clk);
+	if (ret)
+		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       dev->clk);
+	if (ret)
 		return ret;
-	}
 
 	atomic_io_modify(dev->reg + TIMER_CTRL,
 			WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT),
@@ -159,14 +171,17 @@ static int armadaxp_wdt_clock_init(struct platform_device *pdev,
 {
 	int ret;
 
-	dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed");
+	dev->clk = devm_clk_get(&pdev->dev, "fixed");
 	if (IS_ERR(dev->clk))
 		return PTR_ERR(dev->clk);
 	ret = clk_prepare_enable(dev->clk);
-	if (ret) {
-		clk_put(dev->clk);
+	if (ret)
+		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       dev->clk);
+	if (ret)
 		return ret;
-	}
 
 	/* Enable the fixed watchdog clock input */
 	atomic_io_modify(dev->reg + TIMER_CTRL,
@@ -570,7 +585,6 @@ static int orion_wdt_probe(struct platform_device *pdev)
 	dev->wdt.parent = &pdev->dev;
 	watchdog_init_timeout(&dev->wdt, heartbeat, &pdev->dev);
 
-	platform_set_drvdata(pdev, &dev->wdt);
 	watchdog_set_drvdata(&dev->wdt, dev);
 
 	/*
@@ -593,46 +607,23 @@ static int orion_wdt_probe(struct platform_device *pdev)
 				       pdev->name, dev);
 		if (ret < 0) {
 			dev_err(&pdev->dev, "failed to request IRQ\n");
-			goto disable_clk;
+			return ret;
 		}
 	}
 
 	watchdog_set_nowayout(&dev->wdt, nowayout);
-	ret = watchdog_register_device(&dev->wdt);
+	watchdog_stop_on_reboot(&dev->wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &dev->wdt);
 	if (ret)
-		goto disable_clk;
+		return ret;
 
 	pr_info("Initial timeout %d sec%s\n",
 		dev->wdt.timeout, nowayout ? ", nowayout" : "");
 	return 0;
-
-disable_clk:
-	clk_disable_unprepare(dev->clk);
-	clk_put(dev->clk);
-	return ret;
-}
-
-static int orion_wdt_remove(struct platform_device *pdev)
-{
-	struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
-	struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
-
-	watchdog_unregister_device(wdt_dev);
-	clk_disable_unprepare(dev->clk);
-	clk_put(dev->clk);
-	return 0;
-}
-
-static void orion_wdt_shutdown(struct platform_device *pdev)
-{
-	struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
-	orion_wdt_stop(wdt_dev);
 }
 
 static struct platform_driver orion_wdt_driver = {
 	.probe		= orion_wdt_probe,
-	.remove		= orion_wdt_remove,
-	.shutdown	= orion_wdt_shutdown,
 	.driver		= {
 		.name	= "orion_wdt",
 		.of_match_table = orion_wdt_of_match_table,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 42/62] watchdog: pic32-dmt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (9 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 41/62] watchdog: orion_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 43/62] watchdog: pic32-wdt: " Guenter Roeck
                     ` (8 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/pic32-dmt.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/watchdog/pic32-dmt.c b/drivers/watchdog/pic32-dmt.c
index c797305f8338..31d635639049 100644
--- a/drivers/watchdog/pic32-dmt.c
+++ b/drivers/watchdog/pic32-dmt.c
@@ -193,13 +193,17 @@ static int pic32_dmt_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(dmt->clk);
 	if (ret)
 		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       dmt->clk);
+	if (ret)
+		return ret;
 
 	wdd->timeout = pic32_dmt_get_timeout_secs(dmt);
 	if (!wdd->timeout) {
 		dev_err(&pdev->dev,
 			"failed to read watchdog register timeout\n");
-		ret = -EINVAL;
-		goto out_disable_clk;
+		return -EINVAL;
 	}
 
 	dev_info(&pdev->dev, "timeout %d\n", wdd->timeout);
@@ -209,28 +213,12 @@ static int pic32_dmt_probe(struct platform_device *pdev)
 	watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT);
 	watchdog_set_drvdata(wdd, dmt);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, wdd);
 	if (ret) {
 		dev_err(&pdev->dev, "watchdog register failed, err %d\n", ret);
-		goto out_disable_clk;
+		return ret;
 	}
 
-	platform_set_drvdata(pdev, wdd);
-	return 0;
-
-out_disable_clk:
-	clk_disable_unprepare(dmt->clk);
-	return ret;
-}
-
-static int pic32_dmt_remove(struct platform_device *pdev)
-{
-	struct watchdog_device *wdd = platform_get_drvdata(pdev);
-	struct pic32_dmt *dmt = watchdog_get_drvdata(wdd);
-
-	watchdog_unregister_device(wdd);
-	clk_disable_unprepare(dmt->clk);
-
 	return 0;
 }
 
@@ -242,7 +230,6 @@ MODULE_DEVICE_TABLE(of, pic32_dmt_of_ids);
 
 static struct platform_driver pic32_dmt_driver = {
 	.probe		= pic32_dmt_probe,
-	.remove		= pic32_dmt_remove,
 	.driver		= {
 		.name		= "pic32-dmt",
 		.of_match_table = of_match_ptr(pic32_dmt_of_ids),
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 43/62] watchdog: pic32-wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (10 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 42/62] watchdog: pic32-dmt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 44/62] watchdog: pnx4008_wdt: " Guenter Roeck
                     ` (7 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/pic32-wdt.c | 34 +++++++++-------------------------
 1 file changed, 9 insertions(+), 25 deletions(-)

diff --git a/drivers/watchdog/pic32-wdt.c b/drivers/watchdog/pic32-wdt.c
index e2761068dc6f..818d868c4f3e 100644
--- a/drivers/watchdog/pic32-wdt.c
+++ b/drivers/watchdog/pic32-wdt.c
@@ -197,19 +197,22 @@ static int pic32_wdt_drv_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "clk enable failed\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       wdt->clk);
+	if (ret)
+		return ret;
 
 	if (pic32_wdt_is_win_enabled(wdt)) {
 		dev_err(&pdev->dev, "windowed-clear mode is not supported.\n");
-		ret = -ENODEV;
-		goto out_disable_clk;
+		return -ENODEV;
 	}
 
 	wdd->timeout = pic32_wdt_get_timeout_secs(wdt, &pdev->dev);
 	if (!wdd->timeout) {
 		dev_err(&pdev->dev,
 			"failed to read watchdog register timeout\n");
-		ret = -EINVAL;
-		goto out_disable_clk;
+		return -EINVAL;
 	}
 
 	dev_info(&pdev->dev, "timeout %d\n", wdd->timeout);
@@ -219,36 +222,17 @@ static int pic32_wdt_drv_probe(struct platform_device *pdev)
 	watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT);
 	watchdog_set_drvdata(wdd, wdt);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, wdd);
 	if (ret) {
 		dev_err(&pdev->dev, "watchdog register failed, err %d\n", ret);
-		goto out_disable_clk;
+		return ret;
 	}
 
-	platform_set_drvdata(pdev, wdd);
-
-	return 0;
-
-out_disable_clk:
-	clk_disable_unprepare(wdt->clk);
-
-	return ret;
-}
-
-static int pic32_wdt_drv_remove(struct platform_device *pdev)
-{
-	struct watchdog_device *wdd = platform_get_drvdata(pdev);
-	struct pic32_wdt *wdt = watchdog_get_drvdata(wdd);
-
-	watchdog_unregister_device(wdd);
-	clk_disable_unprepare(wdt->clk);
-
 	return 0;
 }
 
 static struct platform_driver pic32_wdt_driver = {
 	.probe		= pic32_wdt_drv_probe,
-	.remove		= pic32_wdt_drv_remove,
 	.driver		= {
 		.name		= "pic32-wdt",
 		.of_match_table = of_match_ptr(pic32_wdt_dt_ids),
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 44/62] watchdog: pnx4008_wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (11 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 43/62] watchdog: pic32-wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-12  0:13     ` Vladimir Zapolskiy
  2017-01-11  0:44   ` [PATCH 45/62] watchdog: qcom-wdt: " Guenter Roeck
                     ` (6 subsequent siblings)
  19 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Vladimir Zapolskiy,
	Sylvain Lemieux, linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Vladimir Zapolskiy <vz@mleia.com>
Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/pnx4008_wdt.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/watchdog/pnx4008_wdt.c b/drivers/watchdog/pnx4008_wdt.c
index 0529aed158a4..a0cda8748c9b 100644
--- a/drivers/watchdog/pnx4008_wdt.c
+++ b/drivers/watchdog/pnx4008_wdt.c
@@ -202,6 +202,11 @@ static int pnx4008_wdt_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(wdt_clk);
 	if (ret)
 		return ret;
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       wdt_clk);
+	if (ret)
+		return ret;
 
 	pnx4008_wdd.bootstatus = (readl(WDTIM_RES(wdt_base)) & WDOG_RESET) ?
 			WDIOF_CARDRESET : 0;
@@ -211,28 +216,15 @@ static int pnx4008_wdt_probe(struct platform_device *pdev)
 
 	pnx4008_wdt_stop(&pnx4008_wdd);	/* disable for now */
 
-	ret = watchdog_register_device(&pnx4008_wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, &pnx4008_wdd);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "cannot register watchdog device\n");
-		goto disable_clk;
+		return ret;
 	}
 
 	dev_info(&pdev->dev, "heartbeat %d sec\n", pnx4008_wdd.timeout);
 
 	return 0;
-
-disable_clk:
-	clk_disable_unprepare(wdt_clk);
-	return ret;
-}
-
-static int pnx4008_wdt_remove(struct platform_device *pdev)
-{
-	watchdog_unregister_device(&pnx4008_wdd);
-
-	clk_disable_unprepare(wdt_clk);
-
-	return 0;
 }
 
 #ifdef CONFIG_OF
@@ -249,7 +241,6 @@ static struct platform_driver platform_wdt_driver = {
 		.of_match_table = of_match_ptr(pnx4008_wdt_match),
 	},
 	.probe = pnx4008_wdt_probe,
-	.remove = pnx4008_wdt_remove,
 };
 
 module_platform_driver(platform_wdt_driver);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 45/62] watchdog: qcom-wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (12 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 44/62] watchdog: pnx4008_wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 46/62] watchdog: renesas_wdt: " Guenter Roeck
                     ` (5 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/qcom-wdt.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c
index 4f47b5e90956..e021aaf73b47 100644
--- a/drivers/watchdog/qcom-wdt.c
+++ b/drivers/watchdog/qcom-wdt.c
@@ -185,6 +185,11 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to setup clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       wdt->clk);
+	if (ret)
+		return ret;
 
 	/*
 	 * We use the clock rate to calculate the max timeout, so ensure it's
@@ -198,8 +203,7 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	if (wdt->rate == 0 ||
 	    wdt->rate > 0x10000000U) {
 		dev_err(&pdev->dev, "invalid clock rate\n");
-		ret = -EINVAL;
-		goto err_clk_unprepare;
+		return -EINVAL;
 	}
 
 	wdt->wdd.info = &qcom_wdt_info;
@@ -220,26 +224,12 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
 	watchdog_init_timeout(&wdt->wdd, 0, &pdev->dev);
 
-	ret = watchdog_register_device(&wdt->wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register watchdog\n");
-		goto err_clk_unprepare;
+		return ret;
 	}
 
-	platform_set_drvdata(pdev, wdt);
-	return 0;
-
-err_clk_unprepare:
-	clk_disable_unprepare(wdt->clk);
-	return ret;
-}
-
-static int qcom_wdt_remove(struct platform_device *pdev)
-{
-	struct qcom_wdt *wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&wdt->wdd);
-	clk_disable_unprepare(wdt->clk);
 	return 0;
 }
 
@@ -253,7 +243,6 @@ MODULE_DEVICE_TABLE(of, qcom_wdt_of_table);
 
 static struct platform_driver qcom_watchdog_driver = {
 	.probe	= qcom_wdt_probe,
-	.remove	= qcom_wdt_remove,
 	.driver	= {
 		.name		= KBUILD_MODNAME,
 		.of_match_table	= qcom_wdt_of_table,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 46/62] watchdog: renesas_wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (13 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 45/62] watchdog: qcom-wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 47/62] watchdog: retu_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                     ` (4 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/renesas_wdt.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/watchdog/renesas_wdt.c b/drivers/watchdog/renesas_wdt.c
index cf61c92f7ecd..f11a5c0583be 100644
--- a/drivers/watchdog/renesas_wdt.c
+++ b/drivers/watchdog/renesas_wdt.c
@@ -157,7 +157,6 @@ static int rwdt_probe(struct platform_device *pdev)
 	priv->wdev.max_timeout = 65536 / clks_per_sec;
 	priv->wdev.timeout = min(priv->wdev.max_timeout, RWDT_DEFAULT_TIMEOUT);
 
-	platform_set_drvdata(pdev, priv);
 	watchdog_set_drvdata(&priv->wdev, priv);
 	watchdog_set_nowayout(&priv->wdev, nowayout);
 
@@ -166,7 +165,7 @@ static int rwdt_probe(struct platform_device *pdev)
 	if (ret)
 		dev_warn(&pdev->dev, "Specified timeout value invalid, using default\n");
 
-	ret = watchdog_register_device(&priv->wdev);
+	ret = devm_watchdog_register_device(&pdev->dev, &priv->wdev);
 	if (ret < 0) {
 		pm_runtime_put(&pdev->dev);
 		pm_runtime_disable(&pdev->dev);
@@ -178,9 +177,6 @@ static int rwdt_probe(struct platform_device *pdev)
 
 static int rwdt_remove(struct platform_device *pdev)
 {
-	struct rwdt_priv *priv = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&priv->wdev);
 	pm_runtime_put(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 47/62] watchdog: retu_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (14 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 46/62] watchdog: renesas_wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 48/62] watchdog: rt2880_wdt: " Guenter Roeck
                     ` (3 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Call cancel_delayed_work_sync() using devm_add_action_or_reset()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/retu_wdt.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/watchdog/retu_wdt.c b/drivers/watchdog/retu_wdt.c
index 39cd51df2ffc..deba0e956c9f 100644
--- a/drivers/watchdog/retu_wdt.c
+++ b/drivers/watchdog/retu_wdt.c
@@ -136,8 +136,13 @@ static int retu_wdt_probe(struct platform_device *pdev)
 	wdev->dev		= &pdev->dev;
 
 	INIT_DELAYED_WORK(&wdev->ping_work, retu_wdt_ping_work);
+	ret = devm_add_action_or_reset(&pdev->dev,
+				(void(*)(void *))cancel_delayed_work_sync,
+				&wdev->ping_work);
+	if (ret)
+		return ret;
 
-	ret = watchdog_register_device(retu_wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, retu_wdt);
 	if (ret < 0)
 		return ret;
 
@@ -146,25 +151,11 @@ static int retu_wdt_probe(struct platform_device *pdev)
 	else
 		retu_wdt_ping_enable(wdev);
 
-	platform_set_drvdata(pdev, retu_wdt);
-
-	return 0;
-}
-
-static int retu_wdt_remove(struct platform_device *pdev)
-{
-	struct watchdog_device *wdog = platform_get_drvdata(pdev);
-	struct retu_wdt_dev *wdev = watchdog_get_drvdata(wdog);
-
-	watchdog_unregister_device(wdog);
-	cancel_delayed_work_sync(&wdev->ping_work);
-
 	return 0;
 }
 
 static struct platform_driver retu_wdt_driver = {
 	.probe		= retu_wdt_probe,
-	.remove		= retu_wdt_remove,
 	.driver		= {
 		.name	= "retu-wdt",
 	},
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 48/62] watchdog: rt2880_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (15 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 47/62] watchdog: retu_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 49/62] watchdog: sama5d4_wdt: Convert to use device managed functions Guenter Roeck
                     ` (2 subsequent siblings)
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/rt2880_wdt.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/watchdog/rt2880_wdt.c b/drivers/watchdog/rt2880_wdt.c
index 4c471fe7b854..a364a5f79823 100644
--- a/drivers/watchdog/rt2880_wdt.c
+++ b/drivers/watchdog/rt2880_wdt.c
@@ -166,25 +166,14 @@ static int rt288x_wdt_probe(struct platform_device *pdev)
 			      &pdev->dev);
 	watchdog_set_nowayout(&rt288x_wdt_dev, nowayout);
 
-	ret = watchdog_register_device(&rt288x_wdt_dev);
+	watchdog_stop_on_reboot(&rt288x_wdt_dev);
+	ret = devm_watchdog_register_device(&pdev->dev, &rt288x_wdt_dev);
 	if (!ret)
 		dev_info(&pdev->dev, "Initialized\n");
 
 	return 0;
 }
 
-static int rt288x_wdt_remove(struct platform_device *pdev)
-{
-	watchdog_unregister_device(&rt288x_wdt_dev);
-
-	return 0;
-}
-
-static void rt288x_wdt_shutdown(struct platform_device *pdev)
-{
-	rt288x_wdt_stop(&rt288x_wdt_dev);
-}
-
 static const struct of_device_id rt288x_wdt_match[] = {
 	{ .compatible = "ralink,rt2880-wdt" },
 	{},
@@ -193,8 +182,6 @@ MODULE_DEVICE_TABLE(of, rt288x_wdt_match);
 
 static struct platform_driver rt288x_wdt_driver = {
 	.probe		= rt288x_wdt_probe,
-	.remove		= rt288x_wdt_remove,
-	.shutdown	= rt288x_wdt_shutdown,
 	.driver		= {
 		.name		= KBUILD_MODNAME,
 		.of_match_table	= rt288x_wdt_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 49/62] watchdog: sama5d4_wdt: Convert to use device managed functions
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (16 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 48/62] watchdog: rt2880_wdt: " Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:44   ` [PATCH 50/62] watchdog: sbsa_gwdt: Convert to use device managed functions and other improvements Guenter Roeck
  2017-01-11  0:45   ` [PATCH 51/62] watchdog: shwdt: " Guenter Roeck
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/sama5d4_wdt.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c
index a49634cdc1cc..8bb9d5bd7eab 100644
--- a/drivers/watchdog/sama5d4_wdt.c
+++ b/drivers/watchdog/sama5d4_wdt.c
@@ -234,7 +234,7 @@ static int sama5d4_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_nowayout(wdd, nowayout);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, wdd);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register watchdog device\n");
 		return ret;
@@ -254,8 +254,6 @@ static int sama5d4_wdt_remove(struct platform_device *pdev)
 
 	sama5d4_wdt_stop(&wdt->wdd);
 
-	watchdog_unregister_device(&wdt->wdd);
-
 	return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 50/62] watchdog: sbsa_gwdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (17 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 49/62] watchdog: sama5d4_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  0:44   ` Guenter Roeck
  2017-01-11  0:45   ` [PATCH 51/62] watchdog: shwdt: " Guenter Roeck
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:44 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Replace &pdev->dev with dev if 'struct device *dev' is a declared
  variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/sbsa_gwdt.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
index e9966bc8c23e..2285d1403b44 100644
--- a/drivers/watchdog/sbsa_gwdt.c
+++ b/drivers/watchdog/sbsa_gwdt.c
@@ -312,7 +312,8 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)
 	 */
 	sbsa_gwdt_set_timeout(wdd, wdd->timeout);
 
-	ret = watchdog_register_device(wdd);
+	watchdog_stop_on_reboot(wdd);
+	ret = devm_watchdog_register_device(dev, wdd);
 	if (ret)
 		return ret;
 
@@ -323,22 +324,6 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void sbsa_gwdt_shutdown(struct platform_device *pdev)
-{
-	struct sbsa_gwdt *gwdt = platform_get_drvdata(pdev);
-
-	sbsa_gwdt_stop(&gwdt->wdd);
-}
-
-static int sbsa_gwdt_remove(struct platform_device *pdev)
-{
-	struct sbsa_gwdt *gwdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&gwdt->wdd);
-
-	return 0;
-}
-
 /* Disable watchdog if it is active during suspend */
 static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
 {
@@ -384,8 +369,6 @@ static struct platform_driver sbsa_gwdt_driver = {
 		.of_match_table = sbsa_gwdt_of_match,
 	},
 	.probe = sbsa_gwdt_probe,
-	.remove = sbsa_gwdt_remove,
-	.shutdown = sbsa_gwdt_shutdown,
 	.id_table = sbsa_gwdt_pdev_match,
 };
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 51/62] watchdog: shwdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (18 preceding siblings ...)
  2017-01-11  0:44   ` [PATCH 50/62] watchdog: sbsa_gwdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  0:45   ` Guenter Roeck
  19 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  0:45 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/shwdt.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/watchdog/shwdt.c b/drivers/watchdog/shwdt.c
index 517a733175ef..98cc70bd7821 100644
--- a/drivers/watchdog/shwdt.c
+++ b/drivers/watchdog/shwdt.c
@@ -269,7 +269,8 @@ static int sh_wdt_probe(struct platform_device *pdev)
 	dev_info(&pdev->dev, "configured with heartbeat=%d sec (nowayout=%d)\n",
 		 sh_wdt_dev.timeout, nowayout);
 
-	rc = watchdog_register_device(&sh_wdt_dev);
+	watchdog_stop_on_reboot(&sh_wdt_dev);
+	rc = devm_watchdog_register_device(&pdev->dev, &sh_wdt_dev);
 	if (unlikely(rc)) {
 		dev_err(&pdev->dev, "Can't register watchdog (err=%d)\n", rc);
 		return rc;
@@ -287,18 +288,11 @@ static int sh_wdt_probe(struct platform_device *pdev)
 
 static int sh_wdt_remove(struct platform_device *pdev)
 {
-	watchdog_unregister_device(&sh_wdt_dev);
-
 	pm_runtime_disable(&pdev->dev);
 
 	return 0;
 }
 
-static void sh_wdt_shutdown(struct platform_device *pdev)
-{
-	sh_wdt_stop(&sh_wdt_dev);
-}
-
 static struct platform_driver sh_wdt_driver = {
 	.driver		= {
 		.name	= DRV_NAME,
@@ -306,7 +300,6 @@ static struct platform_driver sh_wdt_driver = {
 
 	.probe		= sh_wdt_probe,
 	.remove		= sh_wdt_remove,
-	.shutdown	= sh_wdt_shutdown,
 };
 
 static int __init sh_wdt_init(void)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 52/62] watchdog: sirfsoc_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
                   ` (30 preceding siblings ...)
  2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  2:09 ` Guenter Roeck
  2017-01-11  2:09   ` [PATCH 53/62] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
                     ` (9 more replies)
  31 siblings, 10 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Barry Song,
	linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Barry Song <baohua@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/sirfsoc_wdt.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/watchdog/sirfsoc_wdt.c b/drivers/watchdog/sirfsoc_wdt.c
index 3050a0031479..fb88e04d18ae 100644
--- a/drivers/watchdog/sirfsoc_wdt.c
+++ b/drivers/watchdog/sirfsoc_wdt.c
@@ -161,7 +161,8 @@ static int sirfsoc_wdt_probe(struct platform_device *pdev)
 	watchdog_set_nowayout(&sirfsoc_wdd, nowayout);
 	sirfsoc_wdd.parent = &pdev->dev;
 
-	ret = watchdog_register_device(&sirfsoc_wdd);
+	watchdog_stop_on_reboot(&sirfsoc_wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, &sirfsoc_wdd);
 	if (ret)
 		return ret;
 
@@ -170,16 +171,9 @@ static int sirfsoc_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void sirfsoc_wdt_shutdown(struct platform_device *pdev)
-{
-	struct watchdog_device *wdd = platform_get_drvdata(pdev);
-
-	sirfsoc_wdt_disable(wdd);
-}
-
 static int sirfsoc_wdt_remove(struct platform_device *pdev)
 {
-	sirfsoc_wdt_shutdown(pdev);
+	sirfsoc_wdt_disable(platform_get_drvdata(pdev));
 	return 0;
 }
 
@@ -221,7 +215,6 @@ static struct platform_driver sirfsoc_wdt_driver = {
 	},
 	.probe = sirfsoc_wdt_probe,
 	.remove = sirfsoc_wdt_remove,
-	.shutdown = sirfsoc_wdt_shutdown,
 };
 module_platform_driver(sirfsoc_wdt_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 53/62] watchdog: st_lpc_wdt: Convert to use device managed functions
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-11  2:09   ` [PATCH 54/62] watchdog: stmp3xxx_rtc_wdt: " Guenter Roeck
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Patrice Chotard,
	kernel, linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/st_lpc_wdt.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/st_lpc_wdt.c b/drivers/watchdog/st_lpc_wdt.c
index e6100e447dd8..d561fbf1df85 100644
--- a/drivers/watchdog/st_lpc_wdt.c
+++ b/drivers/watchdog/st_lpc_wdt.c
@@ -215,6 +215,11 @@ static int st_wdog_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Unable to enable clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       clk);
+	if (ret)
+		return ret;
 
 	watchdog_set_drvdata(&st_wdog_dev, st_wdog);
 	watchdog_set_nowayout(&st_wdog_dev, WATCHDOG_NOWAYOUT);
@@ -223,14 +228,12 @@ static int st_wdog_probe(struct platform_device *pdev)
 	ret = watchdog_init_timeout(&st_wdog_dev, 0, &pdev->dev);
 	if (ret) {
 		dev_err(&pdev->dev, "Unable to initialise watchdog timeout\n");
-		clk_disable_unprepare(clk);
 		return ret;
 	}
 
-	ret = watchdog_register_device(&st_wdog_dev);
+	ret = devm_watchdog_register_device(&pdev->dev, &st_wdog_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "Unable to register watchdog\n");
-		clk_disable_unprepare(clk);
 		return ret;
 	}
 
@@ -247,8 +250,6 @@ static int st_wdog_remove(struct platform_device *pdev)
 	struct st_wdog *st_wdog = watchdog_get_drvdata(&st_wdog_dev);
 
 	st_wdog_setup(st_wdog, false);
-	watchdog_unregister_device(&st_wdog_dev);
-	clk_disable_unprepare(st_wdog->clk);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 54/62] watchdog: stmp3xxx_rtc_wdt: Convert to use device managed functions
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
  2017-01-11  2:09   ` [PATCH 53/62] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-11  2:09   ` [PATCH 55/62] watchdog: sunxi_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                     ` (7 subsequent siblings)
  9 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/stmp3xxx_rtc_wdt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/watchdog/stmp3xxx_rtc_wdt.c b/drivers/watchdog/stmp3xxx_rtc_wdt.c
index d8b11eb269ad..c67f48fba8e1 100644
--- a/drivers/watchdog/stmp3xxx_rtc_wdt.c
+++ b/drivers/watchdog/stmp3xxx_rtc_wdt.c
@@ -99,7 +99,7 @@ static int stmp3xxx_wdt_probe(struct platform_device *pdev)
 	stmp3xxx_wdd.timeout = clamp_t(unsigned, heartbeat, 1, STMP3XXX_MAX_TIMEOUT);
 	stmp3xxx_wdd.parent = &pdev->dev;
 
-	ret = watchdog_register_device(&stmp3xxx_wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, &stmp3xxx_wdd);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "cannot register watchdog device\n");
 		return ret;
@@ -116,7 +116,6 @@ static int stmp3xxx_wdt_probe(struct platform_device *pdev)
 static int stmp3xxx_wdt_remove(struct platform_device *pdev)
 {
 	unregister_reboot_notifier(&wdt_notifier);
-	watchdog_unregister_device(&stmp3xxx_wdd);
 	return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 55/62] watchdog: sunxi_wdt: Convert to use device managed functions and other improvements
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
  2017-01-11  2:09   ` [PATCH 53/62] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
  2017-01-11  2:09   ` [PATCH 54/62] watchdog: stmp3xxx_rtc_wdt: " Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-11 12:15     ` Maxime Ripard
  2017-01-11  2:09   ` [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions Guenter Roeck
                     ` (6 subsequent siblings)
  9 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Maxime Ripard,
	Chen-Yu Tsai, linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/sunxi_wdt.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
index 953bb7b7446f..9728fa32c357 100644
--- a/drivers/watchdog/sunxi_wdt.c
+++ b/drivers/watchdog/sunxi_wdt.c
@@ -242,8 +242,6 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	if (!sunxi_wdt)
 		return -EINVAL;
 
-	platform_set_drvdata(pdev, sunxi_wdt);
-
 	device = of_match_device(sunxi_wdt_dt_ids, &pdev->dev);
 	if (!device)
 		return -ENODEV;
@@ -270,7 +268,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 
 	sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
 
-	err = watchdog_register_device(&sunxi_wdt->wdt_dev);
+	watchdog_stop_on_reboot(&sunxi_wdt->wdt_dev);
+	err = devm_watchdog_register_device(&pdev->dev, &sunxi_wdt->wdt_dev);
 	if (unlikely(err))
 		return err;
 
@@ -280,27 +279,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int sunxi_wdt_remove(struct platform_device *pdev)
-{
-	struct sunxi_wdt_dev *sunxi_wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&sunxi_wdt->wdt_dev);
-	watchdog_set_drvdata(&sunxi_wdt->wdt_dev, NULL);
-
-	return 0;
-}
-
-static void sunxi_wdt_shutdown(struct platform_device *pdev)
-{
-	struct sunxi_wdt_dev *sunxi_wdt = platform_get_drvdata(pdev);
-
-	sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
-}
-
 static struct platform_driver sunxi_wdt_driver = {
 	.probe		= sunxi_wdt_probe,
-	.remove		= sunxi_wdt_remove,
-	.shutdown	= sunxi_wdt_shutdown,
 	.driver		= {
 		.name		= DRV_NAME,
 		.of_match_table	= sunxi_wdt_dt_ids,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
                     ` (2 preceding siblings ...)
  2017-01-11  2:09   ` [PATCH 55/62] watchdog: sunxi_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-11  9:07     ` Marc Gonzalez
  2017-01-11  2:09   ` [PATCH 57/62] watchdog: tegra_wdt: " Guenter Roeck
                     ` (5 subsequent siblings)
  9 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Marc Gonzalez,
	linux-arm-kernel

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/tangox_wdt.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c
index d5fcce062920..7688e1b35867 100644
--- a/drivers/watchdog/tangox_wdt.c
+++ b/drivers/watchdog/tangox_wdt.c
@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
 	err = clk_prepare_enable(dev->clk);
 	if (err)
 		return err;
+	err = devm_add_action_or_reset(&pdev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       dev->clk);
+	if (err)
+		return err;
 
 	dev->clk_rate = clk_get_rate(dev->clk);
-	if (!dev->clk_rate) {
-		err = -EINVAL;
-		goto err;
-	}
+	if (!dev->clk_rate)
+		return -EINVAL;
 
 	dev->wdt.parent = &pdev->dev;
 	dev->wdt.info = &tangox_wdt_info;
@@ -173,19 +176,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_restart_priority(&dev->wdt, 128);
 
-	err = watchdog_register_device(&dev->wdt);
+	err = devm_watchdog_register_device(&pdev->dev, &dev->wdt);
 	if (err)
-		goto err;
+		return err;
 
 	platform_set_drvdata(pdev, dev);
 
 	dev_info(&pdev->dev, "SMP86xx/SMP87xx watchdog registered\n");
 
 	return 0;
-
- err:
-	clk_disable_unprepare(dev->clk);
-	return err;
 }
 
 static int tangox_wdt_remove(struct platform_device *pdev)
@@ -193,9 +192,6 @@ static int tangox_wdt_remove(struct platform_device *pdev)
 	struct tangox_wdt_device *dev = platform_get_drvdata(pdev);
 
 	tangox_wdt_stop(&dev->wdt);
-	clk_disable_unprepare(dev->clk);
-
-	watchdog_unregister_device(&dev->wdt);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 57/62] watchdog: tegra_wdt: Convert to use device managed functions
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
                     ` (3 preceding siblings ...)
  2017-01-11  2:09   ` [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-19 11:04     ` Thierry Reding
  2017-01-11  2:09   ` [PATCH 58/62] watchdog: ts4800_wdt: " Guenter Roeck
                     ` (4 subsequent siblings)
  9 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Stephen Warren,
	Thierry Reding, Alexandre Courbot, linux-tegra

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_watchdog_register_driver() to register watchdog device

Cc: Stephen Warren <swarren@wwwdotorg.org>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Alexandre Courbot <gnurou@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/tegra_wdt.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/watchdog/tegra_wdt.c b/drivers/watchdog/tegra_wdt.c
index 2d53c3f9394f..9403c08816e3 100644
--- a/drivers/watchdog/tegra_wdt.c
+++ b/drivers/watchdog/tegra_wdt.c
@@ -226,7 +226,7 @@ static int tegra_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_nowayout(wdd, nowayout);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, wdd);
 	if (ret) {
 		dev_err(&pdev->dev,
 			"failed to register watchdog device\n");
@@ -248,8 +248,6 @@ static int tegra_wdt_remove(struct platform_device *pdev)
 
 	tegra_wdt_stop(&wdt->wdd);
 
-	watchdog_unregister_device(&wdt->wdd);
-
 	dev_info(&pdev->dev, "removed wdt\n");
 
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 58/62] watchdog: ts4800_wdt: Convert to use device managed functions
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
                     ` (4 preceding siblings ...)
  2017-01-11  2:09   ` [PATCH 57/62] watchdog: tegra_wdt: " Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-11  2:09   ` [PATCH 59/62] watchdog: twl4030_wdt: " Guenter Roeck
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/ts4800_wdt.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/watchdog/ts4800_wdt.c b/drivers/watchdog/ts4800_wdt.c
index 2b8de8602b67..93e0da560b48 100644
--- a/drivers/watchdog/ts4800_wdt.c
+++ b/drivers/watchdog/ts4800_wdt.c
@@ -168,15 +168,13 @@ static int ts4800_wdt_probe(struct platform_device *pdev)
 	 */
 	ts4800_wdt_stop(wdd);
 
-	ret = watchdog_register_device(wdd);
+	ret = devm_watchdog_register_device(&pdev->dev, wdd);
 	if (ret) {
 		dev_err(&pdev->dev,
 			"failed to register watchdog device\n");
 		return ret;
 	}
 
-	platform_set_drvdata(pdev, wdt);
-
 	dev_info(&pdev->dev,
 		 "initialized (timeout = %d sec, nowayout = %d)\n",
 		 wdd->timeout, nowayout);
@@ -184,15 +182,6 @@ static int ts4800_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int ts4800_wdt_remove(struct platform_device *pdev)
-{
-	struct ts4800_wdt *wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&wdt->wdd);
-
-	return 0;
-}
-
 static const struct of_device_id ts4800_wdt_of_match[] = {
 	{ .compatible = "technologic,ts4800-wdt", },
 	{ },
@@ -201,7 +190,6 @@ MODULE_DEVICE_TABLE(of, ts4800_wdt_of_match);
 
 static struct platform_driver ts4800_wdt_driver = {
 	.probe		= ts4800_wdt_probe,
-	.remove		= ts4800_wdt_remove,
 	.driver		= {
 		.name	= "ts4800_wdt",
 		.of_match_table = ts4800_wdt_of_match,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 59/62] watchdog: twl4030_wdt: Convert to use device managed functions
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
                     ` (5 preceding siblings ...)
  2017-01-11  2:09   ` [PATCH 58/62] watchdog: ts4800_wdt: " Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-11  2:09   ` [PATCH 60/62] watchdog: txx9wdt: Convert to use device managed functions and other improvements Guenter Roeck
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/twl4030_wdt.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/drivers/watchdog/twl4030_wdt.c b/drivers/watchdog/twl4030_wdt.c
index 9bf3cc0f3961..9fd8073b0cde 100644
--- a/drivers/watchdog/twl4030_wdt.c
+++ b/drivers/watchdog/twl4030_wdt.c
@@ -70,7 +70,6 @@ static const struct watchdog_ops twl4030_wdt_ops = {
 
 static int twl4030_wdt_probe(struct platform_device *pdev)
 {
-	int ret = 0;
 	struct watchdog_device *wdt;
 
 	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
@@ -90,20 +89,7 @@ static int twl4030_wdt_probe(struct platform_device *pdev)
 
 	twl4030_wdt_stop(wdt);
 
-	ret = watchdog_register_device(wdt);
-	if (ret)
-		return ret;
-
-	return 0;
-}
-
-static int twl4030_wdt_remove(struct platform_device *pdev)
-{
-	struct watchdog_device *wdt = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(wdt);
-
-	return 0;
+	return devm_watchdog_register_device(&pdev->dev, wdt);
 }
 
 #ifdef CONFIG_PM
@@ -137,7 +123,6 @@ MODULE_DEVICE_TABLE(of, twl_wdt_of_match);
 
 static struct platform_driver twl4030_wdt_driver = {
 	.probe		= twl4030_wdt_probe,
-	.remove		= twl4030_wdt_remove,
 	.suspend	= twl4030_wdt_suspend,
 	.resume		= twl4030_wdt_resume,
 	.driver		= {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 60/62] watchdog: txx9wdt: Convert to use device managed functions and other improvements
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
                     ` (6 preceding siblings ...)
  2017-01-11  2:09   ` [PATCH 59/62] watchdog: twl4030_wdt: " Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-11  2:09   ` [PATCH 61/62] watchdog: ux500_wdt: Convert to use device managed functions Guenter Roeck
  2017-01-11  2:09   ` [PATCH 62/62] watchdog: wm831x_wdt: " Guenter Roeck
  9 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.
Other improvements as listed below.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_clk_get() if the device parameter is not NULL
- Use devm_add_action_or_reset() for calls to clk_put() after clk_get()
  with NULL device parameter
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/txx9wdt.c | 46 ++++++++++++++++------------------------------
 1 file changed, 16 insertions(+), 30 deletions(-)

diff --git a/drivers/watchdog/txx9wdt.c b/drivers/watchdog/txx9wdt.c
index 6f7a9deb27d0..28e192367bd9 100644
--- a/drivers/watchdog/txx9wdt.c
+++ b/drivers/watchdog/txx9wdt.c
@@ -110,21 +110,27 @@ static int __init txx9wdt_probe(struct platform_device *dev)
 	if (IS_ERR(txx9_imclk)) {
 		ret = PTR_ERR(txx9_imclk);
 		txx9_imclk = NULL;
-		goto exit;
+		return ret;
 	}
+	ret = devm_add_action_or_reset(&dev->dev, (void(*)(void *))clk_put,
+				       "imbus_clk");
+	if (ret)
+		return ret;
 	ret = clk_prepare_enable(txx9_imclk);
 	if (ret) {
-		clk_put(txx9_imclk);
 		txx9_imclk = NULL;
-		goto exit;
+		return ret;
 	}
+	ret = devm_add_action_or_reset(&dev->dev,
+				       (void(*)(void *))clk_disable_unprepare,
+				       txx9_imclk);
+	if (ret)
+		return ret;
 
 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
 	txx9wdt_reg = devm_ioremap_resource(&dev->dev, res);
-	if (IS_ERR(txx9wdt_reg)) {
-		ret = PTR_ERR(txx9wdt_reg);
-		goto exit;
-	}
+	if (IS_ERR(txx9wdt_reg))
+		return PTR_ERR(txx9wdt_reg);
 
 	if (timeout < 1 || timeout > WD_MAX_TIMEOUT)
 		timeout = TIMER_MARGIN;
@@ -134,38 +140,18 @@ static int __init txx9wdt_probe(struct platform_device *dev)
 	txx9wdt.parent = &dev->dev;
 	watchdog_set_nowayout(&txx9wdt, nowayout);
 
-	ret = watchdog_register_device(&txx9wdt);
+	watchdog_stop_on_reboot(&txx9wdt);
+	ret = devm_watchdog_register_device(&dev->dev, &txx9wdt);
 	if (ret)
-		goto exit;
+		return ret;
 
 	pr_info("Hardware Watchdog Timer: timeout=%d sec (max %ld) (nowayout= %d)\n",
 		timeout, WD_MAX_TIMEOUT, nowayout);
 
 	return 0;
-exit:
-	if (txx9_imclk) {
-		clk_disable_unprepare(txx9_imclk);
-		clk_put(txx9_imclk);
-	}
-	return ret;
-}
-
-static int __exit txx9wdt_remove(struct platform_device *dev)
-{
-	watchdog_unregister_device(&txx9wdt);
-	clk_disable_unprepare(txx9_imclk);
-	clk_put(txx9_imclk);
-	return 0;
-}
-
-static void txx9wdt_shutdown(struct platform_device *dev)
-{
-	txx9wdt_stop(&txx9wdt);
 }
 
 static struct platform_driver txx9wdt_driver = {
-	.remove = __exit_p(txx9wdt_remove),
-	.shutdown = txx9wdt_shutdown,
 	.driver = {
 		.name = "txx9wdt",
 	},
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 61/62] watchdog: ux500_wdt: Convert to use device managed functions
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
                     ` (7 preceding siblings ...)
  2017-01-11  2:09   ` [PATCH 60/62] watchdog: txx9wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-11  2:09   ` [PATCH 62/62] watchdog: wm831x_wdt: " Guenter Roeck
  9 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/ux500_wdt.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/watchdog/ux500_wdt.c b/drivers/watchdog/ux500_wdt.c
index 37c084353cce..847b6658c36d 100644
--- a/drivers/watchdog/ux500_wdt.c
+++ b/drivers/watchdog/ux500_wdt.c
@@ -105,7 +105,7 @@ static int ux500_wdt_probe(struct platform_device *pdev)
 	/* set HW initial value */
 	prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
 
-	ret = watchdog_register_device(&ux500_wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &ux500_wdt);
 	if (ret)
 		return ret;
 
@@ -114,13 +114,6 @@ static int ux500_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int ux500_wdt_remove(struct platform_device *dev)
-{
-	watchdog_unregister_device(&ux500_wdt);
-
-	return 0;
-}
-
 #ifdef CONFIG_PM
 static int ux500_wdt_suspend(struct platform_device *pdev,
 			     pm_message_t state)
@@ -153,7 +146,6 @@ static int ux500_wdt_resume(struct platform_device *pdev)
 
 static struct platform_driver ux500_wdt_driver = {
 	.probe		= ux500_wdt_probe,
-	.remove		= ux500_wdt_remove,
 	.suspend	= ux500_wdt_suspend,
 	.resume		= ux500_wdt_resume,
 	.driver		= {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* [PATCH 62/62] watchdog: wm831x_wdt: Convert to use device managed functions
  2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
                     ` (8 preceding siblings ...)
  2017-01-11  2:09   ` [PATCH 61/62] watchdog: ux500_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  2:09   ` Guenter Roeck
  2017-01-12 10:04     ` Charles Keepax
  9 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11  2:09 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck, patches

Use device managed functions to simplify error handling, reduce
source code size, improve readability, and reduce the likelyhood of bugs.

The conversion was done automatically with coccinelle using the
following semantic patches. The semantic patches and the scripts used
to generate this commit log are available at
https://github.com/groeck/coccinelle-patches

- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/wm831x_wdt.c | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/watchdog/wm831x_wdt.c b/drivers/watchdog/wm831x_wdt.c
index 8d1184aee932..1ddc1f742cd4 100644
--- a/drivers/watchdog/wm831x_wdt.c
+++ b/drivers/watchdog/wm831x_wdt.c
@@ -194,7 +194,7 @@ static int wm831x_wdt_probe(struct platform_device *pdev)
 	if (ret < 0) {
 		dev_err(wm831x->dev, "Failed to read watchdog status: %d\n",
 			ret);
-		goto err;
+		return ret;
 	}
 	reg = ret;
 
@@ -203,10 +203,8 @@ static int wm831x_wdt_probe(struct platform_device *pdev)
 
 	driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data),
 				   GFP_KERNEL);
-	if (!driver_data) {
-		ret = -ENOMEM;
-		goto err;
-	}
+	if (!driver_data)
+		return -ENOMEM;
 
 	mutex_init(&driver_data->lock);
 	driver_data->wm831x = wm831x;
@@ -253,7 +251,7 @@ static int wm831x_wdt_probe(struct platform_device *pdev)
 				dev_err(wm831x->dev,
 					"Failed to request update GPIO: %d\n",
 					ret);
-				goto err;
+				return ret;
 			}
 
 			driver_data->update_gpio = pdata->update_gpio;
@@ -269,37 +267,22 @@ static int wm831x_wdt_probe(struct platform_device *pdev)
 		} else {
 			dev_err(wm831x->dev,
 				"Failed to unlock security key: %d\n", ret);
-			goto err;
+			return ret;
 		}
 	}
 
-	ret = watchdog_register_device(&driver_data->wdt);
+	ret = devm_watchdog_register_device(&pdev->dev, &driver_data->wdt);
 	if (ret != 0) {
 		dev_err(wm831x->dev, "watchdog_register_device() failed: %d\n",
 			ret);
-		goto err;
+		return ret;
 	}
 
-	platform_set_drvdata(pdev, driver_data);
-
-	return 0;
-
-err:
-	return ret;
-}
-
-static int wm831x_wdt_remove(struct platform_device *pdev)
-{
-	struct wm831x_wdt_drvdata *driver_data = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&driver_data->wdt);
-
 	return 0;
 }
 
 static struct platform_driver wm831x_wdt_driver = {
 	.probe = wm831x_wdt_probe,
-	.remove = wm831x_wdt_remove,
 	.driver = {
 		.name = "wm831x-watchdog",
 	},
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* Re: [PATCH 02/62] watchdog: aspeed_wdt: Convert to use device managed functions
  2017-01-10 23:34 ` [PATCH 02/62] watchdog: aspeed_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  5:18   ` Joel Stanley
  0 siblings, 0 replies; 98+ messages in thread
From: Joel Stanley @ 2017-01-11  5:18 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel

On Wed, Jan 11, 2017 at 10:34 AM, Guenter Roeck <linux@roeck-us.net> wrote:
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
>
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
>
> - Drop assignments to otherwise unused variables
> - Drop remove function
> - Drop platform_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device
>
> Cc: Joel Stanley <joel@jms.id.au>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Acked-by: Joel Stanley <joel@jms.id.au>

Cheers,

Joel

> ---
>  drivers/watchdog/aspeed_wdt.c | 14 +-------------
>  1 file changed, 1 insertion(+), 13 deletions(-)
>
> diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c
> index f5ad8023c2e6..1c652582de40 100644
> --- a/drivers/watchdog/aspeed_wdt.c
> +++ b/drivers/watchdog/aspeed_wdt.c
> @@ -136,15 +136,6 @@ static const struct watchdog_info aspeed_wdt_info = {
>         .identity       = KBUILD_MODNAME,
>  };
>
> -static int aspeed_wdt_remove(struct platform_device *pdev)
> -{
> -       struct aspeed_wdt *wdt = platform_get_drvdata(pdev);
> -
> -       watchdog_unregister_device(&wdt->wdd);
> -
> -       return 0;
> -}
> -
>  static int aspeed_wdt_probe(struct platform_device *pdev)
>  {
>         struct aspeed_wdt *wdt;
> @@ -187,20 +178,17 @@ static int aspeed_wdt_probe(struct platform_device *pdev)
>                 set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
>         }
>
> -       ret = watchdog_register_device(&wdt->wdd);
> +       ret = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
>         if (ret) {
>                 dev_err(&pdev->dev, "failed to register\n");
>                 return ret;
>         }
>
> -       platform_set_drvdata(pdev, wdt);
> -
>         return 0;
>  }
>
>  static struct platform_driver aspeed_watchdog_driver = {
>         .probe = aspeed_wdt_probe,
> -       .remove = aspeed_wdt_remove,
>         .driver = {
>                 .name = KBUILD_MODNAME,
>                 .of_match_table = of_match_ptr(aspeed_wdt_of_table),
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44   ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11  8:42     ` Neil Armstrong
  2017-01-11 18:44     ` Kevin Hilman
  1 sibling, 0 replies; 98+ messages in thread
From: Neil Armstrong @ 2017-01-11  8:42 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: linux-watchdog, Kevin Hilman, linux-kernel, linux-arm-kernel,
	Carlo Caione, linux-amlogic

On 01/11/2017 01:44 AM, Guenter Roeck wrote:
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> Other improvements as listed below.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
> - Check return value from clk_prepare_enable()
> - Replace 'val = e; return val;' with 'return e;'
> - Replace 'if (e) return e; return 0;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Replace 'if (e) { return expr; }' with 'if (e) return expr;'
> - Drop remove function
> - Use devm_watchdog_register_driver() to register watchdog device
> - Replace shutdown function with call to watchdog_stop_on_reboot()
> 
> Cc: Carlo Caione <carlo@caione.org>
> Cc: Kevin Hilman <khilman@baylibre.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/meson_gxbb_wdt.c | 38 ++++++++++----------------------------
>  1 file changed, 10 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c
> index 45d47664a00a..913d8a644460 100644
> --- a/drivers/watchdog/meson_gxbb_wdt.c
> +++ b/drivers/watchdog/meson_gxbb_wdt.c
> @@ -203,7 +203,14 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
>  	if (IS_ERR(data->clk))
>  		return PTR_ERR(data->clk);
>  
> -	clk_prepare_enable(data->clk);
> +	ret = clk_prepare_enable(data->clk);
> +	if (ret)
> +		return ret;
> +	ret = devm_add_action_or_reset(&pdev->dev,
> +				       (void(*)(void *))clk_disable_unprepare,
> +				       data->clk);
> +	if (ret)
> +		return ret;
>  
>  	platform_set_drvdata(pdev, data);
>  
> @@ -224,37 +231,12 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
>  
>  	meson_gxbb_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout);
>  
> -	ret = watchdog_register_device(&data->wdt_dev);
> -	if (ret) {
> -		clk_disable_unprepare(data->clk);
> -		return ret;
> -	}
> -
> -	return 0;
> -}
> -
> -static int meson_gxbb_wdt_remove(struct platform_device *pdev)
> -{
> -	struct meson_gxbb_wdt *data = platform_get_drvdata(pdev);
> -
> -	watchdog_unregister_device(&data->wdt_dev);
> -
> -	clk_disable_unprepare(data->clk);
> -
> -	return 0;
> -}
> -
> -static void meson_gxbb_wdt_shutdown(struct platform_device *pdev)
> -{
> -	struct meson_gxbb_wdt *data = platform_get_drvdata(pdev);
> -
> -	meson_gxbb_wdt_stop(&data->wdt_dev);
> +	watchdog_stop_on_reboot(&data->wdt_dev);
> +	return devm_watchdog_register_device(&pdev->dev, &data->wdt_dev);
>  }
>  
>  static struct platform_driver meson_gxbb_wdt_driver = {
>  	.probe	= meson_gxbb_wdt_probe,
> -	.remove	= meson_gxbb_wdt_remove,
> -	.shutdown = meson_gxbb_wdt_shutdown,
>  	.driver = {
>  		.name = "meson-gxbb-wdt",
>  		.pm = &meson_gxbb_wdt_pm_ops,
> 

Was on my todo list, glad you did this !

Acked-by: Neil Armstrong <narmstrong@baylibre.com>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11  2:09   ` [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11  9:07     ` Marc Gonzalez
  2017-01-11 10:52       ` Guenter Roeck
  0 siblings, 1 reply; 98+ messages in thread
From: Marc Gonzalez @ 2017-01-11  9:07 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel,
	Mans Rullgard, Thibaud Cornic

On 11/01/2017 03:09, Guenter Roeck wrote:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
> - Replace 'goto l; ... l: return e;' with 'return e;'
> - Replace 'val = e; return val;' with 'return e;'
> - Replace 'if (e) { return expr; }' with 'if (e) return expr;'
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Cc: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/tangox_wdt.c | 22 +++++++++-------------
>  1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c
> index d5fcce062920..7688e1b35867 100644
> --- a/drivers/watchdog/tangox_wdt.c
> +++ b/drivers/watchdog/tangox_wdt.c
> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>  	err = clk_prepare_enable(dev->clk);
>  	if (err)
>  		return err;
> +	err = devm_add_action_or_reset(&pdev->dev,
> +				       (void(*)(void *))clk_disable_unprepare,
> +				       dev->clk);
> +	if (err)
> +		return err;

Hello Guenter,

I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?

clk_disable_unprepare() is static inline, so gcc will have to
define an auxiliary function either way. What do you think?

Regards.


diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c
index 202c4b9cc921..1a4f6d245a83 100644
--- a/drivers/watchdog/tangox_wdt.c
+++ b/drivers/watchdog/tangox_wdt.c
@@ -114,6 +114,11 @@ static int tangox_wdt_restart(struct notifier_block *nb, unsigned long action,
        return NOTIFY_DONE;
 }
 
+static void cleanup(void *clk)
+{
+       clk_disable_unprepare(clk);
+}
+
 static int tangox_wdt_probe(struct platform_device *pdev)
 {
        struct tangox_wdt_device *dev;
@@ -138,6 +143,10 @@ static int tangox_wdt_probe(struct platform_device *pdev)
        if (err)
                return err;
 
+       err = devm_add_action_or_reset(&pdev->dev, cleanup, dev->clk);
+       if (err)
+               return err;
+
        dev->clk_rate = clk_get_rate(dev->clk);
        if (!dev->clk_rate) {
                err = -EINVAL;

^ permalink raw reply related	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11  9:07     ` Marc Gonzalez
@ 2017-01-11 10:52       ` Guenter Roeck
  2017-01-11 12:31         ` Marc Gonzalez
  2017-01-12  0:12         ` Andy Shevchenko
  0 siblings, 2 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11 10:52 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel,
	Mans Rullgard, Thibaud Cornic

On 01/11/2017 01:07 AM, Marc Gonzalez wrote:

>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>>  	err = clk_prepare_enable(dev->clk);
>>  	if (err)
>>  		return err;
>> +	err = devm_add_action_or_reset(&pdev->dev,
>> +				       (void(*)(void *))clk_disable_unprepare,
>> +				       dev->clk);
>> +	if (err)
>> +		return err;
>
> Hello Guenter,
>
> I would rather avoid the function pointer cast.
> How about defining an auxiliary function for the cleanup action?
>
> clk_disable_unprepare() is static inline, so gcc will have to
> define an auxiliary function either way. What do you think?
>

Not really. It would just make it more complicated to replace the
call with devm_clk_prepare_enable(), should it ever find its way
into the light of day.

Guenter

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 55/62] watchdog: sunxi_wdt: Convert to use device managed functions and other improvements
  2017-01-11  2:09   ` [PATCH 55/62] watchdog: sunxi_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-11 12:15     ` Maxime Ripard
  0 siblings, 0 replies; 98+ messages in thread
From: Maxime Ripard @ 2017-01-11 12:15 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, Chen-Yu Tsai,
	linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 1075 bytes --]

On Tue, Jan 10, 2017 at 06:09:09PM -0800, Guenter Roeck wrote:
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> Other improvements as listed below.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Drop assignments to otherwise unused variables
> - Drop remove function
> - Drop platform_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device
> - Replace shutdown function with call to watchdog_stop_on_reboot()
> 
> Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
> Cc: Chen-Yu Tsai <wens@csie.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 10:52       ` Guenter Roeck
@ 2017-01-11 12:31         ` Marc Gonzalez
  2017-01-11 14:25           ` Guenter Roeck
  2017-01-11 14:39           ` Uwe Kleine-König
  2017-01-12  0:12         ` Andy Shevchenko
  1 sibling, 2 replies; 98+ messages in thread
From: Marc Gonzalez @ 2017-01-11 12:31 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel,
	Mans Rullgard, Thibaud Cornic, Mark Rutland, Uwe Kleine-Konig,
	Arnd Bergmann

On 11/01/2017 11:52, Guenter Roeck wrote:

> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
> 
>>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>>>  	err = clk_prepare_enable(dev->clk);
>>>  	if (err)
>>>  		return err;
>>> +	err = devm_add_action_or_reset(&pdev->dev,
>>> +				       (void(*)(void *))clk_disable_unprepare,
>>> +				       dev->clk);
>>> +	if (err)
>>> +		return err;
>>
>> Hello Guenter,
>>
>> I would rather avoid the function pointer cast.
>> How about defining an auxiliary function for the cleanup action?
>>
>> clk_disable_unprepare() is static inline, so gcc will have to
>> define an auxiliary function either way. What do you think?
> 
> Not really. It would just make it more complicated to replace the
> call with devm_clk_prepare_enable(), should it ever find its way
> into the light of day.

More complicated, because the cleanup function will have to be deleted later?
The compiler will warn if someone forgets to do that.

In my opinion, it's not a good idea to rely on the fact that casting
void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
on most platforms. (It has undefined behavior, strictly speaking.)

Do you really dislike the portable solution I suggested? :-(

Regards.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 12:31         ` Marc Gonzalez
@ 2017-01-11 14:25           ` Guenter Roeck
  2017-01-11 14:43             ` Måns Rullgård
  2017-01-11 15:28             ` Marc Gonzalez
  2017-01-11 14:39           ` Uwe Kleine-König
  1 sibling, 2 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11 14:25 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel,
	Mans Rullgard, Thibaud Cornic, Mark Rutland, Uwe Kleine-Konig,
	Arnd Bergmann

On 01/11/2017 04:31 AM, Marc Gonzalez wrote:
> On 11/01/2017 11:52, Guenter Roeck wrote:
>
>> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
>>
>>>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>>>>  	err = clk_prepare_enable(dev->clk);
>>>>  	if (err)
>>>>  		return err;
>>>> +	err = devm_add_action_or_reset(&pdev->dev,
>>>> +				       (void(*)(void *))clk_disable_unprepare,
>>>> +				       dev->clk);
>>>> +	if (err)
>>>> +		return err;
>>>
>>> Hello Guenter,
>>>
>>> I would rather avoid the function pointer cast.
>>> How about defining an auxiliary function for the cleanup action?
>>>
>>> clk_disable_unprepare() is static inline, so gcc will have to
>>> define an auxiliary function either way. What do you think?
>>
>> Not really. It would just make it more complicated to replace the
>> call with devm_clk_prepare_enable(), should it ever find its way
>> into the light of day.
>
> More complicated, because the cleanup function will have to be deleted later?
> The compiler will warn if someone forgets to do that.
>
> In my opinion, it's not a good idea to rely on the fact that casting
> void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
> on most platforms. (It has undefined behavior, strictly speaking.)
>
I do hear that you object to this code.

However, I must admit that you completely lost me here. It is a cast from
one function pointer to another, passed as argument to another function,
with a secondary cast of its argument from a typed pointer to a void pointer.
I don't think C permits for "undefined behavior, strictly speaking".
Besides, that same mechanism is already used elsewhere, which is how I
got the idea. Are you claiming that there are situations where it won't
work ?

> Do you really dislike the portable solution I suggested? :-(
>
It is not more portable than the above. It is more expensive and adds more
code.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 12:31         ` Marc Gonzalez
  2017-01-11 14:25           ` Guenter Roeck
@ 2017-01-11 14:39           ` Uwe Kleine-König
  2017-01-11 14:50             ` Vladimir Zapolskiy
                               ` (2 more replies)
  1 sibling, 3 replies; 98+ messages in thread
From: Uwe Kleine-König @ 2017-01-11 14:39 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Guenter Roeck, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm-kernel, Mans Rullgard, Thibaud Cornic, Mark Rutland,
	Arnd Bergmann

On Wed, Jan 11, 2017 at 01:31:47PM +0100, Marc Gonzalez wrote:
> On 11/01/2017 11:52, Guenter Roeck wrote:
> 
> > On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
> > 
> >>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
> >>>  	err = clk_prepare_enable(dev->clk);
> >>>  	if (err)
> >>>  		return err;
> >>> +	err = devm_add_action_or_reset(&pdev->dev,
> >>> +				       (void(*)(void *))clk_disable_unprepare,
> >>> +				       dev->clk);
> >>> +	if (err)
> >>> +		return err;

This looks wrong. There is no clk_unprepare_disable when
devm_add_action_or_reset fails.

> >>
> >> Hello Guenter,
> >>
> >> I would rather avoid the function pointer cast.
> >> How about defining an auxiliary function for the cleanup action?
> >>
> >> clk_disable_unprepare() is static inline, so gcc will have to
> >> define an auxiliary function either way. What do you think?
> > 
> > Not really. It would just make it more complicated to replace the
> > call with devm_clk_prepare_enable(), should it ever find its way
> > into the light of day.
> 
> More complicated, because the cleanup function will have to be deleted later?
> The compiler will warn if someone forgets to do that.
> 
> In my opinion, it's not a good idea to rely on the fact that casting
> void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
> on most platforms. (It has undefined behavior, strictly speaking.)

I would expect it to work on all (Linux) platforms. Anyhow, I wonder if
there couldn't be found a better solution.

If in the end it looks like the following that would be good I think:

	clk = devm_clk_get(...);
	if (IS_ERR(clk))
		...

	ret = devm_clk_prepare_enable(clk)
	if (ret)
		return ret;

	...

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 14:25           ` Guenter Roeck
@ 2017-01-11 14:43             ` Måns Rullgård
  2017-01-11 15:28             ` Marc Gonzalez
  1 sibling, 0 replies; 98+ messages in thread
From: Måns Rullgård @ 2017-01-11 14:43 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Marc Gonzalez, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm-kernel, Thibaud Cornic, Mark Rutland, Uwe Kleine-Konig,
	Arnd Bergmann

Guenter Roeck <linux@roeck-us.net> writes:

> On 01/11/2017 04:31 AM, Marc Gonzalez wrote:
>> On 11/01/2017 11:52, Guenter Roeck wrote:
>>
>>> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
>>>
>>>>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>>>>>  	err = clk_prepare_enable(dev->clk);
>>>>>  	if (err)
>>>>>  		return err;
>>>>> +	err = devm_add_action_or_reset(&pdev->dev,
>>>>> +				       (void(*)(void *))clk_disable_unprepare,
>>>>> +				       dev->clk);
>>>>> +	if (err)
>>>>> +		return err;
>>>>
>>>> Hello Guenter,
>>>>
>>>> I would rather avoid the function pointer cast.
>>>> How about defining an auxiliary function for the cleanup action?
>>>>
>>>> clk_disable_unprepare() is static inline, so gcc will have to
>>>> define an auxiliary function either way. What do you think?
>>>
>>> Not really. It would just make it more complicated to replace the
>>> call with devm_clk_prepare_enable(), should it ever find its way
>>> into the light of day.
>>
>> More complicated, because the cleanup function will have to be deleted later?
>> The compiler will warn if someone forgets to do that.
>>
>> In my opinion, it's not a good idea to rely on the fact that casting
>> void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
>> on most platforms. (It has undefined behavior, strictly speaking.)
>>
> I do hear that you object to this code.
>
> However, I must admit that you completely lost me here. It is a cast from
> one function pointer to another, passed as argument to another function,
> with a secondary cast of its argument from a typed pointer to a void pointer.
> I don't think C permits for "undefined behavior, strictly speaking".
> Besides, that same mechanism is already used elsewhere, which is how I
> got the idea. Are you claiming that there are situations where it won't
> work ?

A pointer to void is interchangeable with any other pointer type.  That
doesn't necessarily imply that pointers to functions taking arguments of
different pointer types (as we have here) are always compatible.  I'd
have to read the C standard carefully to see if there's any such
promise, and I have other things to do right now.  I am, however, not
aware of any ABI (certainly none used by Linux) where it would pose a
problem.

-- 
Måns Rullgård

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 14:39           ` Uwe Kleine-König
@ 2017-01-11 14:50             ` Vladimir Zapolskiy
  2017-01-11 17:28             ` Guenter Roeck
  2017-01-13  5:17             ` Guenter Roeck
  2 siblings, 0 replies; 98+ messages in thread
From: Vladimir Zapolskiy @ 2017-01-11 14:50 UTC (permalink / raw)
  To: Uwe Kleine-König, Marc Gonzalez
  Cc: Guenter Roeck, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm-kernel, Mans Rullgard, Thibaud Cornic, Mark Rutland,
	Arnd Bergmann

Hello Uwe,

On 01/11/2017 04:39 PM, Uwe Kleine-König wrote:
> On Wed, Jan 11, 2017 at 01:31:47PM +0100, Marc Gonzalez wrote:
>> On 11/01/2017 11:52, Guenter Roeck wrote:
>>
>>> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
>>>
>>>>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>>>>>  	err = clk_prepare_enable(dev->clk);
>>>>>  	if (err)
>>>>>  		return err;
>>>>> +	err = devm_add_action_or_reset(&pdev->dev,
>>>>> +				       (void(*)(void *))clk_disable_unprepare,
>>>>> +				       dev->clk);
>>>>> +	if (err)
>>>>> +		return err;
> 
> This looks wrong. There is no clk_unprepare_disable when
> devm_add_action_or_reset fails.

actually there is a call to clk_disable_unprepare() on error path, you may
take a look at devm_add_action_or_reset() implementation.

Your comment is valid for devm_add_action() function though, but it's not
the case here.

--
With best wishes,
Vladimir

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 14:25           ` Guenter Roeck
  2017-01-11 14:43             ` Måns Rullgård
@ 2017-01-11 15:28             ` Marc Gonzalez
  2017-01-11 17:51               ` Guenter Roeck
  1 sibling, 1 reply; 98+ messages in thread
From: Marc Gonzalez @ 2017-01-11 15:28 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel,
	Mans Rullgard, Thibaud Cornic, Mark Rutland, Uwe Kleine-Konig,
	Arnd Bergmann

On 11/01/2017 15:25, Guenter Roeck wrote:
> On 01/11/2017 04:31 AM, Marc Gonzalez wrote:
>> On 11/01/2017 11:52, Guenter Roeck wrote:
>>
>>> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
>>>
>>>>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>>>>>  	err = clk_prepare_enable(dev->clk);
>>>>>  	if (err)
>>>>>  		return err;
>>>>> +	err = devm_add_action_or_reset(&pdev->dev,
>>>>> +				       (void(*)(void *))clk_disable_unprepare,
>>>>> +				       dev->clk);
>>>>> +	if (err)
>>>>> +		return err;
>>>>
>>>> Hello Guenter,
>>>>
>>>> I would rather avoid the function pointer cast.
>>>> How about defining an auxiliary function for the cleanup action?
>>>>
>>>> clk_disable_unprepare() is static inline, so gcc will have to
>>>> define an auxiliary function either way. What do you think?
>>>
>>> Not really. It would just make it more complicated to replace the
>>> call with devm_clk_prepare_enable(), should it ever find its way
>>> into the light of day.
>>
>> More complicated, because the cleanup function will have to be deleted later?
>> The compiler will warn if someone forgets to do that.
>>
>> In my opinion, it's not a good idea to rely on the fact that casting
>> void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
>> on most platforms. (It has undefined behavior, strictly speaking.)
>
> I do hear that you object to this code.
> 
> However, I must admit that you completely lost me here. It is a cast from
> one function pointer to another,

Perhaps you are used to work at the assembly level, where pointers are
just addresses, and all pointers are interchangeable.

At a slightly higher level (C abstract machine), it is not so.

> passed as argument to another function,
> with a secondary cast of its argument from a typed pointer to a void pointer.
> I don't think C permits for "undefined behavior, strictly speaking".

The C standard leaves quite a lot of behavior undefined, e.g.

char *foo = "hello";
foo[1] = 'a'; // UB

char buf[4];
*(int *)&buf = 0xdeadbeef; // UB

1 << 64; // UB

> Besides, that same mechanism is already used elsewhere, which is how I
> got the idea. Are you claiming that there are situations where it won't
> work ?

If this technique is already used elsewhere in the kernel, then I'll
crawl back under my rock (and weep).

I can see two issues with the code you propose.

First is the same for all casts: silencing potential warnings,
e.g. if the prototype of clk_disable_unprepare ever changed.
(Though casts are required for vararg function arguments.)

Second is just theory and not a real-world concern.

>> Do you really dislike the portable solution I suggested? :-(
>
> It is not more portable than the above. It is more expensive and adds more
> code.

Maybe I am mistaken. Can you tell me why adding an auxiliary function
is more expensive? (In CPU cycles?)

clk_disable_unprepare() is static inline, so an auxiliary function
exists either way (implicit or explicit).

Regards.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions
  2017-01-10 23:34 ` [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions Guenter Roeck
@ 2017-01-11 15:48   ` Linus Walleij
  0 siblings, 0 replies; 98+ messages in thread
From: Linus Walleij @ 2017-01-11 15:48 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel

On Wed, Jan 11, 2017 at 12:34 AM, Guenter Roeck <linux@roeck-us.net> wrote:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
>
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
>
> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
> - Use devm_clk_get() if the device parameter is not NULL
> - Replace 'goto l; ... l: return e;' with 'return e;'
> - Replace 'val = e; return val;' with 'return e;'
> - Replace 'if (e) { return expr; }' with 'if (e) return expr;'
> - Replace request_irq, request_threaded_irq, and request_any_context_irq
>   with their device managed equivalent
> - Replace &pdev->dev with dev if 'struct device *dev' is a declared
>   variable
> - Use devm_watchdog_register_driver() to register watchdog device
>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 14:39           ` Uwe Kleine-König
  2017-01-11 14:50             ` Vladimir Zapolskiy
@ 2017-01-11 17:28             ` Guenter Roeck
  2017-01-13  5:17             ` Guenter Roeck
  2 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11 17:28 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Marc Gonzalez, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm-kernel, Mans Rullgard, Thibaud Cornic, Mark Rutland,
	Arnd Bergmann

On Wed, Jan 11, 2017 at 03:39:17PM +0100, Uwe Kleine-König wrote:
> On Wed, Jan 11, 2017 at 01:31:47PM +0100, Marc Gonzalez wrote:
> > On 11/01/2017 11:52, Guenter Roeck wrote:
> > 
> > > On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
> > > 
> > >>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
> > >>>  	err = clk_prepare_enable(dev->clk);
> > >>>  	if (err)
> > >>>  		return err;
> > >>> +	err = devm_add_action_or_reset(&pdev->dev,
> > >>> +				       (void(*)(void *))clk_disable_unprepare,
> > >>> +				       dev->clk);
> > >>> +	if (err)
> > >>> +		return err;
> 
> This looks wrong. There is no clk_unprepare_disable when
> devm_add_action_or_reset fails.
> 
That is what the _or_reset part of devm_add_action_or_reset() is for.

> > >>
> > >> Hello Guenter,
> > >>
> > >> I would rather avoid the function pointer cast.
> > >> How about defining an auxiliary function for the cleanup action?
> > >>
> > >> clk_disable_unprepare() is static inline, so gcc will have to
> > >> define an auxiliary function either way. What do you think?
> > > 
> > > Not really. It would just make it more complicated to replace the
> > > call with devm_clk_prepare_enable(), should it ever find its way
> > > into the light of day.
> > 
> > More complicated, because the cleanup function will have to be deleted later?
> > The compiler will warn if someone forgets to do that.
> > 
> > In my opinion, it's not a good idea to rely on the fact that casting
> > void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
> > on most platforms. (It has undefined behavior, strictly speaking.)
> 
> I would expect it to work on all (Linux) platforms. Anyhow, I wonder if
> there couldn't be found a better solution.
> 
> If in the end it looks like the following that would be good I think:
> 
> 	clk = devm_clk_get(...);
> 	if (IS_ERR(clk))
> 		...
> 
> 	ret = devm_clk_prepare_enable(clk)
> 	if (ret)
> 		return ret;
> 
Yes, Dmitry tried to introduce devm_clk_prepare_enable() some 5 years ago,
but the effort stalled.

My take is that it will be easy to write another coccinelle script to convert
to devm_clk_prepare_enable() once that is available, but I didn't see the point
of waiting for that, especially since it may never happen.

Guenter

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 15:28             ` Marc Gonzalez
@ 2017-01-11 17:51               ` Guenter Roeck
  2017-01-12  9:44                 ` Marc Gonzalez
  0 siblings, 1 reply; 98+ messages in thread
From: Guenter Roeck @ 2017-01-11 17:51 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel,
	Mans Rullgard, Thibaud Cornic, Mark Rutland, Uwe Kleine-Konig,
	Arnd Bergmann

On Wed, Jan 11, 2017 at 04:28:12PM +0100, Marc Gonzalez wrote:
> On 11/01/2017 15:25, Guenter Roeck wrote:
> > On 01/11/2017 04:31 AM, Marc Gonzalez wrote:
> >> On 11/01/2017 11:52, Guenter Roeck wrote:
> >>
> >>> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
> >>>
> >>>>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
> >>>>>  	err = clk_prepare_enable(dev->clk);
> >>>>>  	if (err)
> >>>>>  		return err;
> >>>>> +	err = devm_add_action_or_reset(&pdev->dev,
> >>>>> +				       (void(*)(void *))clk_disable_unprepare,
> >>>>> +				       dev->clk);
> >>>>> +	if (err)
> >>>>> +		return err;
> >>>>
> >>>> Hello Guenter,
> >>>>
> >>>> I would rather avoid the function pointer cast.
> >>>> How about defining an auxiliary function for the cleanup action?
> >>>>
> >>>> clk_disable_unprepare() is static inline, so gcc will have to
> >>>> define an auxiliary function either way. What do you think?
> >>>
> >>> Not really. It would just make it more complicated to replace the
> >>> call with devm_clk_prepare_enable(), should it ever find its way
> >>> into the light of day.
> >>
> >> More complicated, because the cleanup function will have to be deleted later?
> >> The compiler will warn if someone forgets to do that.
> >>
> >> In my opinion, it's not a good idea to rely on the fact that casting
> >> void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
> >> on most platforms. (It has undefined behavior, strictly speaking.)
> >
> > I do hear that you object to this code.
> > 
> > However, I must admit that you completely lost me here. It is a cast from
> > one function pointer to another,
> 
> Perhaps you are used to work at the assembly level, where pointers are
> just addresses, and all pointers are interchangeable.
> 
> At a slightly higher level (C abstract machine), it is not so.
> 
> > passed as argument to another function,
> > with a secondary cast of its argument from a typed pointer to a void pointer.
> > I don't think C permits for "undefined behavior, strictly speaking".
> 
> The C standard leaves quite a lot of behavior undefined, e.g.
> 
> char *foo = "hello";
> foo[1] = 'a'; // UB
> 
> char buf[4];
> *(int *)&buf = 0xdeadbeef; // UB
> 
> 1 << 64; // UB
> 
Ah, yes, I stand corrected.

However, some other unrelated undefined behavior does not mean that this
specific behavior is undefined.

So far we have a claim that a cast to a void * may somehow be different
to a cast to a different pointer, if used as function argument, and that
the behavior with such a cast may be undefined. In other words, you claim
that a function implemented as, say,

   void func(int *var) {}

might result in undefined behavior if some header file declares it as

    void func(void *);

and it is called as

    int var;

    func(&var);

That seems really far fetched to me.

I do get the message that you do not like this kind of cast. But that doesn't
mean it is not correct.

> > Besides, that same mechanism is already used elsewhere, which is how I
> > got the idea. Are you claiming that there are situations where it won't
> > work ?
> 
> If this technique is already used elsewhere in the kernel, then I'll
> crawl back under my rock (and weep).
> 

git grep "(void(\*)(void \*))"

and variants thereof:

git grep "(void(\*)"

> I can see two issues with the code you propose.
> 
> First is the same for all casts: silencing potential warnings,
> e.g. if the prototype of clk_disable_unprepare ever changed.
> (Though casts are required for vararg function arguments.)
> 
Understood. However, one should really hope that anyone changing
an API has a look at all its callers and does not just pray that
there are no problems.

> Second is just theory and not a real-world concern.
> 
> >> Do you really dislike the portable solution I suggested? :-(
> >
> > It is not more portable than the above. It is more expensive and adds more
> > code.
> 
> Maybe I am mistaken. Can you tell me why adding an auxiliary function
> is more expensive? (In CPU cycles?)
> 
In terms of code required. The idea here is to simplify the code, not
to make it more complex. The auxiliary function needs to be declared
and maintained in each affected file. I do find it easier and better
(and safer, for that matter) to let the C compiler handle it.

Guenter

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44   ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck
  2017-01-11  8:42     ` Neil Armstrong
@ 2017-01-11 18:44     ` Kevin Hilman
  1 sibling, 0 replies; 98+ messages in thread
From: Kevin Hilman @ 2017-01-11 18:44 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, Carlo Caione,
	linux-amlogic, linux-arm-kernel

Guenter Roeck <linux@roeck-us.net> writes:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> Other improvements as listed below.
>
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
>
> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
> - Check return value from clk_prepare_enable()
> - Replace 'val = e; return val;' with 'return e;'
> - Replace 'if (e) return e; return 0;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Replace 'if (e) { return expr; }' with 'if (e) return expr;'
> - Drop remove function
> - Use devm_watchdog_register_driver() to register watchdog device
> - Replace shutdown function with call to watchdog_stop_on_reboot()
>
> Cc: Carlo Caione <carlo@caione.org>
> Cc: Kevin Hilman <khilman@baylibre.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Nice, thanks for the cleanup!

Acked-by: Kevin Hilman <khilman@baylibre.com>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 33/62] watchdog: meson_wdt: Convert to use device managed functions and other improvements
  2017-01-11  0:44   ` [PATCH 33/62] watchdog: meson_wdt: " Guenter Roeck
@ 2017-01-11 18:45     ` Kevin Hilman
  0 siblings, 0 replies; 98+ messages in thread
From: Kevin Hilman @ 2017-01-11 18:45 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, Carlo Caione,
	linux-amlogic, linux-arm-kernel

Guenter Roeck <linux@roeck-us.net> writes:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> Other improvements as listed below.
>
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
>
> - Drop assignments to otherwise unused variables
> - Drop remove function
> - Drop platform_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device
> - Replace shutdown function with call to watchdog_stop_on_reboot()
>
> Cc: Carlo Caione <carlo@caione.org>
> Cc: Kevin Hilman <khilman@baylibre.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Acked-by: Kevin Hilman <khilman@baylibre.com>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 23/62] watchdog: intel-mid_wdt: Convert to use device managed functions
  2017-01-10 23:34 ` [PATCH 23/62] watchdog: intel-mid_wdt: " Guenter Roeck
@ 2017-01-11 23:36   ` Andy Shevchenko
  0 siblings, 0 replies; 98+ messages in thread
From: Andy Shevchenko @ 2017-01-11 23:36 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel

On Wed, Jan 11, 2017 at 1:34 AM, Guenter Roeck <linux@roeck-us.net> wrote:
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
>
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
>
> - Drop assignments to otherwise unused variables
> - Drop remove function
> - Drop platform_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/intel-mid_wdt.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)
>
> diff --git a/drivers/watchdog/intel-mid_wdt.c b/drivers/watchdog/intel-mid_wdt.c
> index a4b729259b12..45e4d02221b5 100644
> --- a/drivers/watchdog/intel-mid_wdt.c
> +++ b/drivers/watchdog/intel-mid_wdt.c
> @@ -137,7 +137,6 @@ static int mid_wdt_probe(struct platform_device *pdev)
>         wdt_dev->parent = &pdev->dev;
>
>         watchdog_set_drvdata(wdt_dev, &pdev->dev);
> -       platform_set_drvdata(pdev, wdt_dev);
>
>         ret = devm_request_irq(&pdev->dev, pdata->irq, mid_wdt_irq,
>                                IRQF_SHARED | IRQF_NO_SUSPEND, "watchdog",
> @@ -151,7 +150,7 @@ static int mid_wdt_probe(struct platform_device *pdev)
>         /* Make sure the watchdog is not running */
>         wdt_stop(wdt_dev);
>
> -       ret = watchdog_register_device(wdt_dev);
> +       ret = devm_watchdog_register_device(&pdev->dev, wdt_dev);
>         if (ret) {
>                 dev_err(&pdev->dev, "error registering watchdog device\n");
>                 return ret;
> @@ -162,16 +161,8 @@ static int mid_wdt_probe(struct platform_device *pdev)
>         return 0;
>  }
>
> -static int mid_wdt_remove(struct platform_device *pdev)
> -{
> -       struct watchdog_device *wd = platform_get_drvdata(pdev);
> -       watchdog_unregister_device(wd);
> -       return 0;
> -}
> -
>  static struct platform_driver mid_wdt_driver = {
>         .probe          = mid_wdt_probe,
> -       .remove         = mid_wdt_remove,
>         .driver         = {
>                 .name   = "intel_mid_wdt",
>         },
> --
> 2.7.4
>



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 20/62] watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot
  2017-01-10 23:34 ` [PATCH 20/62] watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot Guenter Roeck
@ 2017-01-11 23:36   ` Andy Shevchenko
  0 siblings, 0 replies; 98+ messages in thread
From: Andy Shevchenko @ 2017-01-11 23:36 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel

On Wed, Jan 11, 2017 at 1:34 AM, Guenter Roeck <linux@roeck-us.net> wrote:
> The shutdown function calls the stop function.
> Call watchdog_stop_on_reboot() from probe instead.
>
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
>
> - Replace shutdown function with call to watchdog_stop_on_reboot()
>

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/iTCO_wdt.c | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
> index d8bb7bf5e669..3d0abc0d59b4 100644
> --- a/drivers/watchdog/iTCO_wdt.c
> +++ b/drivers/watchdog/iTCO_wdt.c
> @@ -520,6 +520,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
>                         WATCHDOG_TIMEOUT);
>         }
>
> +       watchdog_stop_on_reboot(&p->wddev);
>         ret = devm_watchdog_register_device(dev, &p->wddev);
>         if (ret != 0) {
>                 pr_err("cannot register watchdog device (err=%d)\n", ret);
> @@ -543,13 +544,6 @@ static int iTCO_wdt_remove(struct platform_device *pdev)
>         return 0;
>  }
>
> -static void iTCO_wdt_shutdown(struct platform_device *pdev)
> -{
> -       struct iTCO_wdt_private *p = platform_get_drvdata(pdev);
> -
> -       iTCO_wdt_stop(&p->wddev);
> -}
> -
>  #ifdef CONFIG_PM_SLEEP
>  /*
>   * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
> @@ -603,7 +597,6 @@ static const struct dev_pm_ops iTCO_wdt_pm = {
>  static struct platform_driver iTCO_wdt_driver = {
>         .probe          = iTCO_wdt_probe,
>         .remove         = iTCO_wdt_remove,
> -       .shutdown       = iTCO_wdt_shutdown,
>         .driver         = {
>                 .name   = DRV_NAME,
>                 .pm     = ITCO_WDT_PM_OPS,
> --
> 2.7.4
>



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 10:52       ` Guenter Roeck
  2017-01-11 12:31         ` Marc Gonzalez
@ 2017-01-12  0:12         ` Andy Shevchenko
  2017-01-12  1:29           ` Guenter Roeck
  1 sibling, 1 reply; 98+ messages in thread
From: Andy Shevchenko @ 2017-01-12  0:12 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Marc Gonzalez, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm Mailing List, Mans Rullgard, Thibaud Cornic

On Wed, Jan 11, 2017 at 12:52 PM, Guenter Roeck <linux@roeck-us.net> wrote:
> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
> Not really. It would just make it more complicated to replace the
> call with devm_clk_prepare_enable(), should it ever find its way
> into the light of day.
Actually what is the status to the patch series which brings devm_clk
stuff like prepare_enable()? It was submitted 2(?) years ago.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 44/62] watchdog: pnx4008_wdt: Convert to use device managed functions
  2017-01-11  0:44   ` [PATCH 44/62] watchdog: pnx4008_wdt: " Guenter Roeck
@ 2017-01-12  0:13     ` Vladimir Zapolskiy
  0 siblings, 0 replies; 98+ messages in thread
From: Vladimir Zapolskiy @ 2017-01-12  0:13 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Sylvain Lemieux, linux-arm-kernel

Hi Guenter,

On 01/11/2017 02:44 AM, Guenter Roeck wrote:
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
> - Replace 'goto l; ... l: return e;' with 'return e;'
> - Drop remove function
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Cc: Vladimir Zapolskiy <vz@mleia.com>

Acked-by: Vladimir Zapolskiy <vz@mleia.com>

Thank you for the cleanup.

> Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

--
With best wishes,
Vladimir

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-12  0:12         ` Andy Shevchenko
@ 2017-01-12  1:29           ` Guenter Roeck
  0 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-12  1:29 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Marc Gonzalez, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm Mailing List, Mans Rullgard, Thibaud Cornic

On 01/11/2017 04:12 PM, Andy Shevchenko wrote:
> On Wed, Jan 11, 2017 at 12:52 PM, Guenter Roeck <linux@roeck-us.net> wrote:
>> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
>> Not really. It would just make it more complicated to replace the
>> call with devm_clk_prepare_enable(), should it ever find its way
>> into the light of day.
> Actually what is the status to the patch series which brings devm_clk
> stuff like prepare_enable()? It was submitted 2(?) years ago.
>

It stalled.

Guenter

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 17:51               ` Guenter Roeck
@ 2017-01-12  9:44                 ` Marc Gonzalez
  2017-01-12  9:57                   ` Uwe Kleine-König
  2017-01-12 11:24                   ` Måns Rullgård
  0 siblings, 2 replies; 98+ messages in thread
From: Marc Gonzalez @ 2017-01-12  9:44 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel,
	Mans Rullgard, Thibaud Cornic, Mark Rutland, Uwe Kleine-Konig,
	Arnd Bergmann

On 11/01/2017 18:51, Guenter Roeck wrote:

> However, some other unrelated undefined behavior does not mean that this
> specific behavior is undefined.

True :-)

Let me just give two additional examples of UB that /have/ bitten
Linux kernel devs.

int i;
for (i = 1; i > 0; ++i)
	/* do_something(); */

=> optimized into an infinite loop

and

void func(struct foo *p) {
	int n = p->field;
	if (!p) return;

=> null-pointer check optimized away

> So far we have a claim that a cast to a void * may somehow be different
> to a cast to a different pointer, if used as function argument, and that
> the behavior with such a cast may be undefined. In other words, you claim
> that a function implemented as, say,
> 
>    void func(int *var) {}
> 
> might result in undefined behavior if some header file declares it as
> 
>     void func(void *);
> 
> and it is called as
> 
>     int var;
> 
>     func(&var);
> 
> That seems really far fetched to me.

Thanks for giving me an opportunity to play the language lawyer :-)

C99 6.3.2.3 sub-clause 8 states:

"A pointer to a function of one type may be converted to a pointer to a function of another
type and back again; the result shall compare equal to the original pointer. If a converted
pointer is used to call a function whose type is not compatible with the pointed-to type,
the behavior is undefined."

So, the behavior is undefined, not when you cast clk_disable_unprepare,
but when clk_disable_unprepare is later called through the devres->action
function pointer.

However, I agree that it will work as expected on typical platforms
(where all pointers are the same size, and the calling convention
treats all pointers the same).

> I do get the message that you do not like this kind of cast. But that doesn't
> mean it is not correct.

If it's already widely used in the kernel, it seems there is no point
fighting it ;-)

Regards.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-12  9:44                 ` Marc Gonzalez
@ 2017-01-12  9:57                   ` Uwe Kleine-König
  2017-01-12 11:24                   ` Måns Rullgård
  1 sibling, 0 replies; 98+ messages in thread
From: Uwe Kleine-König @ 2017-01-12  9:57 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Guenter Roeck, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm-kernel, Mans Rullgard, Thibaud Cornic, Mark Rutland,
	Arnd Bergmann

On Thu, Jan 12, 2017 at 10:44:07AM +0100, Marc Gonzalez wrote:
> On 11/01/2017 18:51, Guenter Roeck wrote:
> 
> > However, some other unrelated undefined behavior does not mean that this
> > specific behavior is undefined.
> 
> True :-)
> 
> Let me just give two additional examples of UB that /have/ bitten
> Linux kernel devs.
> 
> int i;
> for (i = 1; i > 0; ++i)
> 	/* do_something(); */
> 
> => optimized into an infinite loop
> 
> and
> 
> void func(struct foo *p) {
> 	int n = p->field;
> 	if (!p) return;
> 
> => null-pointer check optimized away
> 
> > So far we have a claim that a cast to a void * may somehow be different
> > to a cast to a different pointer, if used as function argument, and that
> > the behavior with such a cast may be undefined. In other words, you claim
> > that a function implemented as, say,
> > 
> >    void func(int *var) {}
> > 
> > might result in undefined behavior if some header file declares it as
> > 
> >     void func(void *);
> > 
> > and it is called as
> > 
> >     int var;
> > 
> >     func(&var);
> > 
> > That seems really far fetched to me.
> 
> Thanks for giving me an opportunity to play the language lawyer :-)
> 
> C99 6.3.2.3 sub-clause 8 states:
> 
> "A pointer to a function of one type may be converted to a pointer to a function of another
> type and back again; the result shall compare equal to the original pointer. If a converted
> pointer is used to call a function whose type is not compatible with the pointed-to type,
> the behavior is undefined."
> 
> So, the behavior is undefined, not when you cast clk_disable_unprepare,
> but when clk_disable_unprepare is later called through the devres->action
> function pointer.
> 
> However, I agree that it will work as expected on typical platforms
> (where all pointers are the same size, and the calling convention
> treats all pointers the same).
> 
> > I do get the message that you do not like this kind of cast. But that doesn't
> > mean it is not correct.
> 
> If it's already widely used in the kernel, it seems there is no point
> fighting it ;-)

I'd say +.5 here (where +1 is an ack). My approach would be to push
devm_clk_prepare_enable and use that. It cannot be that hard, can it?

It looks prettier, is well defined, easier to fit into 80 chars per
line. I wonder why not everybody jubilates on this new function.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 62/62] watchdog: wm831x_wdt: Convert to use device managed functions
  2017-01-11  2:09   ` [PATCH 62/62] watchdog: wm831x_wdt: " Guenter Roeck
@ 2017-01-12 10:04     ` Charles Keepax
  0 siblings, 0 replies; 98+ messages in thread
From: Charles Keepax @ 2017-01-12 10:04 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, patches

On Tue, Jan 10, 2017 at 06:09:16PM -0800, Guenter Roeck wrote:
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Replace 'goto l; ... l: return e;' with 'return e;'
> - Replace 'val = e; return val;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Replace 'if (e) { return expr; }' with 'if (e) return expr;'
> - Drop remove function
> - Drop platform_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Looks good to me:

Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>

Thanks,
Charles

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-12  9:44                 ` Marc Gonzalez
  2017-01-12  9:57                   ` Uwe Kleine-König
@ 2017-01-12 11:24                   ` Måns Rullgård
  2017-01-12 12:15                     ` Marc Gonzalez
  1 sibling, 1 reply; 98+ messages in thread
From: Måns Rullgård @ 2017-01-12 11:24 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Guenter Roeck, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm-kernel, Thibaud Cornic, Mark Rutland, Uwe Kleine-Konig,
	Arnd Bergmann

Marc Gonzalez <marc_gonzalez@sigmadesigns.com> writes:

>> So far we have a claim that a cast to a void * may somehow be different
>> to a cast to a different pointer, if used as function argument, and that
>> the behavior with such a cast may be undefined. In other words, you claim
>> that a function implemented as, say,
>> 
>>    void func(int *var) {}
>> 
>> might result in undefined behavior if some header file declares it as
>> 
>>     void func(void *);
>> 
>> and it is called as
>> 
>>     int var;
>> 
>>     func(&var);
>> 
>> That seems really far fetched to me.
>
> Thanks for giving me an opportunity to play the language lawyer :-)
>
> C99 6.3.2.3 sub-clause 8 states:
>
> "A pointer to a function of one type may be converted to a pointer to
> a function of another type and back again; the result shall compare
> equal to the original pointer. If a converted pointer is used to call
> a function whose type is not compatible with the pointed-to type, the
> behavior is undefined."
>
> So, the behavior is undefined, not when you cast clk_disable_unprepare,
> but when clk_disable_unprepare is later called through the devres->action
> function pointer.

Only if the function types are incompatible.  C99 6.7.5.3 subclause 15:

  For two function types to be compatible, both shall specify compatible
  return types.  Moreover, the parameter type lists, if both are
  present, shall agree in the number of parameters and in use of the
  ellipsis terminator; corresponding parameters shall have compatible
  types.

The question then is whether pointer to void and pointer to struct clk
are compatible types.  6.7.5.1 subclause 2:

  For two pointer types to be compatible, both shall be identically
  qualified and both shall be pointers to compatible types.

6.2.5 subclause 27:

  A pointer to void shall have the same representation and alignment
  requirements as a pointer to a character type. 39)

  39) The same representation and alignment requirements are meant to
      imply interchangeability as arguments to functions, return values
      from functions, and members of unions.

6.3.2.3 subclause 1:

  A pointer to void may be converted to or from a pointer to any
  incomplete or object type.

>From what I can tell, the standard stops just short of declaring pointer
to void compatible with other pointer types.

> However, I agree that it will work as expected on typical platforms
> (where all pointers are the same size, and the calling convention
> treats all pointers the same).

Yes, I don't see how it could possibly go wrong.

-- 
Måns Rullgård

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 16/62] watchdog: digicolor_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 ` [PATCH 16/62] watchdog: digicolor_wdt: " Guenter Roeck
@ 2017-01-12 11:47   ` Baruch Siach
  0 siblings, 0 replies; 98+ messages in thread
From: Baruch Siach @ 2017-01-12 11:47 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel

Hi Guenter,

On Tue, Jan 10, 2017 at 03:34:33PM -0800, Guenter Roeck wrote:
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> Other improvements as listed below.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Replace 'goto l; ... l: return e;' with 'return e;'
> - Replace 'val = e; return val;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Replace 'if (e) { return expr; }' with 'if (e) return expr;'
> - Drop remove function
> - Replace of_iomap() with platform_get_resource() followed by
>   devm_ioremap_resource()
> - Drop platform_set_drvdata()
> - Replace &pdev->dev with dev if 'struct device *dev' is a declared
>   variable
> - Use devm_watchdog_register_driver() to register watchdog device
> - Replace shutdown function with call to watchdog_stop_on_reboot()
> 
> Cc: Baruch Siach <baruch@tkos.co.il>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Acked-by: Baruch Siach <baruch@tkos.co.il>
Tested-by: Baruch Siach <baruch@tkos.co.il>

Thanks,
baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-12 11:24                   ` Måns Rullgård
@ 2017-01-12 12:15                     ` Marc Gonzalez
  0 siblings, 0 replies; 98+ messages in thread
From: Marc Gonzalez @ 2017-01-12 12:15 UTC (permalink / raw)
  To: Mans Rullgard
  Cc: Guenter Roeck, Wim Van Sebroeck, linux-watchdog, linux-kernel,
	linux-arm-kernel, Thibaud Cornic, Mark Rutland, Uwe Kleine-Konig,
	Arnd Bergmann

On 12/01/2017 12:24, Måns Rullgård wrote:

> Marc Gonzalez writes:
> 
>>> So far we have a claim that a cast to a void * may somehow be different
>>> to a cast to a different pointer, if used as function argument, and that
>>> the behavior with such a cast may be undefined. In other words, you claim
>>> that a function implemented as, say,
>>>
>>>    void func(int *var) {}
>>>
>>> might result in undefined behavior if some header file declares it as
>>>
>>>     void func(void *);
>>>
>>> and it is called as
>>>
>>>     int var;
>>>
>>>     func(&var);
>>>
>>> That seems really far fetched to me.
>>
>> Thanks for giving me an opportunity to play the language lawyer :-)
>>
>> C99 6.3.2.3 sub-clause 8 states:
>>
>> "A pointer to a function of one type may be converted to a pointer to
>> a function of another type and back again; the result shall compare
>> equal to the original pointer. If a converted pointer is used to call
>> a function whose type is not compatible with the pointed-to type, the
>> behavior is undefined."
>>
>> So, the behavior is undefined, not when you cast clk_disable_unprepare,
>> but when clk_disable_unprepare is later called through the devres->action
>> function pointer.
> 
> Only if the function types are incompatible.  C99 6.7.5.3 subclause 15:
> 
>   For two function types to be compatible, both shall specify compatible
>   return types.  Moreover, the parameter type lists, if both are
>   present, shall agree in the number of parameters and in use of the
>   ellipsis terminator; corresponding parameters shall have compatible
>   types.
> 
> The question then is whether pointer to void and pointer to struct clk
> are compatible types.

6.2.7 Compatible type and composite type
sub-clause 1

"Two types have compatible type if their types are the same. Additional rules for
determining whether two types are compatible are described in 6.7.2 for type specifiers,
in 6.7.3 for type qualifiers, and in 6.7.5 for declarators."

6.7.5.1 Pointer declarators
sub-clause 2

"For two pointer types to be compatible, both shall be identically qualified and both shall
be pointers to compatible types."

I don't think void and struct clk are compatible types.
AFAIU, conversion and compatibility are two separate subjects.

Regards.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
  2017-01-11 14:39           ` Uwe Kleine-König
  2017-01-11 14:50             ` Vladimir Zapolskiy
  2017-01-11 17:28             ` Guenter Roeck
@ 2017-01-13  5:17             ` Guenter Roeck
  2 siblings, 0 replies; 98+ messages in thread
From: Guenter Roeck @ 2017-01-13  5:17 UTC (permalink / raw)
  To: Uwe Kleine-König, Marc Gonzalez
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, linux-arm-kernel,
	Mans Rullgard, Thibaud Cornic, Mark Rutland, Arnd Bergmann

On 01/11/2017 06:39 AM, Uwe Kleine-König wrote:
> On Wed, Jan 11, 2017 at 01:31:47PM +0100, Marc Gonzalez wrote:
>> On 11/01/2017 11:52, Guenter Roeck wrote:
>>
>>> On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
>>>
>>>>> @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>>>>>  	err = clk_prepare_enable(dev->clk);
>>>>>  	if (err)
>>>>>  		return err;
>>>>> +	err = devm_add_action_or_reset(&pdev->dev,
>>>>> +				       (void(*)(void *))clk_disable_unprepare,
>>>>> +				       dev->clk);
>>>>> +	if (err)
>>>>> +		return err;
>
> This looks wrong. There is no clk_unprepare_disable when
> devm_add_action_or_reset fails.
>
>>>>
>>>> Hello Guenter,
>>>>
>>>> I would rather avoid the function pointer cast.
>>>> How about defining an auxiliary function for the cleanup action?
>>>>
>>>> clk_disable_unprepare() is static inline, so gcc will have to
>>>> define an auxiliary function either way. What do you think?
>>>
>>> Not really. It would just make it more complicated to replace the
>>> call with devm_clk_prepare_enable(), should it ever find its way
>>> into the light of day.
>>
>> More complicated, because the cleanup function will have to be deleted later?
>> The compiler will warn if someone forgets to do that.
>>
>> In my opinion, it's not a good idea to rely on the fact that casting
>> void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected
>> on most platforms. (It has undefined behavior, strictly speaking.)
>
> I would expect it to work on all (Linux) platforms. Anyhow, I wonder if
> there couldn't be found a better solution.
>
> If in the end it looks like the following that would be good I think:
>
> 	clk = devm_clk_get(...);
> 	if (IS_ERR(clk))
> 		...
>
> 	ret = devm_clk_prepare_enable(clk)
> 	if (ret)
> 		return ret;
>

It turns out that at least one static analyzer complains about different
parameter pointer types in situations like this, and at least one embedded
compiler manages to create function names with embedded parameter type
(eg it appends an 'i' to the function name for each integer parameter).

With that, I consider the typecast to be too risky after all. It may work
for all of today's Linux architectures and compilers, but who knows if I
get flooded with static analyzer warnings, and who knows if gcc version
18.0 or binutils 35.0 makes it truly incompatible (following the logic of
"we can, therefore we do"). Since I also dislike the stub function solution,
at least in this situation, I'll drop all patches touching clk_prepare_enable(),
and wait for devm_clk_prepare_enable() to be available.

Guenter

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 30/62] watchdog: mena21_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 ` [PATCH 30/62] watchdog: mena21_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2017-01-13  8:08   ` Johannes Thumshirn
  0 siblings, 0 replies; 98+ messages in thread
From: Johannes Thumshirn @ 2017-01-13  8:08 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-watchdog, linux-kernel, Wim Van Sebroeck

> Am 11.01.2017 12:38 vorm. schrieb "Guenter Roeck" <linux@roeck-us.net>:
>
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> Other improvements as listed below.
>
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
>
> - Replace 'goto l; ... l: return e;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Drop remove function
> - Drop unnecessary mutex_destroy() on allocated data
> - Use devm_watchdog_register_driver() to register watchdog device
>
> Cc: Johannes Thumshirn <morbidrsa@gmail.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Looks good,
Acked-by: Johannes Thumshirn <jth@kernel.org>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 05/62] watchdog: bcm2835_wdt: Convert to use device managed functions and other improvements
  2017-01-10 23:34 ` [PATCH 05/62] watchdog: bcm2835_wdt: " Guenter Roeck
@ 2017-01-14  6:27   ` Eric Anholt
  0 siblings, 0 replies; 98+ messages in thread
From: Eric Anholt @ 2017-01-14  6:27 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Stephen Warren,
	Lee Jones, Florian Fainelli, Ray Jui, Scott Branden,
	bcm-kernel-feedback-list, linux-arm-kernel, linux-rpi-kernel

[-- Attachment #1: Type: text/plain, Size: 1033 bytes --]

Guenter Roeck <linux@roeck-us.net> writes:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> Other improvements as listed below.
>
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
>
> - Drop assignments to otherwise unused variables
> - Replace of_iomap() with platform_get_resource() followed by
>   devm_ioremap_resource()

Every time I see this pattern I wish we had a
devm_ioremap_platform_resource().

> - Replace &pdev->dev with dev if 'struct device *dev' is a declared
>   variable
> - Use devm_watchdog_register_driver() to register watchdog device
> - Replace shutdown function with call to watchdog_stop_on_reboot()

I'm trusting you here that this last change is right.  All the rest of
it looks good:

Acked-by: Eric Anholt <eric@anholt.net>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 98+ messages in thread

* RE: [PATCH 12/62] watchdog: da9055_wdt: Convert to use device managed functions
  2017-01-10 23:34 ` [PATCH 12/62] watchdog: da9055_wdt: " Guenter Roeck
@ 2017-01-17 13:58   ` Adam Thomson
  0 siblings, 0 replies; 98+ messages in thread
From: Adam Thomson @ 2017-01-17 13:58 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Support Opensource

On 10 January 2017 23:34, Guenter Roeck wrote:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Replace 'goto l; ... l: return e;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Drop remove function
> - Drop platform_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Cc: Support Opensource <support.opensource@diasemi.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Acked-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* RE: [PATCH 11/62] watchdog: da9052_wdt: Convert to use device managed functions
  2017-01-10 23:34 ` [PATCH 11/62] watchdog: da9052_wdt: " Guenter Roeck
@ 2017-01-17 14:12   ` Adam Thomson
  0 siblings, 0 replies; 98+ messages in thread
From: Adam Thomson @ 2017-01-17 14:12 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Support Opensource

On 10 January 2017 23:34, Guenter Roeck wrote:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Replace 'goto l; ... l: return e;' with 'return e;'
> - Replace 'val = e; return val;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Replace 'if (e) { return expr; }' with 'if (e) return expr;'
> - Drop remove function
> - Drop platform_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Cc: Support Opensource <support.opensource@diasemi.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Acked-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* RE: [PATCH 13/62] watchdog: da9062_wdt: Convert to use device managed functions
  2017-01-10 23:34 ` [PATCH 13/62] watchdog: da9062_wdt: " Guenter Roeck
@ 2017-01-17 14:17   ` Adam Thomson
  0 siblings, 0 replies; 98+ messages in thread
From: Adam Thomson @ 2017-01-17 14:17 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Support Opensource

On 10 January 2017 23:35, Guenter Roeck wrote:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Replace 'val = e; return val;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Drop remove function
> - Drop dev_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Cc: Support Opensource <support.opensource@diasemi.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Acked-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* RE: [PATCH 14/62] watchdog: da9063_wdt: Convert to use device managed functions
  2017-01-10 23:34 ` [PATCH 14/62] watchdog: da9063_wdt: " Guenter Roeck
@ 2017-01-17 14:19   ` Adam Thomson
  0 siblings, 0 replies; 98+ messages in thread
From: Adam Thomson @ 2017-01-17 14:19 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Support Opensource

On 10 January 2017 23:35, Guenter Roeck wrote:

> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Replace 'val = e; return val;' with 'return e;'
> - Replace 'if (e) return e; return 0;' with 'return e;'
> - Drop assignments to otherwise unused variables
> - Drop unused variables
> - Drop remove function
> - Drop dev_set_drvdata()
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Cc: Support Opensource <support.opensource@diasemi.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Acked-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: [PATCH 57/62] watchdog: tegra_wdt: Convert to use device managed functions
  2017-01-11  2:09   ` [PATCH 57/62] watchdog: tegra_wdt: " Guenter Roeck
@ 2017-01-19 11:04     ` Thierry Reding
  0 siblings, 0 replies; 98+ messages in thread
From: Thierry Reding @ 2017-01-19 11:04 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, Stephen Warren,
	Alexandre Courbot, linux-tegra

[-- Attachment #1: Type: text/plain, Size: 866 bytes --]

On Tue, Jan 10, 2017 at 06:09:11PM -0800, Guenter Roeck wrote:
> Use device managed functions to simplify error handling, reduce
> source code size, improve readability, and reduce the likelyhood of bugs.
> 
> The conversion was done automatically with coccinelle using the
> following semantic patches. The semantic patches and the scripts used
> to generate this commit log are available at
> https://github.com/groeck/coccinelle-patches
> 
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Cc: Stephen Warren <swarren@wwwdotorg.org>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: Alexandre Courbot <gnurou@gmail.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/tegra_wdt.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 98+ messages in thread

end of thread, other threads:[~2017-01-19 11:04 UTC | newest]

Thread overview: 98+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-10 23:34 [PATCH 00/62] watchdog: Convert to use device managed functions Guenter Roeck
2017-01-10 23:34 ` [PATCH 01/62] watchdog: asm9260_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-10 23:34 ` [PATCH 02/62] watchdog: aspeed_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  5:18   ` Joel Stanley
2017-01-10 23:34 ` [PATCH 03/62] watchdog: at91sam9_wdt: " Guenter Roeck
2017-01-10 23:34 ` [PATCH 04/62] watchdog: atlas7_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-10 23:34 ` [PATCH 05/62] watchdog: bcm2835_wdt: " Guenter Roeck
2017-01-14  6:27   ` Eric Anholt
2017-01-10 23:34 ` [PATCH 06/62] watchdog: bcm47xx_wdt: Convert to use device managed functions Guenter Roeck
2017-01-10 23:34 ` [PATCH 07/62] watchdog: bcm7038_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-10 23:34 ` [PATCH 08/62] watchdog: bcm_kona_wdt: " Guenter Roeck
2017-01-10 23:34 ` [PATCH 09/62] watchdog: cadence_wdt: " Guenter Roeck
2017-01-10 23:34 ` [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11 15:48   ` Linus Walleij
2017-01-10 23:34 ` [PATCH 11/62] watchdog: da9052_wdt: " Guenter Roeck
2017-01-17 14:12   ` Adam Thomson
2017-01-10 23:34 ` [PATCH 12/62] watchdog: da9055_wdt: " Guenter Roeck
2017-01-17 13:58   ` Adam Thomson
2017-01-10 23:34 ` [PATCH 13/62] watchdog: da9062_wdt: " Guenter Roeck
2017-01-17 14:17   ` Adam Thomson
2017-01-10 23:34 ` [PATCH 14/62] watchdog: da9063_wdt: " Guenter Roeck
2017-01-17 14:19   ` Adam Thomson
2017-01-10 23:34 ` [PATCH 15/62] watchdog: davinci_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-10 23:34 ` [PATCH 16/62] watchdog: digicolor_wdt: " Guenter Roeck
2017-01-12 11:47   ` Baruch Siach
2017-01-10 23:34 ` [PATCH 17/62] watchdog: dw_wdt: Convert to use device managed functions Guenter Roeck
2017-01-10 23:34 ` [PATCH 18/62] watchdog: ep93xx_wdt: " Guenter Roeck
2017-01-10 23:34 ` [PATCH 19/62] watchdog: gpio_wdt: " Guenter Roeck
2017-01-10 23:34 ` [PATCH 20/62] watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot Guenter Roeck
2017-01-11 23:36   ` Andy Shevchenko
2017-01-10 23:34 ` [PATCH 21/62] watchdog: imgpdc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-10 23:34 ` [PATCH 22/62] watchdog: imx2_wdt: Convert to use device managed functions Guenter Roeck
2017-01-10 23:34 ` [PATCH 23/62] watchdog: intel-mid_wdt: " Guenter Roeck
2017-01-11 23:36   ` Andy Shevchenko
2017-01-10 23:34 ` [PATCH 24/62] watchdog: jz4740_wdt: " Guenter Roeck
2017-01-10 23:34 ` [PATCH 25/62] watchdog: kempld_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-10 23:34 ` [PATCH 26/62] watchdog: loongson1_wdt: Convert to use device managed functions Guenter Roeck
2017-01-10 23:34 ` [PATCH 27/62] watchdog: lpc18xx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-10 23:34 ` [PATCH 28/62] watchdog: max63xx_wdt: Convert to use device managed functions Guenter Roeck
2017-01-10 23:34 ` [PATCH 29/62] watchdog: max77620_wdt: " Guenter Roeck
2017-01-10 23:34 ` [PATCH 30/62] watchdog: mena21_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-13  8:08   ` Johannes Thumshirn
2017-01-11  0:44 ` [PATCH 31/62] watchdog: menf21bmc_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  0:44   ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11  8:42     ` Neil Armstrong
2017-01-11 18:44     ` Kevin Hilman
2017-01-11  0:44   ` [PATCH 33/62] watchdog: meson_wdt: " Guenter Roeck
2017-01-11 18:45     ` Kevin Hilman
2017-01-11  0:44   ` [PATCH 34/62] watchdog: moxart_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  0:44   ` [PATCH 35/62] watchdog: mpc8xxx_wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 36/62] watchdog: mt7621_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11  0:44   ` [PATCH 37/62] watchdog: mtk_wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 38/62] watchdog: nic7018_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  0:44   ` [PATCH 39/62] watchdog: of_xilinx_wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 40/62] watchdog: omap_wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 41/62] watchdog: orion_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11  0:44   ` [PATCH 42/62] watchdog: pic32-dmt: Convert to use device managed functions Guenter Roeck
2017-01-11  0:44   ` [PATCH 43/62] watchdog: pic32-wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 44/62] watchdog: pnx4008_wdt: " Guenter Roeck
2017-01-12  0:13     ` Vladimir Zapolskiy
2017-01-11  0:44   ` [PATCH 45/62] watchdog: qcom-wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 46/62] watchdog: renesas_wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 47/62] watchdog: retu_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11  0:44   ` [PATCH 48/62] watchdog: rt2880_wdt: " Guenter Roeck
2017-01-11  0:44   ` [PATCH 49/62] watchdog: sama5d4_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  0:44   ` [PATCH 50/62] watchdog: sbsa_gwdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11  0:45   ` [PATCH 51/62] watchdog: shwdt: " Guenter Roeck
2017-01-11  2:09 ` [PATCH 52/62] watchdog: sirfsoc_wdt: " Guenter Roeck
2017-01-11  2:09   ` [PATCH 53/62] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  2:09   ` [PATCH 54/62] watchdog: stmp3xxx_rtc_wdt: " Guenter Roeck
2017-01-11  2:09   ` [PATCH 55/62] watchdog: sunxi_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11 12:15     ` Maxime Ripard
2017-01-11  2:09   ` [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  9:07     ` Marc Gonzalez
2017-01-11 10:52       ` Guenter Roeck
2017-01-11 12:31         ` Marc Gonzalez
2017-01-11 14:25           ` Guenter Roeck
2017-01-11 14:43             ` Måns Rullgård
2017-01-11 15:28             ` Marc Gonzalez
2017-01-11 17:51               ` Guenter Roeck
2017-01-12  9:44                 ` Marc Gonzalez
2017-01-12  9:57                   ` Uwe Kleine-König
2017-01-12 11:24                   ` Måns Rullgård
2017-01-12 12:15                     ` Marc Gonzalez
2017-01-11 14:39           ` Uwe Kleine-König
2017-01-11 14:50             ` Vladimir Zapolskiy
2017-01-11 17:28             ` Guenter Roeck
2017-01-13  5:17             ` Guenter Roeck
2017-01-12  0:12         ` Andy Shevchenko
2017-01-12  1:29           ` Guenter Roeck
2017-01-11  2:09   ` [PATCH 57/62] watchdog: tegra_wdt: " Guenter Roeck
2017-01-19 11:04     ` Thierry Reding
2017-01-11  2:09   ` [PATCH 58/62] watchdog: ts4800_wdt: " Guenter Roeck
2017-01-11  2:09   ` [PATCH 59/62] watchdog: twl4030_wdt: " Guenter Roeck
2017-01-11  2:09   ` [PATCH 60/62] watchdog: txx9wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11  2:09   ` [PATCH 61/62] watchdog: ux500_wdt: Convert to use device managed functions Guenter Roeck
2017-01-11  2:09   ` [PATCH 62/62] watchdog: wm831x_wdt: " Guenter Roeck
2017-01-12 10:04     ` Charles Keepax

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).