Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3)
@ 2019-04-09 17:23 Guenter Roeck
  2019-04-09 17:23 ` [PATCH 01/23] watchdog: max77620_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (22 more replies)
  0 siblings, 23 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

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

The changes made in this series can be summarized to

- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_watchdog_register_driver() to register watchdog device
- Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)'
- Drop assignments to otherwise unused variables
- Drop unnecessary braces around conditional return statements
- Drop empty remove function
- Replace shutdown function with call to watchdog_stop_on_reboot()
- Replace stop on remove with call to watchdog_stop_on_unregister()
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'ret = e; return ret;' with 'return e;'.
- Use local variable 'struct device *dev' consistently
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Drop unnecessary calls to platform_set_drvdata()

Conversions were performed automatically with coccinelle using a number
of semantic patches. The semantic patches and the scripts used to generate
commit logs are available at https://github.com/groeck/coccinelle-patches.
All patches were compile tested and manually reviewed.

This is the second of (at least) three series of similar patches for watchdog
drivers.

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

* [PATCH 01/23] watchdog: max77620_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 02/23] watchdog: mena21_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 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 empty remove function
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Replace stop on remove with call to watchdog_stop_on_unregister()
- Use devm_watchdog_register_driver() to register watchdog device

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

diff --git a/drivers/watchdog/max77620_wdt.c b/drivers/watchdog/max77620_wdt.c
index 70c9cd3ba938..3ca6b9337932 100644
--- a/drivers/watchdog/max77620_wdt.c
+++ b/drivers/watchdog/max77620_wdt.c
@@ -112,17 +112,18 @@ static const struct watchdog_ops max77620_wdt_ops = {
 
 static int max77620_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct max77620_wdt *wdt;
 	struct watchdog_device *wdt_dev;
 	unsigned int regval;
 	int ret;
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
-	wdt->dev = &pdev->dev;
-	wdt->rmap = dev_get_regmap(pdev->dev.parent, NULL);
+	wdt->dev = dev;
+	wdt->rmap = dev_get_regmap(dev->parent, NULL);
 	if (!wdt->rmap) {
 		dev_err(wdt->dev, "Failed to get parent regmap\n");
 		return -ENODEV;
@@ -183,25 +184,16 @@ 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);
+	watchdog_stop_on_unregister(wdt_dev);
+	ret = devm_watchdog_register_device(dev, wdt_dev);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "watchdog registration failed: %d\n", ret);
+		dev_err(dev, "watchdog registration failed: %d\n", ret);
 		return ret;
 	}
 
 	return 0;
 }
 
-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;
-}
-
 static const struct platform_device_id max77620_wdt_devtype[] = {
 	{ .name = "max77620-watchdog", },
 	{ },
@@ -213,7 +205,6 @@ static struct platform_driver max77620_wdt_driver = {
 		.name	= "max77620-watchdog",
 	},
 	.probe	= max77620_wdt_probe,
-	.remove	= max77620_wdt_remove,
 	.id_table = max77620_wdt_devtype,
 };
 
-- 
2.7.4


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

* [PATCH 02/23] watchdog: mena21_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
  2019-04-09 17:23 ` [PATCH 01/23] watchdog: max77620_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-11  7:18   ` Johannes Thumshirn
  2019-04-09 17:23 ` [PATCH 03/23] watchdog: menf21bmc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (20 subsequent siblings)
  22 siblings, 1 reply; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Johannes Thumshirn

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatedly.

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

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

diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c
index 6db69883ece6..e9ca4e0e25dc 100644
--- a/drivers/watchdog/mena21_wdt.c
+++ b/drivers/watchdog/mena21_wdt.c
@@ -127,19 +127,20 @@ static struct watchdog_device a21_wdt = {
 
 static int a21_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct a21_wdt_drv *drv;
 	unsigned int reset = 0;
 	int num_gpios;
 	int ret;
 	int i;
 
-	drv = devm_kzalloc(&pdev->dev, sizeof(struct a21_wdt_drv), GFP_KERNEL);
+	drv = devm_kzalloc(dev, sizeof(struct a21_wdt_drv), GFP_KERNEL);
 	if (!drv)
 		return -ENOMEM;
 
-	num_gpios = gpiod_count(&pdev->dev, NULL);
+	num_gpios = gpiod_count(dev, NULL);
 	if (num_gpios != NUM_GPIOS) {
-		dev_err(&pdev->dev, "gpios DT property wrong, got %d want %d",
+		dev_err(dev, "gpios DT property wrong, got %d want %d",
 			num_gpios, NUM_GPIOS);
 		return -ENODEV;
 	}
@@ -152,12 +153,9 @@ static int a21_wdt_probe(struct platform_device *pdev)
 			gflags = GPIOD_ASIS;
 		else
 			gflags = GPIOD_IN;
-		drv->gpios[i] = devm_gpiod_get_index(&pdev->dev, NULL, i,
-						     gflags);
-		if (IS_ERR(drv->gpios[i])) {
-			ret = PTR_ERR(drv->gpios[i]);
-			return ret;
-		}
+		drv->gpios[i] = devm_gpiod_get_index(dev, NULL, i, gflags);
+		if (IS_ERR(drv->gpios[i]))
+			return PTR_ERR(drv->gpios[i]);
 
 		gpiod_set_consumer_name(drv->gpios[i], "MEN A21 Watchdog");
 
@@ -173,10 +171,10 @@ static int a21_wdt_probe(struct platform_device *pdev)
 		}
 	}
 
-	watchdog_init_timeout(&a21_wdt, 30, &pdev->dev);
+	watchdog_init_timeout(&a21_wdt, 30, dev);
 	watchdog_set_nowayout(&a21_wdt, nowayout);
 	watchdog_set_drvdata(&a21_wdt, drv);
-	a21_wdt.parent = &pdev->dev;
+	a21_wdt.parent = dev;
 
 	reset = a21_wdt_get_bootstatus(drv);
 	if (reset == 2)
@@ -189,15 +187,15 @@ static int a21_wdt_probe(struct platform_device *pdev)
 		a21_wdt.bootstatus |= WDIOF_EXTERN2;
 
 	drv->wdt = a21_wdt;
-	dev_set_drvdata(&pdev->dev, drv);
+	dev_set_drvdata(dev, drv);
 
-	ret = devm_watchdog_register_device(&pdev->dev, &a21_wdt);
+	ret = devm_watchdog_register_device(dev, &a21_wdt);
 	if (ret) {
-		dev_err(&pdev->dev, "Cannot register watchdog device\n");
+		dev_err(dev, "Cannot register watchdog device\n");
 		return ret;
 	}
 
-	dev_info(&pdev->dev, "MEN A21 watchdog timer driver enabled\n");
+	dev_info(dev, "MEN A21 watchdog timer driver enabled\n");
 
 	return 0;
 }
-- 
2.7.4


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

* [PATCH 03/23] watchdog: menf21bmc_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
  2019-04-09 17:23 ` [PATCH 01/23] watchdog: max77620_wdt: Convert to use device managed functions and other improvements Guenter Roeck
  2019-04-09 17:23 ` [PATCH 02/23] watchdog: mena21_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 04/23] watchdog: meson_gxbb_wdt: " Guenter Roeck
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 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.
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 empty remove function
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- 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 | 33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/drivers/watchdog/menf21bmc_wdt.c b/drivers/watchdog/menf21bmc_wdt.c
index 3aefddebb386..b1dbff553cdc 100644
--- a/drivers/watchdog/menf21bmc_wdt.c
+++ b/drivers/watchdog/menf21bmc_wdt.c
@@ -117,12 +117,12 @@ static const struct watchdog_ops menf21bmc_wdt_ops = {
 
 static int menf21bmc_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	int ret, bmc_timeout;
 	struct menf21bmc_wdt *drv_data;
-	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+	struct i2c_client *i2c_client = to_i2c_client(dev->parent);
 
-	drv_data = devm_kzalloc(&pdev->dev,
-				sizeof(struct menf21bmc_wdt), GFP_KERNEL);
+	drv_data = devm_kzalloc(dev, sizeof(struct menf21bmc_wdt), GFP_KERNEL);
 	if (!drv_data)
 		return -ENOMEM;
 
@@ -130,7 +130,7 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev)
 	drv_data->wdt.info = &menf21bmc_wdt_info;
 	drv_data->wdt.min_timeout = BMC_WD_TIMEOUT_MIN;
 	drv_data->wdt.max_timeout = BMC_WD_TIMEOUT_MAX;
-	drv_data->wdt.parent = &pdev->dev;
+	drv_data->wdt.parent = dev;
 	drv_data->i2c_client = i2c_client;
 
 	/*
@@ -140,40 +140,28 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev)
 	bmc_timeout = i2c_smbus_read_word_data(drv_data->i2c_client,
 					       BMC_CMD_WD_TIME);
 	if (bmc_timeout < 0) {
-		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
+		dev_err(dev, "failed to get current WDT timeout\n");
 		return bmc_timeout;
 	}
 
-	watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, &pdev->dev);
+	watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, dev);
 	watchdog_set_nowayout(&drv_data->wdt, nowayout);
 	watchdog_set_drvdata(&drv_data->wdt, drv_data);
 	platform_set_drvdata(pdev, drv_data);
 
 	ret = menf21bmc_wdt_set_bootstatus(drv_data);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
+		dev_err(dev, "failed to set Watchdog bootstatus\n");
 		return ret;
 	}
 
-	ret = watchdog_register_device(&drv_data->wdt);
+	ret = devm_watchdog_register_device(dev, &drv_data->wdt);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register Watchdog device\n");
+		dev_err(dev, "failed to register Watchdog device\n");
 		return ret;
 	}
 
-	dev_info(&pdev->dev, "MEN 14F021P00 BMC Watchdog device enabled\n");
-
-	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);
+	dev_info(dev, "MEN 14F021P00 BMC Watchdog device enabled\n");
 
 	return 0;
 }
@@ -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	[flat|nested] 31+ messages in thread

* [PATCH 04/23] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (2 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 03/23] watchdog: menf21bmc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-09 17:23 ` " Guenter Roeck
  2019-04-09 17:23 ` [PATCH 05/23] watchdog: meson_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Kevin Hilman

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 unnecessary braces around conditional return statements
- Drop empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()

Cc: Kevin Hilman <khilman@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/meson_gxbb_wdt.c | 45 +++++++++++++--------------------------
 1 file changed, 15 insertions(+), 30 deletions(-)

diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c
index a8ed75cc9a6e..d17c1a6ed723 100644
--- a/drivers/watchdog/meson_gxbb_wdt.c
+++ b/drivers/watchdog/meson_gxbb_wdt.c
@@ -136,12 +136,18 @@ static const struct of_device_id meson_gxbb_wdt_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, meson_gxbb_wdt_dt_ids);
 
+static void meson_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int meson_gxbb_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct meson_gxbb_wdt *data;
 	int ret;
 
-	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -149,17 +155,21 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(data->reg_base))
 		return PTR_ERR(data->reg_base);
 
-	data->clk = devm_clk_get(&pdev->dev, NULL);
+	data->clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(data->clk))
 		return PTR_ERR(data->clk);
 
 	ret = clk_prepare_enable(data->clk);
 	if (ret)
 		return ret;
+	ret = devm_add_action_or_reset(dev, meson_clk_disable_unprepare,
+				       data->clk);
+	if (ret)
+		return ret;
 
 	platform_set_drvdata(pdev, data);
 
-	data->wdt_dev.parent = &pdev->dev;
+	data->wdt_dev.parent = dev;
 	data->wdt_dev.info = &meson_gxbb_wdt_info;
 	data->wdt_dev.ops = &meson_gxbb_wdt_ops;
 	data->wdt_dev.max_hw_heartbeat_ms = GXBB_WDT_TCNT_SETUP_MASK;
@@ -176,37 +186,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(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	[flat|nested] 31+ messages in thread

* [PATCH 05/23] watchdog: meson_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (3 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 04/23] watchdog: meson_gxbb_wdt: " Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 06/23] watchdog: mlx_wdt: " Guenter Roeck
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Kevin Hilman

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatedly.

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

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

diff --git a/drivers/watchdog/meson_wdt.c b/drivers/watchdog/meson_wdt.c
index 7fc6acb33c7f..01889cef81e1 100644
--- a/drivers/watchdog/meson_wdt.c
+++ b/drivers/watchdog/meson_wdt.c
@@ -164,11 +164,12 @@ MODULE_DEVICE_TABLE(of, meson_wdt_dt_ids);
 
 static int meson_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct meson_wdt_dev *meson_wdt;
 	const struct of_device_id *of_id;
 	int err;
 
-	meson_wdt = devm_kzalloc(&pdev->dev, sizeof(*meson_wdt), GFP_KERNEL);
+	meson_wdt = devm_kzalloc(dev, sizeof(*meson_wdt), GFP_KERNEL);
 	if (!meson_wdt)
 		return -ENOMEM;
 
@@ -176,14 +177,14 @@ static int meson_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(meson_wdt->wdt_base))
 		return PTR_ERR(meson_wdt->wdt_base);
 
-	of_id = of_match_device(meson_wdt_dt_ids, &pdev->dev);
+	of_id = of_match_device(meson_wdt_dt_ids, dev);
 	if (!of_id) {
-		dev_err(&pdev->dev, "Unable to initialize WDT data\n");
+		dev_err(dev, "Unable to initialize WDT data\n");
 		return -ENODEV;
 	}
 	meson_wdt->data = of_id->data;
 
-	meson_wdt->wdt_dev.parent = &pdev->dev;
+	meson_wdt->wdt_dev.parent = dev;
 	meson_wdt->wdt_dev.info = &meson_wdt_info;
 	meson_wdt->wdt_dev.ops = &meson_wdt_ops;
 	meson_wdt->wdt_dev.max_timeout =
@@ -195,18 +196,18 @@ static int meson_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_drvdata(&meson_wdt->wdt_dev, meson_wdt);
 
-	watchdog_init_timeout(&meson_wdt->wdt_dev, timeout, &pdev->dev);
+	watchdog_init_timeout(&meson_wdt->wdt_dev, timeout, dev);
 	watchdog_set_nowayout(&meson_wdt->wdt_dev, nowayout);
 	watchdog_set_restart_priority(&meson_wdt->wdt_dev, 128);
 
 	meson_wdt_stop(&meson_wdt->wdt_dev);
 
 	watchdog_stop_on_reboot(&meson_wdt->wdt_dev);
-	err = devm_watchdog_register_device(&pdev->dev, &meson_wdt->wdt_dev);
+	err = devm_watchdog_register_device(dev, &meson_wdt->wdt_dev);
 	if (err)
 		return err;
 
-	dev_info(&pdev->dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)",
+	dev_info(dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)",
 		 meson_wdt->wdt_dev.timeout, nowayout);
 
 	return 0;
-- 
2.7.4


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

* [PATCH 06/23] watchdog: mlx_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (4 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 05/23] watchdog: meson_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
@ 2019-04-09 17:23 ` " Guenter Roeck
  2019-04-09 17:23 ` [PATCH 07/23] watchdog: moxart_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatedly.

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

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

diff --git a/drivers/watchdog/mlx_wdt.c b/drivers/watchdog/mlx_wdt.c
index 70c2cbf9c993..03b9ac4b99af 100644
--- a/drivers/watchdog/mlx_wdt.c
+++ b/drivers/watchdog/mlx_wdt.c
@@ -233,20 +233,21 @@ static int mlxreg_wdt_init_timeout(struct mlxreg_wdt *wdt,
 
 static int mlxreg_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct mlxreg_core_platform_data *pdata;
 	struct mlxreg_wdt *wdt;
 	int rc;
 
-	pdata = dev_get_platdata(&pdev->dev);
+	pdata = dev_get_platdata(dev);
 	if (!pdata) {
-		dev_err(&pdev->dev, "Failed to get platform data.\n");
+		dev_err(dev, "Failed to get platform data.\n");
 		return -EINVAL;
 	}
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
-	wdt->wdd.parent = &pdev->dev;
+	wdt->wdd.parent = dev;
 	wdt->regmap = pdata->regmap;
 	mlxreg_wdt_config(wdt, pdata);
 
@@ -266,12 +267,11 @@ static int mlxreg_wdt_probe(struct platform_device *pdev)
 		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
 	}
 	mlxreg_wdt_check_card_reset(wdt);
-	rc = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
+	rc = devm_watchdog_register_device(dev, &wdt->wdd);
 
 register_error:
 	if (rc)
-		dev_err(&pdev->dev,
-			"Cannot register watchdog device (err=%d)\n", rc);
+		dev_err(dev, "Cannot register watchdog device (err=%d)\n", rc);
 	return rc;
 }
 
-- 
2.7.4


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

* [PATCH 07/23] watchdog: moxart_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (5 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 06/23] watchdog: mlx_wdt: " Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 08/23] watchdog: mtk_wdt: " Guenter Roeck
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 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 empty remove function
- Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)'
- Use local variable 'struct device *dev' consistently
- Replace stop on remove with call to watchdog_stop_on_unregister()
- Use devm_watchdog_register_driver() to register watchdog device

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

diff --git a/drivers/watchdog/moxart_wdt.c b/drivers/watchdog/moxart_wdt.c
index 740215a247fc..6340a1f5f471 100644
--- a/drivers/watchdog/moxart_wdt.c
+++ b/drivers/watchdog/moxart_wdt.c
@@ -91,7 +91,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 clk *clk;
 	int err;
 	unsigned int max_timeout;
@@ -107,7 +106,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);
@@ -134,7 +133,8 @@ static int moxart_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_drvdata(&moxart_wdt->dev, moxart_wdt);
 
-	err = watchdog_register_device(&moxart_wdt->dev);
+	watchdog_stop_on_unregister(&moxart_wdt->dev);
+	err = devm_watchdog_register_device(dev, &moxart_wdt->dev);
 	if (err)
 		return err;
 
@@ -144,15 +144,6 @@ static int moxart_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int moxart_wdt_remove(struct platform_device *pdev)
-{
-	struct moxart_wdt_dev *moxart_wdt = platform_get_drvdata(pdev);
-
-	moxart_wdt_stop(&moxart_wdt->dev);
-
-	return 0;
-}
-
 static const struct of_device_id moxart_watchdog_match[] = {
 	{ .compatible = "moxa,moxart-watchdog" },
 	{ },
@@ -161,7 +152,6 @@ MODULE_DEVICE_TABLE(of, moxart_watchdog_match);
 
 static struct platform_driver moxart_wdt_driver = {
 	.probe      = moxart_wdt_probe,
-	.remove     = moxart_wdt_remove,
 	.driver     = {
 		.name		= "moxart-watchdog",
 		.of_match_table	= moxart_watchdog_match,
-- 
2.7.4


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

* [PATCH 08/23] watchdog: mtk_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (6 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 07/23] watchdog: moxart_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-09 17:23 ` " Guenter Roeck
  2019-04-09 17:23 ` [PATCH 09/23] watchdog: npcm_wdt: Use local variable 'dev' consistently Guenter Roeck
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 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 assignments to otherwise unused variables
- Drop empty remove function
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- 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 | 33 ++++++++-------------------------
 1 file changed, 8 insertions(+), 25 deletions(-)

diff --git a/drivers/watchdog/mtk_wdt.c b/drivers/watchdog/mtk_wdt.c
index 113a48d54058..9c3d0033260d 100644
--- a/drivers/watchdog/mtk_wdt.c
+++ b/drivers/watchdog/mtk_wdt.c
@@ -153,10 +153,11 @@ static const struct watchdog_ops mtk_wdt_ops = {
 
 static int mtk_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct mtk_wdt_dev *mtk_wdt;
 	int err;
 
-	mtk_wdt = devm_kzalloc(&pdev->dev, sizeof(*mtk_wdt), GFP_KERNEL);
+	mtk_wdt = devm_kzalloc(dev, sizeof(*mtk_wdt), GFP_KERNEL);
 	if (!mtk_wdt)
 		return -ENOMEM;
 
@@ -171,9 +172,9 @@ static int mtk_wdt_probe(struct platform_device *pdev)
 	mtk_wdt->wdt_dev.timeout = WDT_MAX_TIMEOUT;
 	mtk_wdt->wdt_dev.max_timeout = WDT_MAX_TIMEOUT;
 	mtk_wdt->wdt_dev.min_timeout = WDT_MIN_TIMEOUT;
-	mtk_wdt->wdt_dev.parent = &pdev->dev;
+	mtk_wdt->wdt_dev.parent = dev;
 
-	watchdog_init_timeout(&mtk_wdt->wdt_dev, timeout, &pdev->dev);
+	watchdog_init_timeout(&mtk_wdt->wdt_dev, timeout, dev);
 	watchdog_set_nowayout(&mtk_wdt->wdt_dev, nowayout);
 	watchdog_set_restart_priority(&mtk_wdt->wdt_dev, 128);
 
@@ -181,29 +182,13 @@ 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(dev, &mtk_wdt->wdt_dev);
 	if (unlikely(err))
 		return err;
 
-	dev_info(&pdev->dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)\n",
-			mtk_wdt->wdt_dev.timeout, nowayout);
-
-	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);
+	dev_info(dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)\n",
+		 mtk_wdt->wdt_dev.timeout, nowayout);
 
 	return 0;
 }
@@ -245,8 +230,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	[flat|nested] 31+ messages in thread

* [PATCH 09/23] watchdog: npcm_wdt: Use local variable 'dev' consistently
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (7 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 08/23] watchdog: mtk_wdt: " Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Avi Fishman,
	Tomer Maimon, Patrick Venture, Nancy Yuen, Brendan Higgins

Use local variable 'struct device *dev' consistently.

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

Cc: Avi Fishman <avifishman70@gmail.com>
Cc: Tomer Maimon <tmaimon77@gmail.com>
Cc: Patrick Venture <venture@google.com>
Cc: Nancy Yuen <yuenn@google.com>
Cc: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/npcm_wdt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/npcm_wdt.c b/drivers/watchdog/npcm_wdt.c
index 4fce10c145c2..9d6c1689b12c 100644
--- a/drivers/watchdog/npcm_wdt.c
+++ b/drivers/watchdog/npcm_wdt.c
@@ -184,7 +184,7 @@ static int npcm_wdt_probe(struct platform_device *pdev)
 	int irq;
 	int ret;
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -214,8 +214,8 @@ static int npcm_wdt_probe(struct platform_device *pdev)
 		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
 	}
 
-	ret = devm_request_irq(dev, irq, npcm_wdt_interrupt, 0,
-			       "watchdog", wdt);
+	ret = devm_request_irq(dev, irq, npcm_wdt_interrupt, 0, "watchdog",
+			       wdt);
 	if (ret)
 		return ret;
 
-- 
2.7.4


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

* [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (8 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 09/23] watchdog: npcm_wdt: Use local variable 'dev' consistently Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-10  6:38   ` Michal Simek
  2019-04-09 17:23 ` [PATCH 11/23] watchdog: pm8916_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
                   ` (12 subsequent siblings)
  22 siblings, 1 reply; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Michal Simek

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 empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/of_xilinx_wdt.c | 58 ++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
index 5c977164b3e5..03786992b701 100644
--- a/drivers/watchdog/of_xilinx_wdt.c
+++ b/drivers/watchdog/of_xilinx_wdt.c
@@ -151,41 +151,46 @@ static u32 xwdt_selftest(struct xwdt_device *xdev)
 		return XWT_TIMER_FAILED;
 }
 
+static void xwdt_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int xwdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	int rc;
 	u32 pfreq = 0, enable_once = 0;
 	struct xwdt_device *xdev;
 	struct watchdog_device *xilinx_wdt_wdd;
 
-	xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL);
+	xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL);
 	if (!xdev)
 		return -ENOMEM;
 
 	xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd;
 	xilinx_wdt_wdd->info = &xilinx_wdt_ident;
 	xilinx_wdt_wdd->ops = &xilinx_wdt_ops;
-	xilinx_wdt_wdd->parent = &pdev->dev;
+	xilinx_wdt_wdd->parent = dev;
 
 	xdev->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(xdev->base))
 		return PTR_ERR(xdev->base);
 
-	rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval",
+	rc = of_property_read_u32(dev->of_node, "xlnx,wdt-interval",
 				  &xdev->wdt_interval);
 	if (rc)
-		dev_warn(&pdev->dev,
-			 "Parameter \"xlnx,wdt-interval\" not found\n");
+		dev_warn(dev, "Parameter \"xlnx,wdt-interval\" not found\n");
 
-	rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-enable-once",
+	rc = of_property_read_u32(dev->of_node, "xlnx,wdt-enable-once",
 				  &enable_once);
 	if (rc)
-		dev_warn(&pdev->dev,
+		dev_warn(dev,
 			 "Parameter \"xlnx,wdt-enable-once\" not found\n");
 
 	watchdog_set_nowayout(xilinx_wdt_wdd, enable_once);
 
-	xdev->clk = devm_clk_get(&pdev->dev, NULL);
+	xdev->clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(xdev->clk)) {
 		if (PTR_ERR(xdev->clk) != -ENOENT)
 			return PTR_ERR(xdev->clk);
@@ -196,10 +201,10 @@ static int xwdt_probe(struct platform_device *pdev)
 		 */
 		xdev->clk = NULL;
 
-		rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+		rc = of_property_read_u32(dev->of_node, "clock-frequency",
 					  &pfreq);
 		if (rc)
-			dev_warn(&pdev->dev,
+			dev_warn(dev,
 				 "The watchdog clock freq cannot be obtained\n");
 	} else {
 		pfreq = clk_get_rate(xdev->clk);
@@ -218,44 +223,34 @@ static int xwdt_probe(struct platform_device *pdev)
 
 	rc = clk_prepare_enable(xdev->clk);
 	if (rc) {
-		dev_err(&pdev->dev, "unable to enable clock\n");
+		dev_err(dev, "unable to enable clock\n");
 		return rc;
 	}
+	rc = devm_add_action_or_reset(dev, xwdt_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;
+		dev_err(dev, "SelfTest routine error\n");
+		return rc;
 	}
 
-	rc = watchdog_register_device(xilinx_wdt_wdd);
+	rc = devm_watchdog_register_device(dev, xilinx_wdt_wdd);
 	if (rc) {
-		dev_err(&pdev->dev, "Cannot register watchdog (err=%d)\n", rc);
-		goto err_clk_disable;
+		dev_err(dev, "Cannot register watchdog (err=%d)\n", rc);
+		return rc;
 	}
 
 	clk_disable(xdev->clk);
 
-	dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
+	dev_info(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;
 }
 
 /**
@@ -303,7 +298,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	[flat|nested] 31+ messages in thread

* [PATCH 11/23] watchdog: pm8916_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (9 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 12/23] watchdog: qcom-wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatedly.

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

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

diff --git a/drivers/watchdog/pm8916_wdt.c b/drivers/watchdog/pm8916_wdt.c
index 7f10041fcf5b..2d3652004e39 100644
--- a/drivers/watchdog/pm8916_wdt.c
+++ b/drivers/watchdog/pm8916_wdt.c
@@ -132,15 +132,16 @@ static const struct watchdog_ops pm8916_wdt_ops = {
 
 static int pm8916_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct pm8916_wdt *wdt;
 	struct device *parent;
 	int err, irq;
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
-	parent = pdev->dev.parent;
+	parent = dev->parent;
 
 	/*
 	 * The pm8916-pon-wdt is a child of the pon device, which is a child
@@ -150,20 +151,20 @@ static int pm8916_wdt_probe(struct platform_device *pdev)
 	 */
 	wdt->regmap = dev_get_regmap(parent->parent, NULL);
 	if (!wdt->regmap) {
-		dev_err(&pdev->dev, "failed to locate regmap\n");
+		dev_err(dev, "failed to locate regmap\n");
 		return -ENODEV;
 	}
 
 	err = device_property_read_u32(parent, "reg", &wdt->baseaddr);
 	if (err) {
-		dev_err(&pdev->dev, "failed to get pm8916-pon address\n");
+		dev_err(dev, "failed to get pm8916-pon address\n");
 		return err;
 	}
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq > 0) {
-		if (devm_request_irq(&pdev->dev, irq, pm8916_wdt_isr, 0,
-				     "pm8916_wdt", wdt))
+		if (devm_request_irq(dev, irq, pm8916_wdt_isr, 0, "pm8916_wdt",
+				     wdt))
 			irq = 0;
 	}
 
@@ -172,23 +173,23 @@ static int pm8916_wdt_probe(struct platform_device *pdev)
 			   wdt->baseaddr + PON_PMIC_WD_RESET_S2_CTL,
 			   RESET_TYPE_HARD);
 	if (err) {
-		dev_err(&pdev->dev, "failed configure watchdog\n");
+		dev_err(dev, "failed configure watchdog\n");
 		return err;
 	}
 
 	wdt->wdev.info = (irq > 0) ? &pm8916_wdt_pt_ident : &pm8916_wdt_ident,
 	wdt->wdev.ops = &pm8916_wdt_ops,
-	wdt->wdev.parent = &pdev->dev;
+	wdt->wdev.parent = dev;
 	wdt->wdev.min_timeout = PM8916_WDT_MIN_TIMEOUT;
 	wdt->wdev.max_timeout = PM8916_WDT_MAX_TIMEOUT;
 	wdt->wdev.timeout = PM8916_WDT_DEFAULT_TIMEOUT;
 	wdt->wdev.pretimeout = 0;
 	watchdog_set_drvdata(&wdt->wdev, wdt);
 
-	watchdog_init_timeout(&wdt->wdev, 0, &pdev->dev);
+	watchdog_init_timeout(&wdt->wdev, 0, dev);
 	pm8916_wdt_configure_timers(&wdt->wdev);
 
-	return devm_watchdog_register_device(&pdev->dev, &wdt->wdev);
+	return devm_watchdog_register_device(dev, &wdt->wdev);
 }
 
 static const struct of_device_id pm8916_wdt_id_table[] = {
-- 
2.7.4


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

* [PATCH 12/23] watchdog: qcom-wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (10 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 11/23] watchdog: pm8916_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 13/23] watchdog: rn5t618_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Andy Gross, David Brown

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 empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Andy Gross <andy.gross@linaro.org>
Cc: David Brown <david.brown@linaro.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/qcom-wdt.c | 55 +++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 30 deletions(-)

diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c
index 5dfd604477a4..6d29c33b1316 100644
--- a/drivers/watchdog/qcom-wdt.c
+++ b/drivers/watchdog/qcom-wdt.c
@@ -142,22 +142,28 @@ static const struct watchdog_info qcom_wdt_info = {
 	.identity	= KBUILD_MODNAME,
 };
 
+static void qcom_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int qcom_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct qcom_wdt *wdt;
 	struct resource *res;
-	struct device_node *np = pdev->dev.of_node;
+	struct device_node *np = dev->of_node;
 	const u32 *regs;
 	u32 percpu_offset;
 	int ret;
 
-	regs = of_device_get_match_data(&pdev->dev);
+	regs = of_device_get_match_data(dev);
 	if (!regs) {
-		dev_err(&pdev->dev, "Unsupported QCOM WDT module\n");
+		dev_err(dev, "Unsupported QCOM WDT module\n");
 		return -ENODEV;
 	}
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -172,21 +178,25 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	res->start += percpu_offset;
 	res->end += percpu_offset;
 
-	wdt->base = devm_ioremap_resource(&pdev->dev, res);
+	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);
+	wdt->clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(wdt->clk)) {
-		dev_err(&pdev->dev, "failed to get input clock\n");
+		dev_err(dev, "failed to get input clock\n");
 		return PTR_ERR(wdt->clk);
 	}
 
 	ret = clk_prepare_enable(wdt->clk);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to setup clock\n");
+		dev_err(dev, "failed to setup clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(dev, qcom_clk_disable_unprepare,
+				       wdt->clk);
+	if (ret)
+		return ret;
 
 	/*
 	 * We use the clock rate to calculate the max timeout, so ensure it's
@@ -199,16 +209,15 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	wdt->rate = clk_get_rate(wdt->clk);
 	if (wdt->rate == 0 ||
 	    wdt->rate > 0x10000000U) {
-		dev_err(&pdev->dev, "invalid clock rate\n");
-		ret = -EINVAL;
-		goto err_clk_unprepare;
+		dev_err(dev, "invalid clock rate\n");
+		return -EINVAL;
 	}
 
 	wdt->wdd.info = &qcom_wdt_info;
 	wdt->wdd.ops = &qcom_wdt_ops;
 	wdt->wdd.min_timeout = 1;
 	wdt->wdd.max_timeout = 0x10000000U / wdt->rate;
-	wdt->wdd.parent = &pdev->dev;
+	wdt->wdd.parent = dev;
 	wdt->layout = regs;
 
 	if (readl(wdt_addr(wdt, WDT_STS)) & 1)
@@ -220,29 +229,16 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	 * the max instead.
 	 */
 	wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
-	watchdog_init_timeout(&wdt->wdd, 0, &pdev->dev);
+	watchdog_init_timeout(&wdt->wdd, 0, dev);
 
-	ret = watchdog_register_device(&wdt->wdd);
+	ret = devm_watchdog_register_device(dev, &wdt->wdd);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register watchdog\n");
-		goto err_clk_unprepare;
+		dev_err(dev, "failed to register watchdog\n");
+		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;
 }
 
 static int __maybe_unused qcom_wdt_suspend(struct device *dev)
@@ -277,7 +273,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	[flat|nested] 31+ messages in thread

* [PATCH 13/23] watchdog: rn5t618_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (11 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 12/23] watchdog: qcom-wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 14/23] watchdog: rtd119x_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatedly.

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

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

diff --git a/drivers/watchdog/rn5t618_wdt.c b/drivers/watchdog/rn5t618_wdt.c
index e60f55702ab7..21fcb36f9074 100644
--- a/drivers/watchdog/rn5t618_wdt.c
+++ b/drivers/watchdog/rn5t618_wdt.c
@@ -146,11 +146,12 @@ static const struct watchdog_ops rn5t618_wdt_ops = {
 
 static int rn5t618_wdt_probe(struct platform_device *pdev)
 {
-	struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = &pdev->dev;
+	struct rn5t618 *rn5t618 = dev_get_drvdata(dev->parent);
 	struct rn5t618_wdt *wdt;
 	int min_timeout, max_timeout;
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(struct rn5t618_wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(struct rn5t618_wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -163,10 +164,10 @@ static int rn5t618_wdt_probe(struct platform_device *pdev)
 	wdt->wdt_dev.min_timeout = min_timeout;
 	wdt->wdt_dev.max_timeout = max_timeout;
 	wdt->wdt_dev.timeout = max_timeout;
-	wdt->wdt_dev.parent = &pdev->dev;
+	wdt->wdt_dev.parent = dev;
 
 	watchdog_set_drvdata(&wdt->wdt_dev, wdt);
-	watchdog_init_timeout(&wdt->wdt_dev, timeout, &pdev->dev);
+	watchdog_init_timeout(&wdt->wdt_dev, timeout, dev);
 	watchdog_set_nowayout(&wdt->wdt_dev, nowayout);
 
 	platform_set_drvdata(pdev, wdt);
-- 
2.7.4


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

* [PATCH 14/23] watchdog: rtd119x_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (12 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 13/23] watchdog: rn5t618_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 15/23] watchdog: rza_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 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 unnecessary braces around conditional return statements
- Drop empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)'
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device

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

diff --git a/drivers/watchdog/rtd119x_wdt.c b/drivers/watchdog/rtd119x_wdt.c
index cb17c49f3534..c4cb23d65218 100644
--- a/drivers/watchdog/rtd119x_wdt.c
+++ b/drivers/watchdog/rtd119x_wdt.c
@@ -95,12 +95,18 @@ static const struct of_device_id rtd119x_wdt_dt_ids[] = {
 	 { }
 };
 
+static void rtd119x_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int rtd119x_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct rtd119x_watchdog_device *data;
 	int ret;
 
-	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -108,22 +114,24 @@ static int rtd119x_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(data->base))
 		return PTR_ERR(data->base);
 
-	data->clk = of_clk_get(pdev->dev.of_node, 0);
+	data->clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(data->clk))
 		return PTR_ERR(data->clk);
 
 	ret = clk_prepare_enable(data->clk);
-	if (ret) {
-		clk_put(data->clk);
+	if (ret)
+		return ret;
+	ret = devm_add_action_or_reset(dev, rtd119x_clk_disable_unprepare,
+				       data->clk);
+	if (ret)
 		return ret;
-	}
 
 	data->wdt_dev.info = &rtd119x_wdt_info;
 	data->wdt_dev.ops = &rtd119x_wdt_ops;
 	data->wdt_dev.timeout = 120;
 	data->wdt_dev.max_timeout = 0xffffffff / clk_get_rate(data->clk);
 	data->wdt_dev.min_timeout = 1;
-	data->wdt_dev.parent = &pdev->dev;
+	data->wdt_dev.parent = dev;
 
 	watchdog_stop_on_reboot(&data->wdt_dev);
 	watchdog_set_drvdata(&data->wdt_dev, data);
@@ -133,31 +141,11 @@ static int rtd119x_wdt_probe(struct platform_device *pdev)
 	rtd119x_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout);
 	rtd119x_wdt_stop(&data->wdt_dev);
 
-	ret = watchdog_register_device(&data->wdt_dev);
-	if (ret) {
-		clk_disable_unprepare(data->clk);
-		clk_put(data->clk);
-		return ret;
-	}
-
-	return 0;
-}
-
-static int rtd119x_wdt_remove(struct platform_device *pdev)
-{
-	struct rtd119x_watchdog_device *data = platform_get_drvdata(pdev);
-
-	watchdog_unregister_device(&data->wdt_dev);
-
-	clk_disable_unprepare(data->clk);
-	clk_put(data->clk);
-
-	return 0;
+	return devm_watchdog_register_device(dev, &data->wdt_dev);
 }
 
 static struct platform_driver rtd119x_wdt_driver = {
 	.probe = rtd119x_wdt_probe,
-	.remove = rtd119x_wdt_remove,
 	.driver = {
 		.name = "rtd1295-watchdog",
 		.of_match_table	= rtd119x_wdt_dt_ids,
-- 
2.7.4


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

* [PATCH 15/23] watchdog: rza_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (13 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 14/23] watchdog: rtd119x_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 16/23] watchdog: sama5d4_wdt: Convert to use device managed functions and other improvements Guenter Roeck
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatedly.

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

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

diff --git a/drivers/watchdog/rza_wdt.c b/drivers/watchdog/rza_wdt.c
index b854f0aeb3ef..7b6c365f7cd3 100644
--- a/drivers/watchdog/rza_wdt.c
+++ b/drivers/watchdog/rza_wdt.c
@@ -166,11 +166,12 @@ static const struct watchdog_ops rza_wdt_ops = {
 
 static int rza_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct rza_wdt *priv;
 	unsigned long rate;
 	int ret;
 
-	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
@@ -178,21 +179,21 @@ static int rza_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->base))
 		return PTR_ERR(priv->base);
 
-	priv->clk = devm_clk_get(&pdev->dev, NULL);
+	priv->clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(priv->clk))
 		return PTR_ERR(priv->clk);
 
 	rate = clk_get_rate(priv->clk);
 	if (rate < 16384) {
-		dev_err(&pdev->dev, "invalid clock rate (%ld)\n", rate);
+		dev_err(dev, "invalid clock rate (%ld)\n", rate);
 		return -ENOENT;
 	}
 
 	priv->wdev.info = &rza_wdt_ident,
 	priv->wdev.ops = &rza_wdt_ops,
-	priv->wdev.parent = &pdev->dev;
+	priv->wdev.parent = dev;
 
-	priv->cks = (u8)(uintptr_t)of_device_get_match_data(&pdev->dev);
+	priv->cks = (u8)(uintptr_t) of_device_get_match_data(dev);
 	if (priv->cks == CKS_4BIT) {
 		/* Assume slowest clock rate possible (CKS=0xF) */
 		priv->wdev.max_timeout = (DIVIDER_4BIT * U8_MAX) / rate;
@@ -207,19 +208,19 @@ static int rza_wdt_probe(struct platform_device *pdev)
 		 * max_hw_heartbeat_ms.
 		 */
 		priv->wdev.max_hw_heartbeat_ms = (1000 * U8_MAX) / rate;
-		dev_dbg(&pdev->dev, "max hw timeout of %dms\n",
-			 priv->wdev.max_hw_heartbeat_ms);
+		dev_dbg(dev, "max hw timeout of %dms\n",
+			priv->wdev.max_hw_heartbeat_ms);
 	}
 
 	priv->wdev.min_timeout = 1;
 	priv->wdev.timeout = DEFAULT_TIMEOUT;
 
-	watchdog_init_timeout(&priv->wdev, 0, &pdev->dev);
+	watchdog_init_timeout(&priv->wdev, 0, dev);
 	watchdog_set_drvdata(&priv->wdev, priv);
 
-	ret = devm_watchdog_register_device(&pdev->dev, &priv->wdev);
+	ret = devm_watchdog_register_device(dev, &priv->wdev);
 	if (ret)
-		dev_err(&pdev->dev, "Cannot register watchdog device\n");
+		dev_err(dev, "Cannot register watchdog device\n");
 
 	return ret;
 }
-- 
2.7.4


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

* [PATCH 16/23] watchdog: sama5d4_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (14 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 15/23] watchdog: rza_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 17/23] watchdog: sirfsoc_wdt: " Guenter Roeck
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Nicolas Ferre,
	Alexandre Belloni, Ludovic Desroches

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 empty remove function
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Replace stop on remove with call to watchdog_stop_on_unregister()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/sama5d4_wdt.c | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)

diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c
index ea72fa0aa3ec..111695223aae 100644
--- a/drivers/watchdog/sama5d4_wdt.c
+++ b/drivers/watchdog/sama5d4_wdt.c
@@ -199,6 +199,7 @@ static int sama5d4_wdt_init(struct sama5d4_wdt *wdt)
 
 static int sama5d4_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct watchdog_device *wdd;
 	struct sama5d4_wdt *wdt;
 	void __iomem *regs;
@@ -206,7 +207,7 @@ static int sama5d4_wdt_probe(struct platform_device *pdev)
 	u32 timeout;
 	int ret;
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -226,26 +227,25 @@ static int sama5d4_wdt_probe(struct platform_device *pdev)
 
 	wdt->reg_base = regs;
 
-	irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
+	irq = irq_of_parse_and_map(dev->of_node, 0);
 	if (!irq)
-		dev_warn(&pdev->dev, "failed to get IRQ from DT\n");
+		dev_warn(dev, "failed to get IRQ from DT\n");
 
-	ret = of_sama5d4_wdt_init(pdev->dev.of_node, wdt);
+	ret = of_sama5d4_wdt_init(dev->of_node, wdt);
 	if (ret)
 		return ret;
 
 	if ((wdt->mr & AT91_WDT_WDFIEN) && irq) {
-		ret = devm_request_irq(&pdev->dev, irq, sama5d4_wdt_irq_handler,
+		ret = devm_request_irq(dev, irq, sama5d4_wdt_irq_handler,
 				       IRQF_SHARED | IRQF_IRQPOLL |
 				       IRQF_NO_SUSPEND, pdev->name, pdev);
 		if (ret) {
-			dev_err(&pdev->dev,
-				"cannot register interrupt handler\n");
+			dev_err(dev, "cannot register interrupt handler\n");
 			return ret;
 		}
 	}
 
-	watchdog_init_timeout(wdd, wdt_timeout, &pdev->dev);
+	watchdog_init_timeout(wdd, wdt_timeout, dev);
 
 	timeout = WDT_SEC2TICKS(wdd->timeout);
 
@@ -258,31 +258,21 @@ static int sama5d4_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_nowayout(wdd, nowayout);
 
-	ret = watchdog_register_device(wdd);
+	watchdog_stop_on_unregister(wdd);
+	ret = devm_watchdog_register_device(dev, wdd);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register watchdog device\n");
+		dev_err(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",
+	dev_info(dev, "initialized (timeout = %d sec, nowayout = %d)\n",
 		 wdd->timeout, nowayout);
 
 	return 0;
 }
 
-static int sama5d4_wdt_remove(struct platform_device *pdev)
-{
-	struct sama5d4_wdt *wdt = platform_get_drvdata(pdev);
-
-	sama5d4_wdt_stop(&wdt->wdd);
-
-	watchdog_unregister_device(&wdt->wdd);
-
-	return 0;
-}
-
 static const struct of_device_id sama5d4_wdt_of_match[] = {
 	{ .compatible = "atmel,sama5d4-wdt", },
 	{ }
@@ -310,7 +300,6 @@ static SIMPLE_DEV_PM_OPS(sama5d4_wdt_pm_ops, NULL,
 
 static struct platform_driver sama5d4_wdt_driver = {
 	.probe		= sama5d4_wdt_probe,
-	.remove		= sama5d4_wdt_remove,
 	.driver		= {
 		.name	= "sama5d4_wdt",
 		.pm	= &sama5d4_wdt_pm_ops,
-- 
2.7.4


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

* [PATCH 17/23] watchdog: sirfsoc_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (15 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 16/23] watchdog: sama5d4_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-09 17:23 ` " Guenter Roeck
  2019-04-09 17:23 ` [PATCH 18/23] watchdog: 1: " Guenter Roeck
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck, Barry Song

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 empty remove function
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Replace shutdown function with call to watchdog_stop_on_reboot()
- Replace stop on remove with call to watchdog_stop_on_unregister()
- Use devm_watchdog_register_driver() to register watchdog device

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

diff --git a/drivers/watchdog/sirfsoc_wdt.c b/drivers/watchdog/sirfsoc_wdt.c
index 2559062d35da..e79a4097d50b 100644
--- a/drivers/watchdog/sirfsoc_wdt.c
+++ b/drivers/watchdog/sirfsoc_wdt.c
@@ -146,6 +146,7 @@ static struct watchdog_device sirfsoc_wdd = {
 
 static int sirfsoc_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	int ret;
 	void __iomem *base;
 
@@ -155,11 +156,13 @@ static int sirfsoc_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_drvdata(&sirfsoc_wdd, (__force void *)base);
 
-	watchdog_init_timeout(&sirfsoc_wdd, timeout, &pdev->dev);
+	watchdog_init_timeout(&sirfsoc_wdd, timeout, dev);
 	watchdog_set_nowayout(&sirfsoc_wdd, nowayout);
-	sirfsoc_wdd.parent = &pdev->dev;
+	sirfsoc_wdd.parent = dev;
 
-	ret = watchdog_register_device(&sirfsoc_wdd);
+	watchdog_stop_on_reboot(&sirfsoc_wdd);
+	watchdog_stop_on_unregister(&sirfsoc_wdd);
+	ret = devm_watchdog_register_device(dev, &sirfsoc_wdd);
 	if (ret)
 		return ret;
 
@@ -168,19 +171,6 @@ 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);
-	return 0;
-}
-
 #ifdef	CONFIG_PM_SLEEP
 static int sirfsoc_wdt_suspend(struct device *dev)
 {
@@ -218,8 +208,6 @@ static struct platform_driver sirfsoc_wdt_driver = {
 		.of_match_table	= sirfsoc_wdt_of_match,
 	},
 	.probe = sirfsoc_wdt_probe,
-	.remove = sirfsoc_wdt_remove,
-	.shutdown = sirfsoc_wdt_shutdown,
 };
 module_platform_driver(sirfsoc_wdt_driver);
 
-- 
2.7.4


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

* [PATCH 18/23] watchdog: 1: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (16 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 17/23] watchdog: sirfsoc_wdt: " Guenter Roeck
@ 2019-04-09 17:23 ` " Guenter Roeck
  2019-04-09 17:38   ` Guenter Roeck
  2019-04-09 17:23 ` [PATCH 19/23] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
                   ` (4 subsequent siblings)
  22 siblings, 1 reply; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 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 devm_add_action() followed by failure action with
  devm_add_action_or_reset()
- Replace 'val = e; return val;' with 'return e;'
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/sprd_wdt.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/drivers/watchdog/sprd_wdt.c b/drivers/watchdog/sprd_wdt.c
index a63163a93777..14874e9b207b 100644
--- a/drivers/watchdog/sprd_wdt.c
+++ b/drivers/watchdog/sprd_wdt.c
@@ -245,9 +245,7 @@ static u32 sprd_wdt_get_timeleft(struct watchdog_device *wdd)
 	u32 val;
 
 	val = sprd_wdt_get_cnt_value(wdt);
-	val = val / SPRD_WDT_CNT_STEP;
-
-	return val;
+	return val / SPRD_WDT_CNT_STEP;
 }
 
 static const struct watchdog_ops sprd_wdt_ops = {
@@ -269,10 +267,11 @@ static const struct watchdog_info sprd_wdt_info = {
 
 static int sprd_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct sprd_wdt *wdt;
 	int ret;
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -280,57 +279,56 @@ static int sprd_wdt_probe(struct platform_device *pdev)
 	if (IS_ERR(wdt->base))
 		return PTR_ERR(wdt->base);
 
-	wdt->enable = devm_clk_get(&pdev->dev, "enable");
+	wdt->enable = devm_clk_get(dev, "enable");
 	if (IS_ERR(wdt->enable)) {
-		dev_err(&pdev->dev, "can't get the enable clock\n");
+		dev_err(dev, "can't get the enable clock\n");
 		return PTR_ERR(wdt->enable);
 	}
 
-	wdt->rtc_enable = devm_clk_get(&pdev->dev, "rtc_enable");
+	wdt->rtc_enable = devm_clk_get(dev, "rtc_enable");
 	if (IS_ERR(wdt->rtc_enable)) {
-		dev_err(&pdev->dev, "can't get the rtc enable clock\n");
+		dev_err(dev, "can't get the rtc enable clock\n");
 		return PTR_ERR(wdt->rtc_enable);
 	}
 
 	wdt->irq = platform_get_irq(pdev, 0);
 	if (wdt->irq < 0) {
-		dev_err(&pdev->dev, "failed to get IRQ resource\n");
+		dev_err(dev, "failed to get IRQ resource\n");
 		return wdt->irq;
 	}
 
-	ret = devm_request_irq(&pdev->dev, wdt->irq, sprd_wdt_isr,
-			       IRQF_NO_SUSPEND, "sprd-wdt", (void *)wdt);
+	ret = devm_request_irq(dev, wdt->irq, sprd_wdt_isr, IRQF_NO_SUSPEND,
+			       "sprd-wdt", (void *)wdt);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register irq\n");
+		dev_err(dev, "failed to register irq\n");
 		return ret;
 	}
 
 	wdt->wdd.info = &sprd_wdt_info;
 	wdt->wdd.ops = &sprd_wdt_ops;
-	wdt->wdd.parent = &pdev->dev;
+	wdt->wdd.parent = dev;
 	wdt->wdd.min_timeout = SPRD_WDT_MIN_TIMEOUT;
 	wdt->wdd.max_timeout = SPRD_WDT_MAX_TIMEOUT;
 	wdt->wdd.timeout = SPRD_WDT_MAX_TIMEOUT;
 
 	ret = sprd_wdt_enable(wdt);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to enable wdt\n");
+		dev_err(dev, "failed to enable wdt\n");
 		return ret;
 	}
-	ret = devm_add_action(&pdev->dev, sprd_wdt_disable, wdt);
+	ret = devm_add_action_or_reset(dev, sprd_wdt_disable, wdt);
 	if (ret) {
-		sprd_wdt_disable(wdt);
-		dev_err(&pdev->dev, "Failed to add wdt disable action\n");
+		dev_err(dev, "Failed to add wdt disable action\n");
 		return ret;
 	}
 
 	watchdog_set_nowayout(&wdt->wdd, WATCHDOG_NOWAYOUT);
-	watchdog_init_timeout(&wdt->wdd, 0, &pdev->dev);
+	watchdog_init_timeout(&wdt->wdd, 0, dev);
 
-	ret = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
+	ret = devm_watchdog_register_device(dev, &wdt->wdd);
 	if (ret) {
 		sprd_wdt_disable(wdt);
-		dev_err(&pdev->dev, "failed to register watchdog\n");
+		dev_err(dev, "failed to register watchdog\n");
 		return ret;
 	}
 	platform_set_drvdata(pdev, wdt);
-- 
2.7.4


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

* [PATCH 19/23] watchdog: st_lpc_wdt: Convert to use device managed functions
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (17 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 18/23] watchdog: 1: " Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-10  7:26   ` Patrice CHOTARD
  2019-04-09 17:23 ` [PATCH 20/23] watchdog: stmp3xxx_rtc_wdt: " Guenter Roeck
                   ` (3 subsequent siblings)
  22 siblings, 1 reply; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Patrice Chotard

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
- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- 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 | 47 ++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/watchdog/st_lpc_wdt.c b/drivers/watchdog/st_lpc_wdt.c
index 196fb4b72c5d..9a5ed95c3403 100644
--- a/drivers/watchdog/st_lpc_wdt.c
+++ b/drivers/watchdog/st_lpc_wdt.c
@@ -142,10 +142,16 @@ static struct watchdog_device st_wdog_dev = {
 	.ops		= &st_wdog_ops,
 };
 
+static void st_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int st_wdog_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	const struct of_device_id *match;
-	struct device_node *np = pdev->dev.of_node;
+	struct device_node *np = dev->of_node;
 	struct st_wdog *st_wdog;
 	struct regmap *regmap;
 	struct clk *clk;
@@ -155,7 +161,7 @@ static int st_wdog_probe(struct platform_device *pdev)
 
 	ret = of_property_read_u32(np, "st,lpc-mode", &mode);
 	if (ret) {
-		dev_err(&pdev->dev, "An LPC mode must be provided\n");
+		dev_err(dev, "An LPC mode must be provided\n");
 		return -EINVAL;
 	}
 
@@ -163,13 +169,13 @@ static int st_wdog_probe(struct platform_device *pdev)
 	if (mode != ST_LPC_MODE_WDT)
 		return -ENODEV;
 
-	st_wdog = devm_kzalloc(&pdev->dev, sizeof(*st_wdog), GFP_KERNEL);
+	st_wdog = devm_kzalloc(dev, sizeof(*st_wdog), GFP_KERNEL);
 	if (!st_wdog)
 		return -ENOMEM;
 
-	match = of_match_device(st_wdog_match, &pdev->dev);
+	match = of_match_device(st_wdog_match, dev);
 	if (!match) {
-		dev_err(&pdev->dev, "Couldn't match device\n");
+		dev_err(dev, "Couldn't match device\n");
 		return -ENODEV;
 	}
 	st_wdog->syscfg	= (struct st_wdog_syscfg *)match->data;
@@ -180,17 +186,17 @@ static int st_wdog_probe(struct platform_device *pdev)
 
 	regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
 	if (IS_ERR(regmap)) {
-		dev_err(&pdev->dev, "No syscfg phandle specified\n");
+		dev_err(dev, "No syscfg phandle specified\n");
 		return PTR_ERR(regmap);
 	}
 
-	clk = devm_clk_get(&pdev->dev, NULL);
+	clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(clk)) {
-		dev_err(&pdev->dev, "Unable to request clock\n");
+		dev_err(dev, "Unable to request clock\n");
 		return PTR_ERR(clk);
 	}
 
-	st_wdog->dev		= &pdev->dev;
+	st_wdog->dev		= dev;
 	st_wdog->base		= base;
 	st_wdog->clk		= clk;
 	st_wdog->regmap		= regmap;
@@ -198,39 +204,40 @@ static int st_wdog_probe(struct platform_device *pdev)
 	st_wdog->clkrate	= clk_get_rate(st_wdog->clk);
 
 	if (!st_wdog->clkrate) {
-		dev_err(&pdev->dev, "Unable to fetch clock rate\n");
+		dev_err(dev, "Unable to fetch clock rate\n");
 		return -EINVAL;
 	}
 	st_wdog_dev.max_timeout = 0xFFFFFFFF / st_wdog->clkrate;
-	st_wdog_dev.parent = &pdev->dev;
+	st_wdog_dev.parent = dev;
 
 	ret = clk_prepare_enable(clk);
 	if (ret) {
-		dev_err(&pdev->dev, "Unable to enable clock\n");
+		dev_err(dev, "Unable to enable clock\n");
 		return ret;
 	}
+	ret = devm_add_action_or_reset(dev, st_clk_disable_unprepare, clk);
+	if (ret)
+		return ret;
 
 	watchdog_set_drvdata(&st_wdog_dev, st_wdog);
 	watchdog_set_nowayout(&st_wdog_dev, WATCHDOG_NOWAYOUT);
 
 	/* Init Watchdog timeout with value in DT */
-	ret = watchdog_init_timeout(&st_wdog_dev, 0, &pdev->dev);
+	ret = watchdog_init_timeout(&st_wdog_dev, 0, dev);
 	if (ret) {
-		dev_err(&pdev->dev, "Unable to initialise watchdog timeout\n");
-		clk_disable_unprepare(clk);
+		dev_err(dev, "Unable to initialise watchdog timeout\n");
 		return ret;
 	}
 
-	ret = watchdog_register_device(&st_wdog_dev);
+	ret = devm_watchdog_register_device(dev, &st_wdog_dev);
 	if (ret) {
-		dev_err(&pdev->dev, "Unable to register watchdog\n");
-		clk_disable_unprepare(clk);
+		dev_err(dev, "Unable to register watchdog\n");
 		return ret;
 	}
 
 	st_wdog_setup(st_wdog, true);
 
-	dev_info(&pdev->dev, "LPC Watchdog driver registered, reset type is %s",
+	dev_info(dev, "LPC Watchdog driver registered, reset type is %s",
 		 st_wdog->warm_reset ? "warm" : "cold");
 
 	return ret;
@@ -241,8 +248,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	[flat|nested] 31+ messages in thread

* [PATCH 20/23] watchdog: stmp3xxx_rtc_wdt: Convert to use device managed functions
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (18 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 19/23] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
@ 2019-04-09 17:23 ` " Guenter Roeck
  2019-04-09 17:23 ` [PATCH 21/23] watchdog: stpmic1_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Maxime Coquelin,
	Alexandre Torgue

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

- Introduce local variable 'struct device *dev' and use it instead of
  dereferencing it repeatedly
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/stmp3xxx_rtc_wdt.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/watchdog/stmp3xxx_rtc_wdt.c b/drivers/watchdog/stmp3xxx_rtc_wdt.c
index 994c54cc68e9..671f4ba7b4ed 100644
--- a/drivers/watchdog/stmp3xxx_rtc_wdt.c
+++ b/drivers/watchdog/stmp3xxx_rtc_wdt.c
@@ -89,31 +89,31 @@ static struct notifier_block wdt_notifier = {
 
 static int stmp3xxx_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	int ret;
 
-	watchdog_set_drvdata(&stmp3xxx_wdd, &pdev->dev);
+	watchdog_set_drvdata(&stmp3xxx_wdd, dev);
 
 	stmp3xxx_wdd.timeout = clamp_t(unsigned, heartbeat, 1, STMP3XXX_MAX_TIMEOUT);
-	stmp3xxx_wdd.parent = &pdev->dev;
+	stmp3xxx_wdd.parent = dev;
 
-	ret = watchdog_register_device(&stmp3xxx_wdd);
+	ret = devm_watchdog_register_device(dev, &stmp3xxx_wdd);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "cannot register watchdog device\n");
+		dev_err(dev, "cannot register watchdog device\n");
 		return ret;
 	}
 
 	if (register_reboot_notifier(&wdt_notifier))
-		dev_warn(&pdev->dev, "cannot register reboot notifier\n");
+		dev_warn(dev, "cannot register reboot notifier\n");
 
-	dev_info(&pdev->dev, "initialized watchdog with heartbeat %ds\n",
-			stmp3xxx_wdd.timeout);
+	dev_info(dev, "initialized watchdog with heartbeat %ds\n",
+		 stmp3xxx_wdd.timeout);
 	return 0;
 }
 
 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	[flat|nested] 31+ messages in thread

* [PATCH 21/23] watchdog: stpmic1_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (19 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 20/23] watchdog: stmp3xxx_rtc_wdt: " Guenter Roeck
@ 2019-04-09 17:23 ` Guenter Roeck
  2019-04-09 17:24 ` [PATCH 22/23] watchdog: sunxi_wdt: " Guenter Roeck
  2019-04-09 17:24 ` [PATCH 23/23] watchdog: tangox_wdt: Convert to use device managed functions and other improvements Guenter Roeck
  22 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:23 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel, Guenter Roeck

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatedly.

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

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

diff --git a/drivers/watchdog/stpmic1_wdt.c b/drivers/watchdog/stpmic1_wdt.c
index ad431d8ad95f..45d0c543466f 100644
--- a/drivers/watchdog/stpmic1_wdt.c
+++ b/drivers/watchdog/stpmic1_wdt.c
@@ -81,18 +81,19 @@ static const struct watchdog_ops pmic_watchdog_ops = {
 
 static int pmic_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	int ret;
 	struct stpmic1 *pmic;
 	struct stpmic1_wdt *wdt;
 
-	if (!pdev->dev.parent)
+	if (!dev->parent)
 		return -EINVAL;
 
-	pmic = dev_get_drvdata(pdev->dev.parent);
+	pmic = dev_get_drvdata(dev->parent);
 	if (!pmic)
 		return -EINVAL;
 
-	wdt = devm_kzalloc(&pdev->dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(dev, sizeof(struct stpmic1_wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -102,15 +103,15 @@ static int pmic_wdt_probe(struct platform_device *pdev)
 	wdt->wdtdev.ops = &pmic_watchdog_ops;
 	wdt->wdtdev.min_timeout = PMIC_WDT_MIN_TIMEOUT;
 	wdt->wdtdev.max_timeout = PMIC_WDT_MAX_TIMEOUT;
-	wdt->wdtdev.parent = &pdev->dev;
+	wdt->wdtdev.parent = dev;
 
 	wdt->wdtdev.timeout = PMIC_WDT_DEFAULT_TIMEOUT;
-	watchdog_init_timeout(&wdt->wdtdev, 0, &pdev->dev);
+	watchdog_init_timeout(&wdt->wdtdev, 0, dev);
 
 	watchdog_set_nowayout(&wdt->wdtdev, nowayout);
 	watchdog_set_drvdata(&wdt->wdtdev, wdt);
 
-	ret = devm_watchdog_register_device(&pdev->dev, &wdt->wdtdev);
+	ret = devm_watchdog_register_device(dev, &wdt->wdtdev);
 	if (ret)
 		return ret;
 
-- 
2.7.4


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

* [PATCH 22/23] watchdog: sunxi_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (20 preceding siblings ...)
  2019-04-09 17:23 ` [PATCH 21/23] watchdog: stpmic1_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
@ 2019-04-09 17:24 ` " Guenter Roeck
  2019-04-10  7:06   ` Maxime Ripard
  2019-04-09 17:24 ` [PATCH 23/23] watchdog: tangox_wdt: Convert to use device managed functions and other improvements Guenter Roeck
  22 siblings, 1 reply; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:24 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Maxime Ripard, Chen-Yu Tsai

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatedly.

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

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

diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c
index f0e7ef40b1e4..9c22f7753c6b 100644
--- a/drivers/watchdog/sunxi_wdt.c
+++ b/drivers/watchdog/sunxi_wdt.c
@@ -233,14 +233,15 @@ MODULE_DEVICE_TABLE(of, sunxi_wdt_dt_ids);
 
 static int sunxi_wdt_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct sunxi_wdt_dev *sunxi_wdt;
 	int err;
 
-	sunxi_wdt = devm_kzalloc(&pdev->dev, sizeof(*sunxi_wdt), GFP_KERNEL);
+	sunxi_wdt = devm_kzalloc(dev, sizeof(*sunxi_wdt), GFP_KERNEL);
 	if (!sunxi_wdt)
 		return -EINVAL;
 
-	sunxi_wdt->wdt_regs = of_device_get_match_data(&pdev->dev);
+	sunxi_wdt->wdt_regs = of_device_get_match_data(dev);
 	if (!sunxi_wdt->wdt_regs)
 		return -ENODEV;
 
@@ -253,9 +254,9 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	sunxi_wdt->wdt_dev.timeout = WDT_MAX_TIMEOUT;
 	sunxi_wdt->wdt_dev.max_timeout = WDT_MAX_TIMEOUT;
 	sunxi_wdt->wdt_dev.min_timeout = WDT_MIN_TIMEOUT;
-	sunxi_wdt->wdt_dev.parent = &pdev->dev;
+	sunxi_wdt->wdt_dev.parent = dev;
 
-	watchdog_init_timeout(&sunxi_wdt->wdt_dev, timeout, &pdev->dev);
+	watchdog_init_timeout(&sunxi_wdt->wdt_dev, timeout, dev);
 	watchdog_set_nowayout(&sunxi_wdt->wdt_dev, nowayout);
 	watchdog_set_restart_priority(&sunxi_wdt->wdt_dev, 128);
 
@@ -264,12 +265,12 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
 
 	watchdog_stop_on_reboot(&sunxi_wdt->wdt_dev);
-	err = devm_watchdog_register_device(&pdev->dev, &sunxi_wdt->wdt_dev);
+	err = devm_watchdog_register_device(dev, &sunxi_wdt->wdt_dev);
 	if (unlikely(err))
 		return err;
 
-	dev_info(&pdev->dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)",
-			sunxi_wdt->wdt_dev.timeout, nowayout);
+	dev_info(dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)",
+		 sunxi_wdt->wdt_dev.timeout, nowayout);
 
 	return 0;
 }
-- 
2.7.4


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

* [PATCH 23/23] watchdog: tangox_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
                   ` (21 preceding siblings ...)
  2019-04-09 17:24 ` [PATCH 22/23] watchdog: sunxi_wdt: " Guenter Roeck
@ 2019-04-09 17:24 ` Guenter Roeck
  2019-04-10 11:20   ` Måns Rullgård
  22 siblings, 1 reply; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:24 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Guenter Roeck, Marc Gonzalez,
	Mans Rullgard

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 unnecessary braces around conditional return statements
- Drop empty remove function
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace stop on remove with call to watchdog_stop_on_unregister()
- Use devm_watchdog_register_driver() to register watchdog device

Cc: Marc Gonzalez <marc.w.gonzalez@free.fr>
Cc: Mans Rullgard <mans@mansr.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/watchdog/tangox_wdt.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c
index 16611fe0d9d1..1afb0e9d808c 100644
--- a/drivers/watchdog/tangox_wdt.c
+++ b/drivers/watchdog/tangox_wdt.c
@@ -108,6 +108,11 @@ static const struct watchdog_ops tangox_wdt_ops = {
 	.restart	= tangox_wdt_restart,
 };
 
+static void tangox_clk_disable_unprepare(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int tangox_wdt_probe(struct platform_device *pdev)
 {
 	struct tangox_wdt_device *dev;
@@ -129,12 +134,14 @@ 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,
+				       tangox_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;
@@ -168,31 +175,16 @@ static int tangox_wdt_probe(struct platform_device *pdev)
 
 	watchdog_set_restart_priority(&dev->wdt, 128);
 
-	err = watchdog_register_device(&dev->wdt);
+	watchdog_stop_on_unregister(&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)
-{
-	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;
 }
 
 static const struct of_device_id tangox_wdt_dt_ids[] = {
@@ -204,7 +196,6 @@ MODULE_DEVICE_TABLE(of, tangox_wdt_dt_ids);
 
 static struct platform_driver tangox_wdt_driver = {
 	.probe	= tangox_wdt_probe,
-	.remove	= tangox_wdt_remove,
 	.driver	= {
 		.name		= "tangox-wdt",
 		.of_match_table	= tangox_wdt_dt_ids,
-- 
2.7.4


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

* Re: [PATCH 18/23] watchdog: 1: Convert to use device managed functions and other improvements
  2019-04-09 17:23 ` [PATCH 18/23] watchdog: 1: " Guenter Roeck
@ 2019-04-09 17:38   ` Guenter Roeck
  0 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-09 17:38 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel

On Tue, Apr 09, 2019 at 10:23:56AM -0700, 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 devm_add_action() followed by failure action with
>   devm_add_action_or_reset()
> - Replace 'val = e; return val;' with 'return e;'
> - Introduce local variable 'struct device *dev' and use it instead of
>   dereferencing it repeatedly
> - Use devm_watchdog_register_driver() to register watchdog device
> 
Hmm, something went wrong with the subject line. Should have been
"watchdog: sprd_wdt:". Sorry for that.

Guenter

> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/sprd_wdt.c | 38 ++++++++++++++++++--------------------
>  1 file changed, 18 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/watchdog/sprd_wdt.c b/drivers/watchdog/sprd_wdt.c
> index a63163a93777..14874e9b207b 100644
> --- a/drivers/watchdog/sprd_wdt.c
> +++ b/drivers/watchdog/sprd_wdt.c
> @@ -245,9 +245,7 @@ static u32 sprd_wdt_get_timeleft(struct watchdog_device *wdd)
>  	u32 val;
>  
>  	val = sprd_wdt_get_cnt_value(wdt);
> -	val = val / SPRD_WDT_CNT_STEP;
> -
> -	return val;
> +	return val / SPRD_WDT_CNT_STEP;
>  }
>  
>  static const struct watchdog_ops sprd_wdt_ops = {
> @@ -269,10 +267,11 @@ static const struct watchdog_info sprd_wdt_info = {
>  
>  static int sprd_wdt_probe(struct platform_device *pdev)
>  {
> +	struct device *dev = &pdev->dev;
>  	struct sprd_wdt *wdt;
>  	int ret;
>  
> -	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
> +	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
>  	if (!wdt)
>  		return -ENOMEM;
>  
> @@ -280,57 +279,56 @@ static int sprd_wdt_probe(struct platform_device *pdev)
>  	if (IS_ERR(wdt->base))
>  		return PTR_ERR(wdt->base);
>  
> -	wdt->enable = devm_clk_get(&pdev->dev, "enable");
> +	wdt->enable = devm_clk_get(dev, "enable");
>  	if (IS_ERR(wdt->enable)) {
> -		dev_err(&pdev->dev, "can't get the enable clock\n");
> +		dev_err(dev, "can't get the enable clock\n");
>  		return PTR_ERR(wdt->enable);
>  	}
>  
> -	wdt->rtc_enable = devm_clk_get(&pdev->dev, "rtc_enable");
> +	wdt->rtc_enable = devm_clk_get(dev, "rtc_enable");
>  	if (IS_ERR(wdt->rtc_enable)) {
> -		dev_err(&pdev->dev, "can't get the rtc enable clock\n");
> +		dev_err(dev, "can't get the rtc enable clock\n");
>  		return PTR_ERR(wdt->rtc_enable);
>  	}
>  
>  	wdt->irq = platform_get_irq(pdev, 0);
>  	if (wdt->irq < 0) {
> -		dev_err(&pdev->dev, "failed to get IRQ resource\n");
> +		dev_err(dev, "failed to get IRQ resource\n");
>  		return wdt->irq;
>  	}
>  
> -	ret = devm_request_irq(&pdev->dev, wdt->irq, sprd_wdt_isr,
> -			       IRQF_NO_SUSPEND, "sprd-wdt", (void *)wdt);
> +	ret = devm_request_irq(dev, wdt->irq, sprd_wdt_isr, IRQF_NO_SUSPEND,
> +			       "sprd-wdt", (void *)wdt);
>  	if (ret) {
> -		dev_err(&pdev->dev, "failed to register irq\n");
> +		dev_err(dev, "failed to register irq\n");
>  		return ret;
>  	}
>  
>  	wdt->wdd.info = &sprd_wdt_info;
>  	wdt->wdd.ops = &sprd_wdt_ops;
> -	wdt->wdd.parent = &pdev->dev;
> +	wdt->wdd.parent = dev;
>  	wdt->wdd.min_timeout = SPRD_WDT_MIN_TIMEOUT;
>  	wdt->wdd.max_timeout = SPRD_WDT_MAX_TIMEOUT;
>  	wdt->wdd.timeout = SPRD_WDT_MAX_TIMEOUT;
>  
>  	ret = sprd_wdt_enable(wdt);
>  	if (ret) {
> -		dev_err(&pdev->dev, "failed to enable wdt\n");
> +		dev_err(dev, "failed to enable wdt\n");
>  		return ret;
>  	}
> -	ret = devm_add_action(&pdev->dev, sprd_wdt_disable, wdt);
> +	ret = devm_add_action_or_reset(dev, sprd_wdt_disable, wdt);
>  	if (ret) {
> -		sprd_wdt_disable(wdt);
> -		dev_err(&pdev->dev, "Failed to add wdt disable action\n");
> +		dev_err(dev, "Failed to add wdt disable action\n");
>  		return ret;
>  	}
>  
>  	watchdog_set_nowayout(&wdt->wdd, WATCHDOG_NOWAYOUT);
> -	watchdog_init_timeout(&wdt->wdd, 0, &pdev->dev);
> +	watchdog_init_timeout(&wdt->wdd, 0, dev);
>  
> -	ret = devm_watchdog_register_device(&pdev->dev, &wdt->wdd);
> +	ret = devm_watchdog_register_device(dev, &wdt->wdd);
>  	if (ret) {
>  		sprd_wdt_disable(wdt);
> -		dev_err(&pdev->dev, "failed to register watchdog\n");
> +		dev_err(dev, "failed to register watchdog\n");
>  		return ret;
>  	}
>  	platform_set_drvdata(pdev, wdt);

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

* Re: [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:23 ` [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-10  6:38   ` Michal Simek
  2019-04-10 12:09     ` Guenter Roeck
  0 siblings, 1 reply; 31+ messages in thread
From: Michal Simek @ 2019-04-10  6:38 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck
  Cc: linux-watchdog, linux-kernel, Michal Simek

On 09. 04. 19 19:23, 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 empty remove function
> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
> - Introduce local variable 'struct device *dev' and use it instead of
>   dereferencing it repeatedly
> - Use devm_watchdog_register_driver() to register watchdog device
> 
> Cc: Michal Simek <michal.simek@xilinx.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/of_xilinx_wdt.c | 58 ++++++++++++++++++----------------------
>  1 file changed, 26 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
> index 5c977164b3e5..03786992b701 100644
> --- a/drivers/watchdog/of_xilinx_wdt.c
> +++ b/drivers/watchdog/of_xilinx_wdt.c
> @@ -151,41 +151,46 @@ static u32 xwdt_selftest(struct xwdt_device *xdev)
>  		return XWT_TIMER_FAILED;
>  }
>  
> +static void xwdt_clk_disable_unprepare(void *data)
> +{
> +	clk_disable_unprepare(data);
> +}
> +
>  static int xwdt_probe(struct platform_device *pdev)
>  {
> +	struct device *dev = &pdev->dev;
>  	int rc;
>  	u32 pfreq = 0, enable_once = 0;
>  	struct xwdt_device *xdev;
>  	struct watchdog_device *xilinx_wdt_wdd;
>  
> -	xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL);
> +	xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL);
>  	if (!xdev)
>  		return -ENOMEM;
>  
>  	xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd;
>  	xilinx_wdt_wdd->info = &xilinx_wdt_ident;
>  	xilinx_wdt_wdd->ops = &xilinx_wdt_ops;
> -	xilinx_wdt_wdd->parent = &pdev->dev;
> +	xilinx_wdt_wdd->parent = dev;
>  
>  	xdev->base = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(xdev->base))
>  		return PTR_ERR(xdev->base);
>  
> -	rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval",
> +	rc = of_property_read_u32(dev->of_node, "xlnx,wdt-interval",
>  				  &xdev->wdt_interval);
>  	if (rc)
> -		dev_warn(&pdev->dev,
> -			 "Parameter \"xlnx,wdt-interval\" not found\n");
> +		dev_warn(dev, "Parameter \"xlnx,wdt-interval\" not found\n");
>  
> -	rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-enable-once",
> +	rc = of_property_read_u32(dev->of_node, "xlnx,wdt-enable-once",
>  				  &enable_once);
>  	if (rc)
> -		dev_warn(&pdev->dev,
> +		dev_warn(dev,
>  			 "Parameter \"xlnx,wdt-enable-once\" not found\n");
>  
>  	watchdog_set_nowayout(xilinx_wdt_wdd, enable_once);
>  
> -	xdev->clk = devm_clk_get(&pdev->dev, NULL);
> +	xdev->clk = devm_clk_get(dev, NULL);
>  	if (IS_ERR(xdev->clk)) {
>  		if (PTR_ERR(xdev->clk) != -ENOENT)
>  			return PTR_ERR(xdev->clk);
> @@ -196,10 +201,10 @@ static int xwdt_probe(struct platform_device *pdev)
>  		 */
>  		xdev->clk = NULL;
>  
> -		rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
> +		rc = of_property_read_u32(dev->of_node, "clock-frequency",
>  					  &pfreq);
>  		if (rc)
> -			dev_warn(&pdev->dev,
> +			dev_warn(dev,
>  				 "The watchdog clock freq cannot be obtained\n");
>  	} else {
>  		pfreq = clk_get_rate(xdev->clk);
> @@ -218,44 +223,34 @@ static int xwdt_probe(struct platform_device *pdev)
>  
>  	rc = clk_prepare_enable(xdev->clk);
>  	if (rc) {
> -		dev_err(&pdev->dev, "unable to enable clock\n");
> +		dev_err(dev, "unable to enable clock\n");
>  		return rc;
>  	}
> +	rc = devm_add_action_or_reset(dev, xwdt_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;
> +		dev_err(dev, "SelfTest routine error\n");
> +		return rc;
>  	}
>  
> -	rc = watchdog_register_device(xilinx_wdt_wdd);
> +	rc = devm_watchdog_register_device(dev, xilinx_wdt_wdd);
>  	if (rc) {
> -		dev_err(&pdev->dev, "Cannot register watchdog (err=%d)\n", rc);
> -		goto err_clk_disable;
> +		dev_err(dev, "Cannot register watchdog (err=%d)\n", rc);
> +		return rc;
>  	}
>  
>  	clk_disable(xdev->clk);
>  
> -	dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
> +	dev_info(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;
>  }
>  
>  /**
> @@ -303,7 +298,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,
> 

Looks good to me. I would prefer to do it via 3 patches but I will let
Wim to comment.

Acked-by: Michal Simek <michal.simek@xilinx.com>

Thanks,
Michal

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

* Re: [PATCH 22/23] watchdog: sunxi_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:24 ` [PATCH 22/23] watchdog: sunxi_wdt: " Guenter Roeck
@ 2019-04-10  7:06   ` Maxime Ripard
  0 siblings, 0 replies; 31+ messages in thread
From: Maxime Ripard @ 2019-04-10  7:06 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, Chen-Yu Tsai

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

On Tue, Apr 09, 2019 at 10:24:00AM -0700, Guenter Roeck wrote:
> Introduce local variable 'struct device *dev' and use it instead of
> dereferencing it repeatedly.
>
> 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
>
> Cc: Maxime Ripard <maxime.ripard@bootlin.com>
> Cc: Chen-Yu Tsai <wens@csie.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

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

Maxime

--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

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

* Re: [PATCH 19/23] watchdog: st_lpc_wdt: Convert to use device managed functions
  2019-04-09 17:23 ` [PATCH 19/23] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
@ 2019-04-10  7:26   ` Patrice CHOTARD
  0 siblings, 0 replies; 31+ messages in thread
From: Patrice CHOTARD @ 2019-04-10  7:26 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel

Hi Guenter

On 4/9/19 7:23 PM, 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
> - Introduce local variable 'struct device *dev' and use it instead of
>   dereferencing it repeatedly
> - 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 | 47 ++++++++++++++++++++++++-------------------
>  1 file changed, 26 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/watchdog/st_lpc_wdt.c b/drivers/watchdog/st_lpc_wdt.c
> index 196fb4b72c5d..9a5ed95c3403 100644
> --- a/drivers/watchdog/st_lpc_wdt.c
> +++ b/drivers/watchdog/st_lpc_wdt.c
> @@ -142,10 +142,16 @@ static struct watchdog_device st_wdog_dev = {
>  	.ops		= &st_wdog_ops,
>  };
>  
> +static void st_clk_disable_unprepare(void *data)
> +{
> +	clk_disable_unprepare(data);
> +}
> +
>  static int st_wdog_probe(struct platform_device *pdev)
>  {
> +	struct device *dev = &pdev->dev;
>  	const struct of_device_id *match;
> -	struct device_node *np = pdev->dev.of_node;
> +	struct device_node *np = dev->of_node;
>  	struct st_wdog *st_wdog;
>  	struct regmap *regmap;
>  	struct clk *clk;
> @@ -155,7 +161,7 @@ static int st_wdog_probe(struct platform_device *pdev)
>  
>  	ret = of_property_read_u32(np, "st,lpc-mode", &mode);
>  	if (ret) {
> -		dev_err(&pdev->dev, "An LPC mode must be provided\n");
> +		dev_err(dev, "An LPC mode must be provided\n");
>  		return -EINVAL;
>  	}
>  
> @@ -163,13 +169,13 @@ static int st_wdog_probe(struct platform_device *pdev)
>  	if (mode != ST_LPC_MODE_WDT)
>  		return -ENODEV;
>  
> -	st_wdog = devm_kzalloc(&pdev->dev, sizeof(*st_wdog), GFP_KERNEL);
> +	st_wdog = devm_kzalloc(dev, sizeof(*st_wdog), GFP_KERNEL);
>  	if (!st_wdog)
>  		return -ENOMEM;
>  
> -	match = of_match_device(st_wdog_match, &pdev->dev);
> +	match = of_match_device(st_wdog_match, dev);
>  	if (!match) {
> -		dev_err(&pdev->dev, "Couldn't match device\n");
> +		dev_err(dev, "Couldn't match device\n");
>  		return -ENODEV;
>  	}
>  	st_wdog->syscfg	= (struct st_wdog_syscfg *)match->data;
> @@ -180,17 +186,17 @@ static int st_wdog_probe(struct platform_device *pdev)
>  
>  	regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
>  	if (IS_ERR(regmap)) {
> -		dev_err(&pdev->dev, "No syscfg phandle specified\n");
> +		dev_err(dev, "No syscfg phandle specified\n");
>  		return PTR_ERR(regmap);
>  	}
>  
> -	clk = devm_clk_get(&pdev->dev, NULL);
> +	clk = devm_clk_get(dev, NULL);
>  	if (IS_ERR(clk)) {
> -		dev_err(&pdev->dev, "Unable to request clock\n");
> +		dev_err(dev, "Unable to request clock\n");
>  		return PTR_ERR(clk);
>  	}
>  
> -	st_wdog->dev		= &pdev->dev;
> +	st_wdog->dev		= dev;
>  	st_wdog->base		= base;
>  	st_wdog->clk		= clk;
>  	st_wdog->regmap		= regmap;
> @@ -198,39 +204,40 @@ static int st_wdog_probe(struct platform_device *pdev)
>  	st_wdog->clkrate	= clk_get_rate(st_wdog->clk);
>  
>  	if (!st_wdog->clkrate) {
> -		dev_err(&pdev->dev, "Unable to fetch clock rate\n");
> +		dev_err(dev, "Unable to fetch clock rate\n");
>  		return -EINVAL;
>  	}
>  	st_wdog_dev.max_timeout = 0xFFFFFFFF / st_wdog->clkrate;
> -	st_wdog_dev.parent = &pdev->dev;
> +	st_wdog_dev.parent = dev;
>  
>  	ret = clk_prepare_enable(clk);
>  	if (ret) {
> -		dev_err(&pdev->dev, "Unable to enable clock\n");
> +		dev_err(dev, "Unable to enable clock\n");
>  		return ret;
>  	}
> +	ret = devm_add_action_or_reset(dev, st_clk_disable_unprepare, clk);
> +	if (ret)
> +		return ret;
>  
>  	watchdog_set_drvdata(&st_wdog_dev, st_wdog);
>  	watchdog_set_nowayout(&st_wdog_dev, WATCHDOG_NOWAYOUT);
>  
>  	/* Init Watchdog timeout with value in DT */
> -	ret = watchdog_init_timeout(&st_wdog_dev, 0, &pdev->dev);
> +	ret = watchdog_init_timeout(&st_wdog_dev, 0, dev);
>  	if (ret) {
> -		dev_err(&pdev->dev, "Unable to initialise watchdog timeout\n");
> -		clk_disable_unprepare(clk);
> +		dev_err(dev, "Unable to initialise watchdog timeout\n");
>  		return ret;
>  	}
>  
> -	ret = watchdog_register_device(&st_wdog_dev);
> +	ret = devm_watchdog_register_device(dev, &st_wdog_dev);
>  	if (ret) {
> -		dev_err(&pdev->dev, "Unable to register watchdog\n");
> -		clk_disable_unprepare(clk);
> +		dev_err(dev, "Unable to register watchdog\n");
>  		return ret;
>  	}
>  
>  	st_wdog_setup(st_wdog, true);
>  
> -	dev_info(&pdev->dev, "LPC Watchdog driver registered, reset type is %s",
> +	dev_info(dev, "LPC Watchdog driver registered, reset type is %s",
>  		 st_wdog->warm_reset ? "warm" : "cold");
>  
>  	return ret;
> @@ -241,8 +248,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;
>  }
> 

Acked-by: Patrice Chotard <patrice.chotard@st.com>

Thanks

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

* Re: [PATCH 23/23] watchdog: tangox_wdt: Convert to use device managed functions and other improvements
  2019-04-09 17:24 ` [PATCH 23/23] watchdog: tangox_wdt: Convert to use device managed functions and other improvements Guenter Roeck
@ 2019-04-10 11:20   ` Måns Rullgård
  0 siblings, 0 replies; 31+ messages in thread
From: Måns Rullgård @ 2019-04-10 11:20 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, Marc Gonzalez

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 unnecessary braces around conditional return statements
> - Drop empty remove function
> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
> - Replace stop on remove with call to watchdog_stop_on_unregister()
> - Use devm_watchdog_register_driver() to register watchdog device
>
> Cc: Marc Gonzalez <marc.w.gonzalez@free.fr>
> Cc: Mans Rullgard <mans@mansr.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/watchdog/tangox_wdt.c | 37 ++++++++++++++-----------------------
>  1 file changed, 14 insertions(+), 23 deletions(-)

Acked-by: Mans Rullgard <mans@mansr.com>

> diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c
> index 16611fe0d9d1..1afb0e9d808c 100644
> --- a/drivers/watchdog/tangox_wdt.c
> +++ b/drivers/watchdog/tangox_wdt.c
> @@ -108,6 +108,11 @@ static const struct watchdog_ops tangox_wdt_ops = {
>  	.restart	= tangox_wdt_restart,
>  };
>
> +static void tangox_clk_disable_unprepare(void *data)
> +{
> +	clk_disable_unprepare(data);
> +}
> +
>  static int tangox_wdt_probe(struct platform_device *pdev)
>  {
>  	struct tangox_wdt_device *dev;
> @@ -129,12 +134,14 @@ 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,
> +				       tangox_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;
> @@ -168,31 +175,16 @@ static int tangox_wdt_probe(struct platform_device *pdev)
>
>  	watchdog_set_restart_priority(&dev->wdt, 128);
>
> -	err = watchdog_register_device(&dev->wdt);
> +	watchdog_stop_on_unregister(&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)
> -{
> -	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;
>  }
>
>  static const struct of_device_id tangox_wdt_dt_ids[] = {
> @@ -204,7 +196,6 @@ MODULE_DEVICE_TABLE(of, tangox_wdt_dt_ids);
>
>  static struct platform_driver tangox_wdt_driver = {
>  	.probe	= tangox_wdt_probe,
> -	.remove	= tangox_wdt_remove,
>  	.driver	= {
>  		.name		= "tangox-wdt",
>  		.of_match_table	= tangox_wdt_dt_ids,
> -- 
> 2.7.4
>

-- 
Måns Rullgård

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

* Re: [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device managed functions and other improvements
  2019-04-10  6:38   ` Michal Simek
@ 2019-04-10 12:09     ` Guenter Roeck
  0 siblings, 0 replies; 31+ messages in thread
From: Guenter Roeck @ 2019-04-10 12:09 UTC (permalink / raw)
  To: Michal Simek, Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel

On 4/9/19 11:38 PM, Michal Simek wrote:
> On 09. 04. 19 19:23, 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 empty remove function
>> - Use devm_add_action_or_reset() for calls to clk_disable_unprepare
>> - Introduce local variable 'struct device *dev' and use it instead of
>>    dereferencing it repeatedly
>> - Use devm_watchdog_register_driver() to register watchdog device
>>
>> Cc: Michal Simek <michal.simek@xilinx.com>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>>   drivers/watchdog/of_xilinx_wdt.c | 58 ++++++++++++++++++----------------------
>>   1 file changed, 26 insertions(+), 32 deletions(-)
>>
>> diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c
>> index 5c977164b3e5..03786992b701 100644
>> --- a/drivers/watchdog/of_xilinx_wdt.c
>> +++ b/drivers/watchdog/of_xilinx_wdt.c
>> @@ -151,41 +151,46 @@ static u32 xwdt_selftest(struct xwdt_device *xdev)
>>   		return XWT_TIMER_FAILED;
>>   }
>>   
>> +static void xwdt_clk_disable_unprepare(void *data)
>> +{
>> +	clk_disable_unprepare(data);
>> +}
>> +
>>   static int xwdt_probe(struct platform_device *pdev)
>>   {
>> +	struct device *dev = &pdev->dev;
>>   	int rc;
>>   	u32 pfreq = 0, enable_once = 0;
>>   	struct xwdt_device *xdev;
>>   	struct watchdog_device *xilinx_wdt_wdd;
>>   
>> -	xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL);
>> +	xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL);
>>   	if (!xdev)
>>   		return -ENOMEM;
>>   
>>   	xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd;
>>   	xilinx_wdt_wdd->info = &xilinx_wdt_ident;
>>   	xilinx_wdt_wdd->ops = &xilinx_wdt_ops;
>> -	xilinx_wdt_wdd->parent = &pdev->dev;
>> +	xilinx_wdt_wdd->parent = dev;
>>   
>>   	xdev->base = devm_platform_ioremap_resource(pdev, 0);
>>   	if (IS_ERR(xdev->base))
>>   		return PTR_ERR(xdev->base);
>>   
>> -	rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval",
>> +	rc = of_property_read_u32(dev->of_node, "xlnx,wdt-interval",
>>   				  &xdev->wdt_interval);
>>   	if (rc)
>> -		dev_warn(&pdev->dev,
>> -			 "Parameter \"xlnx,wdt-interval\" not found\n");
>> +		dev_warn(dev, "Parameter \"xlnx,wdt-interval\" not found\n");
>>   
>> -	rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-enable-once",
>> +	rc = of_property_read_u32(dev->of_node, "xlnx,wdt-enable-once",
>>   				  &enable_once);
>>   	if (rc)
>> -		dev_warn(&pdev->dev,
>> +		dev_warn(dev,
>>   			 "Parameter \"xlnx,wdt-enable-once\" not found\n");
>>   
>>   	watchdog_set_nowayout(xilinx_wdt_wdd, enable_once);
>>   
>> -	xdev->clk = devm_clk_get(&pdev->dev, NULL);
>> +	xdev->clk = devm_clk_get(dev, NULL);
>>   	if (IS_ERR(xdev->clk)) {
>>   		if (PTR_ERR(xdev->clk) != -ENOENT)
>>   			return PTR_ERR(xdev->clk);
>> @@ -196,10 +201,10 @@ static int xwdt_probe(struct platform_device *pdev)
>>   		 */
>>   		xdev->clk = NULL;
>>   
>> -		rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
>> +		rc = of_property_read_u32(dev->of_node, "clock-frequency",
>>   					  &pfreq);
>>   		if (rc)
>> -			dev_warn(&pdev->dev,
>> +			dev_warn(dev,
>>   				 "The watchdog clock freq cannot be obtained\n");
>>   	} else {
>>   		pfreq = clk_get_rate(xdev->clk);
>> @@ -218,44 +223,34 @@ static int xwdt_probe(struct platform_device *pdev)
>>   
>>   	rc = clk_prepare_enable(xdev->clk);
>>   	if (rc) {
>> -		dev_err(&pdev->dev, "unable to enable clock\n");
>> +		dev_err(dev, "unable to enable clock\n");
>>   		return rc;
>>   	}
>> +	rc = devm_add_action_or_reset(dev, xwdt_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;
>> +		dev_err(dev, "SelfTest routine error\n");
>> +		return rc;
>>   	}
>>   
>> -	rc = watchdog_register_device(xilinx_wdt_wdd);
>> +	rc = devm_watchdog_register_device(dev, xilinx_wdt_wdd);
>>   	if (rc) {
>> -		dev_err(&pdev->dev, "Cannot register watchdog (err=%d)\n", rc);
>> -		goto err_clk_disable;
>> +		dev_err(dev, "Cannot register watchdog (err=%d)\n", rc);
>> +		return rc;
>>   	}
>>   
>>   	clk_disable(xdev->clk);
>>   
>> -	dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n",
>> +	dev_info(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;
>>   }
>>   
>>   /**
>> @@ -303,7 +298,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,
>>
> 
> Looks good to me. I would prefer to do it via 3 patches but I will let
> Wim to comment.
> 

I could do that, but the total series is already more than 60 patches.
Splitting them up would mean hundreds of patches.

> Acked-by: Michal Simek <michal.simek@xilinx.com>
> 

Thanks,
Guenter

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

* Re: [PATCH 02/23] watchdog: mena21_wdt: Use 'dev' instead of dereferencing it repeatedly
  2019-04-09 17:23 ` [PATCH 02/23] watchdog: mena21_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
@ 2019-04-11  7:18   ` Johannes Thumshirn
  0 siblings, 0 replies; 31+ messages in thread
From: Johannes Thumshirn @ 2019-04-11  7:18 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck; +Cc: linux-watchdog, linux-kernel

On 09/04/2019 19:23, Guenter Roeck wrote:
> Introduce local variable 'struct device *dev' and use it instead of
> dereferencing it repeatedly.
> 
> 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
> 
> Cc: Johannes Thumshirn <morbidrsa@gmail.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

FWIW,
Reviewed-by: Johannes Thumshirn <jth@kernel.org>

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

end of thread, back to index

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-09 17:23 [PATCH 00/23] watchdog: Expand use of device managed functions (series 2 of 3) Guenter Roeck
2019-04-09 17:23 ` [PATCH 01/23] watchdog: max77620_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 02/23] watchdog: mena21_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-11  7:18   ` Johannes Thumshirn
2019-04-09 17:23 ` [PATCH 03/23] watchdog: menf21bmc_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 04/23] watchdog: meson_gxbb_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 05/23] watchdog: meson_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:23 ` [PATCH 06/23] watchdog: mlx_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 07/23] watchdog: moxart_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 08/23] watchdog: mtk_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 09/23] watchdog: npcm_wdt: Use local variable 'dev' consistently Guenter Roeck
2019-04-09 17:23 ` [PATCH 10/23] watchdog: of_xilinx_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-10  6:38   ` Michal Simek
2019-04-10 12:09     ` Guenter Roeck
2019-04-09 17:23 ` [PATCH 11/23] watchdog: pm8916_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:23 ` [PATCH 12/23] watchdog: qcom-wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 13/23] watchdog: rn5t618_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:23 ` [PATCH 14/23] watchdog: rtd119x_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 15/23] watchdog: rza_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:23 ` [PATCH 16/23] watchdog: sama5d4_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-09 17:23 ` [PATCH 17/23] watchdog: sirfsoc_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 18/23] watchdog: 1: " Guenter Roeck
2019-04-09 17:38   ` Guenter Roeck
2019-04-09 17:23 ` [PATCH 19/23] watchdog: st_lpc_wdt: Convert to use device managed functions Guenter Roeck
2019-04-10  7:26   ` Patrice CHOTARD
2019-04-09 17:23 ` [PATCH 20/23] watchdog: stmp3xxx_rtc_wdt: " Guenter Roeck
2019-04-09 17:23 ` [PATCH 21/23] watchdog: stpmic1_wdt: Use 'dev' instead of dereferencing it repeatedly Guenter Roeck
2019-04-09 17:24 ` [PATCH 22/23] watchdog: sunxi_wdt: " Guenter Roeck
2019-04-10  7:06   ` Maxime Ripard
2019-04-09 17:24 ` [PATCH 23/23] watchdog: tangox_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2019-04-10 11:20   ` Måns Rullgård

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org linux-watchdog@archiver.kernel.org
	public-inbox-index linux-watchdog

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-watchdog


AGPL code for this site: git clone https://public-inbox.org/ public-inbox