watchdog: Convert to use device managed functions
Subsystems (28)
Guenter Roeck
maintainercover watchdog: Convert to use device managed functions
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches.
To reproduce this series of patches, checkout the tree above, then run the following commands from the Linux source tree.
sh ~coccinelle-patches/watchdog/make.sh
sh ~coccinelle-patches/watchdog/do-commit.sh
The patch series is based on the following tree and branch.
git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
watchdog-next
----------------------------------------------------------------
Guenter Roeck (62):
watchdog: asm9260_wdt: Convert to use device managed functions and other improvements
watchdog: aspeed_wdt: Convert to use device managed functions
watchdog: at91sam9_wdt: Convert to use device managed functions
watchdog: atlas7_wdt: Convert to use device managed functions and other improvements
watchdog: bcm2835_wdt: Convert to use device managed functions and other improvements
watchdog: bcm47xx_wdt: Convert to use device managed functions
watchdog: bcm7038_wdt: Convert to use device managed functions and other improvements
watchdog: bcm_kona_wdt: Convert to use device managed functions and other improvements
watchdog: cadence_wdt: Convert to use device managed functions and other improvements
watchdog: coh901327_wdt: Convert to use device managed functions
watchdog: da9052_wdt: Convert to use device managed functions
watchdog: da9055_wdt: Convert to use device managed functions
watchdog: da9062_wdt: Convert to use device managed functions
watchdog: da9063_wdt: Convert to use device managed functions
watchdog: davinci_wdt: Convert to use device managed functions and other improvements
watchdog: digicolor_wdt: Convert to use device managed functions and other improvements
watchdog: dw_wdt: Convert to use device managed functions
watchdog: ep93xx_wdt: Convert to use device managed functions
watchdog: gpio_wdt: Convert to use device managed functions
watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot
watchdog: imgpdc_wdt: Convert to use device managed functions and other improvements
watchdog: imx2_wdt: Convert to use device managed functions
watchdog: intel-mid_wdt: Convert to use device managed functions
watchdog: jz4740_wdt: Convert to use device managed functions
watchdog: kempld_wdt: Convert to use device managed functions and other improvements
watchdog: loongson1_wdt: Convert to use device managed functions
watchdog: lpc18xx_wdt: Convert to use device managed functions and other improvements
watchdog: max63xx_wdt: Convert to use device managed functions
watchdog: max77620_wdt: Convert to use device managed functions
watchdog: mena21_wdt: Convert to use device managed functions and other improvements
watchdog: menf21bmc_wdt: Convert to use device managed functions
watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
watchdog: meson_wdt: Convert to use device managed functions and other improvements
watchdog: moxart_wdt: Convert to use device managed functions
watchdog: mpc8xxx_wdt: Convert to use device managed functions
watchdog: mt7621_wdt: Convert to use device managed functions and other improvements
watchdog: mtk_wdt: Convert to use device managed functions and other improvements
watchdog: nic7018_wdt: Convert to use device managed functions
watchdog: of_xilinx_wdt: Convert to use device managed functions
watchdog: omap_wdt: Convert to use device managed functions
watchdog: orion_wdt: Convert to use device managed functions and other improvements
watchdog: pic32-dmt: Convert to use device managed functions
watchdog: pic32-wdt: Convert to use device managed functions
watchdog: pnx4008_wdt: Convert to use device managed functions
watchdog: qcom-wdt: Convert to use device managed functions
watchdog: renesas_wdt: Convert to use device managed functions
watchdog: retu_wdt: Convert to use device managed functions and other improvements
watchdog: rt2880_wdt: Convert to use device managed functions and other improvements
watchdog: sama5d4_wdt: Convert to use device managed functions
watchdog: sbsa_gwdt: Convert to use device managed functions and other improvements
watchdog: shwdt: Convert to use device managed functions and other improvements
watchdog: sirfsoc_wdt: Convert to use device managed functions and other improvements
watchdog: st_lpc_wdt: Convert to use device managed functions
watchdog: stmp3xxx_rtc_wdt: Convert to use device managed functions
watchdog: sunxi_wdt: Convert to use device managed functions and other improvements
watchdog: tangox_wdt: Convert to use device managed functions
watchdog: tegra_wdt: Convert to use device managed functions
watchdog: ts4800_wdt: Convert to use device managed functions
watchdog: twl4030_wdt: Convert to use device managed functions
watchdog: txx9wdt: Convert to use device managed functions and other improvements
watchdog: ux500_wdt: Convert to use device managed functions
watchdog: wm831x_wdt: Convert to use device managed functions
drivers/watchdog/asm9260_wdt.c | 37 ++++++---------- drivers/watchdog/aspeed_wdt.c | 14 +----- drivers/watchdog/at91sam9_wdt.c | 48 +++++++------------- drivers/watchdog/atlas7_wdt.c | 43 +++++------------- drivers/watchdog/bcm2835_wdt.c | 27 ++++-------- drivers/watchdog/bcm47xx_wdt.c | 31 +++++-------- drivers/watchdog/bcm7038_wdt.c | 25 +++++------ drivers/watchdog/bcm_kona_wdt.c | 14 ++---- drivers/watchdog/cadence_wdt.c | 35 ++++----------- drivers/watchdog/coh901327_wdt.c | 33 +++++--------- drivers/watchdog/da9052_wdt.c | 32 ++++---------- drivers/watchdog/da9055_wdt.c | 17 +------- drivers/watchdog/da9062_wdt.c | 18 +------- drivers/watchdog/da9063_wdt.c | 18 +------- drivers/watchdog/davinci_wdt.c | 28 +++++------- drivers/watchdog/digicolor_wdt.c | 48 +++++--------------- drivers/watchdog/dw_wdt.c | 32 ++++---------- drivers/watchdog/ep93xx_wdt.c | 9 +--- drivers/watchdog/gpio_wdt.c | 23 ++++------ drivers/watchdog/iTCO_wdt.c | 9 +--- drivers/watchdog/imgpdc_wdt.c | 42 +++++++----------- drivers/watchdog/imx2_wdt.c | 15 +++---- drivers/watchdog/intel-mid_wdt.c | 11 +---- drivers/watchdog/jz4740_wdt.c | 22 +++------- drivers/watchdog/kempld_wdt.c | 12 +---- drivers/watchdog/loongson1_wdt.c | 31 ++++--------- drivers/watchdog/lpc18xx_wdt.c | 58 ++++++++----------------- drivers/watchdog/max63xx_wdt.c | 12 +---- drivers/watchdog/max77620_wdt.c | 3 +- drivers/watchdog/mena21_wdt.c | 24 +--------- drivers/watchdog/menf21bmc_wdt.c | 15 +------ drivers/watchdog/meson_gxbb_wdt.c | 38 +++++----------- drivers/watchdog/meson_wdt.c | 23 +--------- drivers/watchdog/moxart_wdt.c | 5 +-- drivers/watchdog/mpc8xxx_wdt.c | 25 +++++------ drivers/watchdog/mt7621_wdt.c | 17 +------- drivers/watchdog/mtk_wdt.c | 22 +--------- drivers/watchdog/nic7018_wdt.c | 4 +- drivers/watchdog/of_xilinx_wdt.c | 28 ++++-------- drivers/watchdog/omap_wdt.c | 3 +- drivers/watchdog/orion_wdt.c | 87 +++++++++++++++++-------------------- drivers/watchdog/pic32-dmt.c | 29 ++++--------- drivers/watchdog/pic32-wdt.c | 34 ++++----------- drivers/watchdog/pnx4008_wdt.c | 23 +++------- drivers/watchdog/qcom-wdt.c | 27 ++++-------- drivers/watchdog/renesas_wdt.c | 6 +-- drivers/watchdog/retu_wdt.c | 21 +++------ drivers/watchdog/rt2880_wdt.c | 17 +------- drivers/watchdog/sama5d4_wdt.c | 4 +- drivers/watchdog/sbsa_gwdt.c | 21 +-------- drivers/watchdog/shwdt.c | 11 +---- drivers/watchdog/sirfsoc_wdt.c | 13 ++---- drivers/watchdog/st_lpc_wdt.c | 11 ++--- drivers/watchdog/stmp3xxx_rtc_wdt.c | 3 +- drivers/watchdog/sunxi_wdt.c | 24 +--------- drivers/watchdog/tangox_wdt.c | 22 ++++------ drivers/watchdog/tegra_wdt.c | 4 +- drivers/watchdog/ts4800_wdt.c | 14 +----- drivers/watchdog/twl4030_wdt.c | 17 +------- drivers/watchdog/txx9wdt.c | 46 +++++++------------- drivers/watchdog/ux500_wdt.c | 10 +---- drivers/watchdog/wm831x_wdt.c | 31 +++---------- 62 files changed, 387 insertions(+), 1039 deletions(-)
Guenter Roeck
maintainerPATCH 1/62 watchdog: asm9260_wdt: Convert to use device managed functions and other improvements
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/asm9260_wdt.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-)
drivers/watchdog/asm9260_wdt.c +13 -24
@@ -219,26 +219,32 @@ static int asm9260_wdt_get_dt_clks(struct asm9260_wdt_priv *priv)dev_err (priv->dev,"Failed to enable ahb_clk!\n" );return err; } + err =devm_add_action_or_reset (priv->dev, + (void (*)(void *))clk_disable_unprepare, + priv->clk_ahb); +if (err) +return err; err =clk_set_rate (priv->clk,CLOCK_FREQ );if (err) { -clk_disable_unprepare (priv->clk_ahb);dev_err (priv->dev,"Failed to set rate!\n" );return err; } err =clk_prepare_enable (priv->clk);if (err) { -clk_disable_unprepare (priv->clk_ahb);dev_err (priv->dev,"Failed to enable clk!\n" );return err; } + err =devm_add_action_or_reset (priv->dev, + (void (*)(void *))clk_disable_unprepare, + priv->clk); +if (err) +return err;/* wdt has internal divider */ clk =clk_get_rate (priv->clk);if (!clk) { -clk_disable_unprepare (priv->clk); -clk_disable_unprepare (priv->clk_ahb);dev_err (priv->dev,"Failed, clk is 0!\n" );return -EINVAL ; }
@@ -335,27 +341,16 @@ static int asm9260_wdt_probe(struct platform_device *pdev)watchdog_set_restart_priority (wdd,128 ); - ret =watchdog_register_device (wdd); +watchdog_stop_on_reboot (wdd); + ret =devm_watchdog_register_device (&pdev->dev, wdd);if (ret) - goto clk_off; +return ret;platform_set_drvdata (pdev, priv);dev_info (&pdev->dev,"Watchdog enabled (timeout: %d sec, mode: %s)\n" , wdd->timeout, mode_name[priv->mode]);return 0 ; - -clk_off: -clk_disable_unprepare (priv->clk); -clk_disable_unprepare (priv->clk_ahb); -return ret; -} - -static void asm9260_wdt_shutdown (struct platform_device *pdev) -{ -struct asm9260_wdt_priv *priv =platform_get_drvdata (pdev); - -asm9260_wdt_disable (&priv->wdd); }static int asm9260_wdt_remove (struct platform_device *pdev)
@@ -364,11 +359,6 @@ static int asm9260_wdt_remove(struct platform_device *pdev)asm9260_wdt_disable (&priv->wdd); -watchdog_unregister_device (&priv->wdd); - -clk_disable_unprepare (priv->clk); -clk_disable_unprepare (priv->clk_ahb); -return 0 ; }
@@ -385,7 +375,6 @@ static struct platform_driver asm9260_wdt_driver = { }, .probe = asm9260_wdt_probe, .remove = asm9260_wdt_remove, - .shutdown = asm9260_wdt_shutdown, };module_platform_driver (asm9260_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 2/62 watchdog: aspeed_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/aspeed_wdt.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/watchdog/aspeed_wdt.c +1 -13
@@ -136,15 +136,6 @@ static const struct watchdog_info aspeed_wdt_info = { .identity = KBUILD_MODNAME, }; -static int aspeed_wdt_remove (struct platform_device *pdev) -{ -struct aspeed_wdt *wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&wdt->wdd); - -return 0 ; -} -static int aspeed_wdt_probe (struct platform_device *pdev) {struct aspeed_wdt *wdt;
@@ -187,20 +178,17 @@ static int aspeed_wdt_probe(struct platform_device *pdev)set_bit (WDOG_HW_RUNNING , &wdt->wdd.status); } - ret =watchdog_register_device (&wdt->wdd); + ret =devm_watchdog_register_device (&pdev->dev, &wdt->wdd);if (ret) {dev_err (&pdev->dev,"failed to register\n" );return ret; } -platform_set_drvdata (pdev, wdt); -return 0 ; }static struct platform_driver aspeed_watchdog_driver = { .probe = aspeed_wdt_probe, - .remove = aspeed_wdt_remove, .driver = { .name =KBUILD_MODNAME , .of_match_table =of_match_ptr (aspeed_wdt_of_table),
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 3/62 watchdog: at91sam9_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Replace request_irq, request_threaded_irq, and request_any_context_irq with their device managed equivalent
- Drop platform_set_drvdata()
- Call del_timer() using devm_add_action()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/at91sam9_wdt.c | 48 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 32 deletions(-)
drivers/watchdog/at91sam9_wdt.c +16 -32
@@ -209,10 +209,9 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt) "min heartbeat and max heartbeat might be too close for the system to handle it correctly\n");if ((tmp &AT91_WDT_WDFIEN ) && wdt->irq) { - err =request_irq (wdt->irq, wdt_interrupt, -IRQF_SHARED |IRQF_IRQPOLL | -IRQF_NO_SUSPEND , - pdev->name, wdt); + err =devm_request_irq (&pdev->dev, wdt->irq, wdt_interrupt, +IRQF_SHARED |IRQF_IRQPOLL |IRQF_NO_SUSPEND , + pdev->name, wdt);if (err)return err; }
@@ -223,6 +222,10 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt) tmp & wdt->mr_mask, wdt->mr & wdt->mr_mask);setup_timer (&wdt->timer, at91_ping, (unsigned long )wdt); + err =devm_add_action (&pdev->dev, (void (*)(void *))del_timer, + &wdt->timer); +if (err) +return err;/* * Use min_heartbeat the first time to avoid spurious watchdog reset:
@@ -237,17 +240,13 @@ static int at91_wdt_init(struct platform_device *pdev, struct at91wdt *wdt)if (watchdog_init_timeout (&wdt->wdd,0 , dev))watchdog_init_timeout (&wdt->wdd, heartbeat, dev);watchdog_set_nowayout (&wdt->wdd, wdt->nowayout); - err =watchdog_register_device (&wdt->wdd); + err =devm_watchdog_register_device (&pdev->dev, &wdt->wdd);if (err) - goto out_stop_timer; +return err; wdt->next_heartbeat = jiffies + wdt->wdd.timeout *HZ ;return 0 ; - -out_stop_timer: -del_timer (&wdt->timer); -return err; }/* ......................................................................... */
@@ -363,40 +362,26 @@ static int __init at91wdt_probe(struct platform_device *pdev)dev_err (&pdev->dev,"Could not enable slow clock\n" );return err; } + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + wdt->sclk); +if (err) +return err;if (pdev->dev.of_node) { err =of_at91wdt_init (pdev->dev.of_node, wdt);if (err) - goto err_clk; +return err; } err =at91_wdt_init (pdev, wdt);if (err) - goto err_clk; - -platform_set_drvdata (pdev, wdt); +return err;pr_info ("enabled (heartbeat=%d sec, nowayout=%d)\n" , wdt->wdd.timeout, wdt->nowayout);return 0 ; - -err_clk: -clk_disable_unprepare (wdt->sclk); - -return err; -} - -static int __exit at91wdt_remove(struct platform_device *pdev) -{ -struct at91wdt *wdt =platform_get_drvdata (pdev); -watchdog_unregister_device (&wdt->wdd); - -pr_warn ("I quit now, hardware will probably reboot!\n" ); -del_timer (&wdt->timer); -clk_disable_unprepare (wdt->sclk); - -return 0 ; }#if defined(CONFIG_OF )
@@ -409,7 +394,6 @@ MODULE_DEVICE_TABLE(of, at91_wdt_dt_ids);#endif static struct platform_driver at91wdt_driver = { - .remove =__exit_p (at91wdt_remove), .driver = { .name ="at91_wdt" , .of_match_table =of_match_ptr (at91_wdt_dt_ids),
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 4/62 watchdog: atlas7_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)'
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/atlas7_wdt.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-)
drivers/watchdog/atlas7_wdt.c +12 -31
@@ -127,7 +127,6 @@ static const struct of_device_id atlas7_wdt_ids[] = {static int atlas7_wdt_probe (struct platform_device *pdev) { -struct device_node *np = pdev->dev.of_node;struct atlas7_wdog *wdt;struct resource *res;struct clk *clk;
@@ -141,23 +140,26 @@ static int atlas7_wdt_probe(struct platform_device *pdev)if (IS_ERR (wdt->base))return PTR_ERR (wdt->base); - clk =of_clk_get (np,0 ); + clk =devm_clk_get (&pdev->dev,NULL );if (IS_ERR (clk))return PTR_ERR (clk); ret =clk_prepare_enable (clk);if (ret) {dev_err (&pdev->dev,"clk enable failed\n" ); - goto err; +return ret; } + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + clk); +if (ret) +return ret;/* disable watchdog hardware */ writel (0 , wdt->base +ATLAS7_WDT_CNT_CTRL ); wdt->tick_rate =clk_get_rate (clk); -if (!wdt->tick_rate) { - ret = -EINVAL ; - goto err1; - } +if (!wdt->tick_rate) +return -EINVAL ; wdt->clk = clk; atlas7_wdd.min_timeout =1 ;
@@ -169,35 +171,15 @@ static int atlas7_wdt_probe(struct platform_device *pdev)watchdog_set_drvdata (&atlas7_wdd, wdt);platform_set_drvdata (pdev, &atlas7_wdd); - ret =watchdog_register_device (&atlas7_wdd); -if (ret) - goto err1; - -return 0 ; - -err1: -clk_disable_unprepare (clk); -err: -clk_put (clk); -return ret; -} - -static void atlas7_wdt_shutdown (struct platform_device *pdev) -{ -struct watchdog_device *wdd =platform_get_drvdata (pdev); -struct atlas7_wdog *wdt =watchdog_get_drvdata (wdd); - -atlas7_wdt_disable (wdd); -clk_disable_unprepare (wdt->clk); +watchdog_stop_on_reboot (&atlas7_wdd); +return devm_watchdog_register_device (&pdev->dev, &atlas7_wdd); }static int atlas7_wdt_remove (struct platform_device *pdev) {struct watchdog_device *wdd =platform_get_drvdata (pdev); -struct atlas7_wdog *wdt =watchdog_get_drvdata (wdd); -atlas7_wdt_shutdown (pdev); -clk_put (wdt->clk); +atlas7_wdt_disable (wdd);return 0 ; }
@@ -237,7 +219,6 @@ static struct platform_driver atlas7_wdt_driver = { }, .probe = atlas7_wdt_probe, .remove = atlas7_wdt_remove, - .shutdown = atlas7_wdt_shutdown, };module_platform_driver (atlas7_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 5/62 watchdog: bcm2835_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Replace of_iomap() with platform_get_resource() followed by devm_ioremap_resource()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/bcm2835_wdt.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)
drivers/watchdog/bcm2835_wdt.c +8 -19
@@ -172,8 +172,8 @@ static void bcm2835_power_off(void)static int bcm2835_wdt_probe (struct platform_device *pdev) { +struct resource *res;struct device *dev = &pdev->dev; -struct device_node *np = dev->of_node;struct bcm2835_wdt *wdt;int err;
@@ -184,16 +184,15 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)spin_lock_init (&wdt->lock); - wdt->base =of_iomap (np,0 ); -if (!wdt->base) { -dev_err (dev,"Failed to remap watchdog regs" ); -return -ENODEV ; - } + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + wdt->base =devm_ioremap_resource (dev, res); +if (IS_ERR (wdt->base)) +return PTR_ERR (wdt->base);watchdog_set_drvdata (&bcm2835_wdt_wdd, wdt);watchdog_init_timeout (&bcm2835_wdt_wdd, heartbeat, dev);watchdog_set_nowayout (&bcm2835_wdt_wdd, nowayout); - bcm2835_wdt_wdd.parent = &pdev->dev; + bcm2835_wdt_wdd.parent = dev;if (bcm2835_wdt_is_running (wdt)) {/* * The currently active timeout value (set by the
@@ -208,10 +207,10 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)watchdog_set_restart_priority (&bcm2835_wdt_wdd,128 ); - err =watchdog_register_device (&bcm2835_wdt_wdd); +watchdog_stop_on_reboot (&bcm2835_wdt_wdd); + err =devm_watchdog_register_device (dev, &bcm2835_wdt_wdd);if (err) {dev_err (dev,"Failed to register watchdog device" ); -iounmap (wdt->base);return err; }
@@ -224,21 +223,12 @@ static int bcm2835_wdt_probe(struct platform_device *pdev)static int bcm2835_wdt_remove (struct platform_device *pdev) { -struct bcm2835_wdt *wdt =platform_get_drvdata (pdev); -if (pm_power_off == bcm2835_power_off) pm_power_off =NULL ; -watchdog_unregister_device (&bcm2835_wdt_wdd); -iounmap (wdt->base);return 0 ; } -static void bcm2835_wdt_shutdown (struct platform_device *pdev) -{ -bcm2835_wdt_stop (&bcm2835_wdt_wdd); -} -static const struct of_device_id bcm2835_wdt_of_match[] = { { .compatible ="brcm,bcm2835-pm-wdt" , }, {},
@@ -248,7 +238,6 @@ MODULE_DEVICE_TABLE(of, bcm2835_wdt_of_match);static struct platform_driver bcm2835_wdt_driver = { .probe = bcm2835_wdt_probe, .remove = bcm2835_wdt_remove, - .shutdown = bcm2835_wdt_shutdown, .driver = { .name ="bcm2835-wdt" , .of_match_table = bcm2835_wdt_of_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 6/62 watchdog: bcm47xx_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Call del_timer_sync() using devm_add_action()
Introduce helper function since we can not call del_timer_sync() directly
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/bcm47xx_wdt.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-)
drivers/watchdog/bcm47xx_wdt.c +12 -19
@@ -177,6 +177,11 @@ static struct watchdog_ops bcm47xx_wdt_soft_ops = { .restart = bcm47xx_wdt_restart, }; +static void __del_timer_sync_cb (void *t) +{ +del_timer_sync (t); +} +static int bcm47xx_wdt_probe (struct platform_device *pdev) {int ret;
@@ -192,6 +197,10 @@ static int bcm47xx_wdt_probe(struct platform_device *pdev) wdt->wdd.ops = &bcm47xx_wdt_soft_ops;setup_timer (&wdt->soft_timer, bcm47xx_wdt_soft_timer_tick, (long unsigned int )wdt); + ret =devm_add_action (&pdev->dev, __del_timer_sync_cb, + &wdt->soft_timer); +if (ret) +return ret; }else { wdt->wdd.ops = &bcm47xx_wdt_hard_ops; }
@@ -201,34 +210,19 @@ static int bcm47xx_wdt_probe(struct platform_device *pdev) wdt->wdd.parent = &pdev->dev; ret = wdt->wdd.ops->set_timeout (&wdt->wdd, timeout);if (ret) - goto err_timer; +return ret;watchdog_set_nowayout (&wdt->wdd, nowayout);watchdog_set_restart_priority (&wdt->wdd,64 );watchdog_stop_on_reboot (&wdt->wdd); - ret =watchdog_register_device (&wdt->wdd); + ret =devm_watchdog_register_device (&pdev->dev, &wdt->wdd);if (ret) - goto err_timer; +return ret;dev_info (&pdev->dev,"BCM47xx Watchdog Timer enabled (%d seconds%s%s)\n" , timeout, nowayout ?", nowayout" :"" , soft ?", Software Timer" :"" );return 0 ; - -err_timer: -if (soft) -del_timer_sync (&wdt->soft_timer); - -return ret; -} - -static int bcm47xx_wdt_remove (struct platform_device *pdev) -{ -struct bcm47xx_wdt *wdt =dev_get_platdata (&pdev->dev); - -watchdog_unregister_device (&wdt->wdd); - -return 0 ; }static struct platform_driver bcm47xx_wdt_driver = {
@@ -236,7 +230,6 @@ static struct platform_driver bcm47xx_wdt_driver = { .name = "bcm47xx-wdt", }, .probe = bcm47xx_wdt_probe, - .remove = bcm47xx_wdt_remove, };module_platform_driver (bcm47xx_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 7/62 watchdog: bcm7038_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Check return value from clk_prepare_enable()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/bcm7038_wdt.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/watchdog/bcm7038_wdt.c +10 -15
@@ -136,7 +136,14 @@ static int bcm7038_wdt_probe(struct platform_device *pdev) wdt->clk =devm_clk_get (dev,NULL );/* If unable to get clock, use default frequency */ if (!IS_ERR (wdt->clk)) { -clk_prepare_enable (wdt->clk); + err =clk_prepare_enable (wdt->clk); +if (err) +return err; + err =devm_add_action_or_reset (dev, + (void (*)(void *))clk_disable_unprepare, + wdt->clk); +if (err) +return err; wdt->rate =clk_get_rate (wdt->clk);/* Prevent divide-by-zero exception */ if (!wdt->rate)
@@ -154,10 +161,10 @@ static int bcm7038_wdt_probe(struct platform_device *pdev) wdt->wdd.parent = dev;watchdog_set_drvdata (&wdt->wdd, wdt); - err =watchdog_register_device (&wdt->wdd); +watchdog_stop_on_reboot (&wdt->wdd); + err =devm_watchdog_register_device (dev, &wdt->wdd);if (err) {dev_err (dev,"Failed to register watchdog device\n" ); -clk_disable_unprepare (wdt->clk);return err; }
@@ -173,9 +180,6 @@ static int bcm7038_wdt_remove(struct platform_device *pdev)if (!nowayout)bcm7038_wdt_stop (&wdt->wdd); -watchdog_unregister_device (&wdt->wdd); -clk_disable_unprepare (wdt->clk); -return 0 ; }
@@ -204,14 +208,6 @@ static int bcm7038_wdt_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(bcm7038_wdt_pm_ops, bcm7038_wdt_suspend, bcm7038_wdt_resume); -static void bcm7038_wdt_shutdown (struct platform_device *pdev) -{ -struct bcm7038_watchdog *wdt =platform_get_drvdata (pdev); - -if (watchdog_active (&wdt->wdd)) -bcm7038_wdt_stop (&wdt->wdd); -} -static const struct of_device_id bcm7038_wdt_match[] = { { .compatible ="brcm,bcm7038-wdt" }, {},
@@ -221,7 +217,6 @@ MODULE_DEVICE_TABLE(of, bcm7038_wdt_match);static struct platform_driver bcm7038_wdt_driver = { .probe = bcm7038_wdt_probe, .remove = bcm7038_wdt_remove, - .shutdown = bcm7038_wdt_shutdown, .driver = { .name ="bcm7038-wdt" , .of_match_table = bcm7038_wdt_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 8/62 watchdog: bcm_kona_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/bcm_kona_wdt.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/watchdog/bcm_kona_wdt.c +4 -10
@@ -288,11 +288,6 @@ static struct watchdog_device bcm_kona_wdt_wdd = { .timeout = SECWDOG_MAX_COUNT >> SECWDOG_DEFAULT_RESOLUTION, }; -static void bcm_kona_wdt_shutdown (struct platform_device *pdev) -{ -bcm_kona_wdt_stop (&bcm_kona_wdt_wdd); -} -static int bcm_kona_wdt_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -319,7 +314,7 @@ static int bcm_kona_wdt_probe(struct platform_device *pdev)spin_lock_init (&wdt->lock);platform_set_drvdata (pdev, wdt);watchdog_set_drvdata (&bcm_kona_wdt_wdd, wdt); - bcm_kona_wdt_wdd.parent = &pdev->dev; + bcm_kona_wdt_wdd.parent = dev; ret =bcm_kona_wdt_set_timeout_reg (&bcm_kona_wdt_wdd,0 );if (ret) {
@@ -327,7 +322,8 @@ static int bcm_kona_wdt_probe(struct platform_device *pdev)return ret; } - ret =watchdog_register_device (&bcm_kona_wdt_wdd); +watchdog_stop_on_reboot (&bcm_kona_wdt_wdd); + ret =devm_watchdog_register_device (dev, &bcm_kona_wdt_wdd);if (ret) {dev_err (dev,"Failed to register watchdog device" );return ret;
@@ -342,8 +338,7 @@ static int bcm_kona_wdt_probe(struct platform_device *pdev)static int bcm_kona_wdt_remove (struct platform_device *pdev) {bcm_kona_wdt_debug_exit (pdev); -bcm_kona_wdt_shutdown (pdev); -watchdog_unregister_device (&bcm_kona_wdt_wdd); +bcm_kona_wdt_stop (platform_get_drvdata (pdev));dev_dbg (&pdev->dev,"Watchdog driver disabled" );return 0 ;
@@ -362,7 +357,6 @@ static struct platform_driver bcm_kona_wdt_driver = { }, .probe = bcm_kona_wdt_probe, .remove = bcm_kona_wdt_remove, - .shutdown = bcm_kona_wdt_shutdown, };module_platform_driver (bcm_kona_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 9/62 watchdog: cadence_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/cadence_wdt.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-)
drivers/watchdog/cadence_wdt.c +9 -26
@@ -340,8 +340,7 @@ static int cdns_wdt_probe(struct platform_device *pdev) wdt->clk =devm_clk_get (&pdev->dev,NULL );if (IS_ERR (wdt->clk)) {dev_err (&pdev->dev,"input clock not found\n" ); - ret =PTR_ERR (wdt->clk); -return ret; +return PTR_ERR (wdt->clk); } ret =clk_prepare_enable (wdt->clk);
@@ -349,6 +348,11 @@ static int cdns_wdt_probe(struct platform_device *pdev)dev_err (&pdev->dev,"unable to enable clock\n" );return ret; } + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + wdt->clk); +if (ret) +return ret; clock_f =clk_get_rate (wdt->clk);if (clock_f <=CDNS_WDT_CLK_75MHZ ) {
@@ -361,10 +365,11 @@ static int cdns_wdt_probe(struct platform_device *pdev)spin_lock_init (&wdt->io_lock); - ret =watchdog_register_device (cdns_wdt_device); +watchdog_stop_on_reboot (cdns_wdt_device); + ret =devm_watchdog_register_device (&pdev->dev, cdns_wdt_device);if (ret) {dev_err (&pdev->dev,"Failed to register wdt device\n" ); - goto err_clk_disable; +return ret; }platform_set_drvdata (pdev, wdt);
@@ -373,11 +378,6 @@ static int cdns_wdt_probe(struct platform_device *pdev) nowayout ? ", nowayout" : "");return 0 ; - -err_clk_disable: -clk_disable_unprepare (wdt->clk); - -return ret; }/**
@@ -393,27 +393,11 @@ static int cdns_wdt_remove(struct platform_device *pdev)struct cdns_wdt *wdt =platform_get_drvdata (pdev);cdns_wdt_stop (&wdt->cdns_wdt_device); -watchdog_unregister_device (&wdt->cdns_wdt_device); -clk_disable_unprepare (wdt->clk);return 0 ; }/** -* cdns_wdt_shutdown - Stop the device. -* -* @pdev: handle to the platform structure. -* -*/ -static void cdns_wdt_shutdown (struct platform_device *pdev) -{ -struct cdns_wdt *wdt =platform_get_drvdata (pdev); - -cdns_wdt_stop (&wdt->cdns_wdt_device); -clk_disable_unprepare (wdt->clk); -} - -/** * cdns_wdt_suspend - Stop the device. * * @dev: handle to the device structure.
@@ -468,7 +452,6 @@ MODULE_DEVICE_TABLE(of, cdns_wdt_of_match);static struct platform_driver cdns_wdt_driver = { .probe = cdns_wdt_probe, .remove = cdns_wdt_remove, - .shutdown = cdns_wdt_shutdown, .driver = { .name ="cdns-wdt" , .of_match_table = cdns_wdt_of_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 10/62 watchdog: coh901327_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_clk_get() if the device parameter is not NULL
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Replace request_irq, request_threaded_irq, and request_any_context_irq with their device managed equivalent
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/coh901327_wdt.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-)
drivers/watchdog/coh901327_wdt.c +12 -21
@@ -241,11 +241,7 @@ static struct watchdog_device coh901327_wdt = { static int __exit coh901327_remove(struct platform_device *pdev) { -watchdog_unregister_device (&coh901327_wdt);coh901327_disable (); -free_irq (irq, pdev); -clk_disable_unprepare (clk); -clk_put (clk);return 0 ; }
@@ -263,7 +259,7 @@ static int __init coh901327_probe(struct platform_device *pdev)if (IS_ERR (virtbase))return PTR_ERR (virtbase); - clk =clk_get (dev,NULL ); + clk =devm_clk_get (dev,NULL );if (IS_ERR (clk)) { ret =PTR_ERR (clk);dev_err (dev,"could not get clock\n" );
@@ -272,8 +268,13 @@ static int __init coh901327_probe(struct platform_device *pdev) ret =clk_prepare_enable (clk);if (ret) {dev_err (dev,"could not prepare and enable clock\n" ); - goto out_no_clk_enable; +return ret; } + ret =devm_add_action_or_reset (dev, + (void (*)(void *))clk_disable_unprepare, + clk); +if (ret) +return ret; val =readw (virtbase +U300_WDOG_SR );switch (val) {
@@ -309,31 +310,21 @@ static int __init coh901327_probe(struct platform_device *pdev)writew (U300_WDOG_SR_RESET_STATUS_RESET , virtbase +U300_WDOG_SR ); irq =platform_get_irq (pdev,0 ); -if (request_irq (irq, coh901327_interrupt,0 , -DRV_NAME " Bark" , pdev)) { - ret = -EIO ; - goto out_no_irq; - } +if (devm_request_irq (dev, irq, coh901327_interrupt,0 , +DRV_NAME " Bark" , pdev)) +return -EIO ; ret =watchdog_init_timeout (&coh901327_wdt, margin, dev);if (ret <0 ) coh901327_wdt.timeout =60 ; coh901327_wdt.parent = dev; - ret =watchdog_register_device (&coh901327_wdt); + ret =devm_watchdog_register_device (dev, &coh901327_wdt);if (ret) - goto out_no_wdog; +return ret;dev_info (dev,"initialized. timer margin=%d sec\n" , margin);return 0 ; - -out_no_wdog: -free_irq (irq, pdev); -out_no_irq: -clk_disable_unprepare (clk); -out_no_clk_enable: -clk_put (clk); -return ret; }#ifdef CONFIG_PM
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 11/62 watchdog: da9052_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/da9052_wdt.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-)
drivers/watchdog/da9052_wdt.c +8 -24
@@ -128,16 +128,14 @@ static int da9052_wdt_ping(struct watchdog_device *wdt_dev) ret =da9052_reg_update (da9052,DA9052_CONTROL_D_REG ,DA9052_CONTROLD_WATCHDOG ,1 <<7 );if (ret <0 ) - goto err_strobe; +return ret;/* * FIXME: Reset the watchdog core, in general PMIC * is supposed to do this */ - ret =da9052_reg_update (da9052,DA9052_CONTROL_D_REG , -DA9052_CONTROLD_WATCHDOG ,0 <<7 ); -err_strobe: -return ret; +return da9052_reg_update (da9052,DA9052_CONTROL_D_REG , +DA9052_CONTROLD_WATCHDOG ,0 <<7 ); }static const struct watchdog_info da9052_wdt_info = {
@@ -163,10 +161,8 @@ static int da9052_wdt_probe(struct platform_device *pdev) driver_data =devm_kzalloc (&pdev->dev,sizeof (*driver_data),GFP_KERNEL ); -if (!driver_data) { - ret = -ENOMEM ; - goto err; - } +if (!driver_data) +return -ENOMEM ; driver_data->da9052 = da9052; da9052_wdt = &driver_data->wdt;
@@ -182,33 +178,21 @@ static int da9052_wdt_probe(struct platform_device *pdev)if (ret <0 ) {dev_err (&pdev->dev,"Failed to disable watchdog bits, %d\n" , ret); - goto err; +return ret; } - ret =watchdog_register_device (&driver_data->wdt); + ret =devm_watchdog_register_device (&pdev->dev, &driver_data->wdt);if (ret !=0 ) {dev_err (da9052->dev,"watchdog_register_device() failed: %d\n" , ret); - goto err; +return ret; } -platform_set_drvdata (pdev, driver_data); -err:return ret; } -static int da9052_wdt_remove (struct platform_device *pdev) -{ -struct da9052_wdt_data *driver_data =platform_get_drvdata (pdev); - -watchdog_unregister_device (&driver_data->wdt); - -return 0 ; -} -static struct platform_driver da9052_wdt_driver = { .probe = da9052_wdt_probe, - .remove = da9052_wdt_remove, .driver = { .name ="da9052-watchdog" , },
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 12/62 watchdog: da9055_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/da9055_wdt.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/watchdog/da9055_wdt.c +2 -15
@@ -147,32 +147,19 @@ static int da9055_wdt_probe(struct platform_device *pdev) ret =da9055_wdt_stop (da9055_wdt);if (ret <0 ) {dev_err (&pdev->dev,"Failed to stop watchdog, %d\n" , ret); - goto err; +return ret; } -platform_set_drvdata (pdev, driver_data); - - ret =watchdog_register_device (&driver_data->wdt); + ret =devm_watchdog_register_device (&pdev->dev, &driver_data->wdt);if (ret !=0 )dev_err (da9055->dev,"watchdog_register_device() failed: %d\n" , ret); -err:return ret; } -static int da9055_wdt_remove (struct platform_device *pdev) -{ -struct da9055_wdt_data *driver_data =platform_get_drvdata (pdev); - -watchdog_unregister_device (&driver_data->wdt); - -return 0 ; -} -static struct platform_driver da9055_wdt_driver = { .probe = da9055_wdt_probe, - .remove = da9055_wdt_remove, .driver = { .name ="da9055-watchdog" , },
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 13/62 watchdog: da9062_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop dev_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/da9062_wdt.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-)
drivers/watchdog/da9062_wdt.c +2 -16
@@ -220,9 +220,8 @@ static int da9062_wdt_probe(struct platform_device *pdev) wdt->wdtdev.parent = &pdev->dev;watchdog_set_drvdata (&wdt->wdtdev, wdt); -dev_set_drvdata (&pdev->dev, wdt); - ret =watchdog_register_device (&wdt->wdtdev); + ret =devm_watchdog_register_device (&pdev->dev, &wdt->wdtdev);if (ret <0 ) {dev_err (wdt->hw->dev,"watchdog registration failed (%d)\n" , ret);
@@ -231,24 +230,11 @@ static int da9062_wdt_probe(struct platform_device *pdev)da9062_set_window_start (wdt); - ret =da9062_wdt_ping (&wdt->wdtdev); -if (ret <0 ) -watchdog_unregister_device (&wdt->wdtdev); - -return ret; -} - -static int da9062_wdt_remove (struct platform_device *pdev) -{ -struct da9062_watchdog *wdt =dev_get_drvdata (&pdev->dev); - -watchdog_unregister_device (&wdt->wdtdev); -return 0 ; +return da9062_wdt_ping (&wdt->wdtdev); }static struct platform_driver da9062_wdt_driver = { .probe = da9062_wdt_probe, - .remove = da9062_wdt_remove, .driver = { .name ="da9062-watchdog" , .of_match_table = da9062_compatible_id_table,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 14/62 watchdog: da9063_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop unused variables
- Drop remove function
- Drop dev_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/da9063_wdt.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
drivers/watchdog/da9063_wdt.c +1 -17
@@ -151,7 +151,6 @@ static const struct watchdog_ops da9063_watchdog_ops = {static int da9063_wdt_probe (struct platform_device *pdev) { -int ret;struct da9063 *da9063;struct da9063_watchdog *wdt;
@@ -181,27 +180,12 @@ static int da9063_wdt_probe(struct platform_device *pdev)watchdog_set_restart_priority (&wdt->wdtdev,128 );watchdog_set_drvdata (&wdt->wdtdev, wdt); -dev_set_drvdata (&pdev->dev, wdt); - - ret =watchdog_register_device (&wdt->wdtdev); -if (ret) -return ret; - -return 0 ; -} - -static int da9063_wdt_remove (struct platform_device *pdev) -{ -struct da9063_watchdog *wdt =dev_get_drvdata (&pdev->dev); - -watchdog_unregister_device (&wdt->wdtdev); -return 0 ; +return devm_watchdog_register_device (&pdev->dev, &wdt->wdtdev); }static struct platform_driver da9063_wdt_driver = { .probe = da9063_wdt_probe, - .remove = da9063_wdt_remove, .driver = { .name =DA9063_DRVNAME_WATCHDOG , },
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 15/62 watchdog: davinci_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Check return value from clk_prepare_enable()
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/davinci_wdt.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/watchdog/davinci_wdt.c +11 -17
@@ -169,13 +169,18 @@ static int davinci_wdt_probe(struct platform_device *pdev)if (IS_ERR (davinci_wdt->clk)) {if (PTR_ERR (davinci_wdt->clk) != -EPROBE_DEFER ) -dev_err (&pdev->dev,"failed to get clock node\n" ); +dev_err (dev,"failed to get clock node\n" );return PTR_ERR (davinci_wdt->clk); } -clk_prepare_enable (davinci_wdt->clk); - -platform_set_drvdata (pdev, davinci_wdt); + ret =clk_prepare_enable (davinci_wdt->clk); +if (ret) +return ret; + ret =devm_add_action_or_reset (dev, + (void (*)(void *))clk_disable_unprepare, + davinci_wdt->clk); +if (ret) +return ret; wdd = &davinci_wdt->wdd; wdd->info = &davinci_wdt_info;
@@ -183,7 +188,7 @@ static int davinci_wdt_probe(struct platform_device *pdev) wdd->min_timeout =1 ; wdd->max_timeout =MAX_HEARTBEAT ; wdd->timeout =DEFAULT_HEARTBEAT ; - wdd->parent = &pdev->dev; + wdd->parent = dev;watchdog_init_timeout (wdd, heartbeat, dev);
@@ -197,23 +202,13 @@ static int davinci_wdt_probe(struct platform_device *pdev)if (IS_ERR (davinci_wdt->base))return PTR_ERR (davinci_wdt->base); - ret =watchdog_register_device (wdd); + ret =devm_watchdog_register_device (dev, wdd);if (ret <0 )dev_err (dev,"cannot register watchdog device\n" );return ret; } -static int davinci_wdt_remove (struct platform_device *pdev) -{ -struct davinci_wdt_device *davinci_wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&davinci_wdt->wdd); -clk_disable_unprepare (davinci_wdt->clk); - -return 0 ; -} -static const struct of_device_id davinci_wdt_of_match[] = { { .compatible ="ti,davinci-wdt" , }, {},
@@ -226,7 +221,6 @@ static struct platform_driver platform_wdt_driver = { .of_match_table = davinci_wdt_of_match, }, .probe = davinci_wdt_probe, - .remove = davinci_wdt_remove, };module_platform_driver (platform_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 16/62 watchdog: digicolor_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Replace of_iomap() with platform_get_resource() followed by devm_ioremap_resource()
- Drop platform_set_drvdata()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/digicolor_wdt.c | 48 ++++++++++------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-)
drivers/watchdog/digicolor_wdt.c +12 -36
@@ -119,62 +119,40 @@ static struct watchdog_device dc_wdt_wdd = {static int dc_wdt_probe (struct platform_device *pdev) { +struct resource *res;struct device *dev = &pdev->dev; -struct device_node *np = dev->of_node;struct dc_wdt *wdt;int ret; wdt =devm_kzalloc (dev,sizeof (struct dc_wdt ),GFP_KERNEL );if (!wdt)return -ENOMEM ; -platform_set_drvdata (pdev, wdt); - wdt->base =of_iomap (np,0 ); -if (!wdt->base) { -dev_err (dev,"Failed to remap watchdog regs" ); -return -ENODEV ; - } + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + wdt->base =devm_ioremap_resource (dev, res); +if (IS_ERR (wdt->base)) +return PTR_ERR (wdt->base); - wdt->clk =devm_clk_get (&pdev->dev,NULL ); -if (IS_ERR (wdt->clk)) { - ret =PTR_ERR (wdt->clk); - goto err_iounmap; - } + wdt->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (wdt->clk)) +return PTR_ERR (wdt->clk); dc_wdt_wdd.max_timeout =U32_MAX /clk_get_rate (wdt->clk); dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout; - dc_wdt_wdd.parent = &pdev->dev; + dc_wdt_wdd.parent = dev;spin_lock_init (&wdt->lock);watchdog_set_drvdata (&dc_wdt_wdd, wdt);watchdog_set_restart_priority (&dc_wdt_wdd,128 );watchdog_init_timeout (&dc_wdt_wdd, timeout, dev); - ret =watchdog_register_device (&dc_wdt_wdd); +watchdog_stop_on_reboot (&dc_wdt_wdd); + ret =devm_watchdog_register_device (dev, &dc_wdt_wdd);if (ret) {dev_err (dev,"Failed to register watchdog device" ); - goto err_iounmap; +return ret; }return 0 ; - -err_iounmap: -iounmap (wdt->base); -return ret; -} - -static int dc_wdt_remove (struct platform_device *pdev) -{ -struct dc_wdt *wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&dc_wdt_wdd); -iounmap (wdt->base); - -return 0 ; -} - -static void dc_wdt_shutdown (struct platform_device *pdev) -{ -dc_wdt_stop (&dc_wdt_wdd); }static const struct of_device_id dc_wdt_of_match[] = {
@@ -185,8 +163,6 @@ MODULE_DEVICE_TABLE(of, dc_wdt_of_match);static struct platform_driver dc_wdt_driver = { .probe = dc_wdt_probe, - .remove = dc_wdt_remove, - .shutdown = dc_wdt_shutdown, .driver = { .name ="digicolor-wdt" , .of_match_table = dc_wdt_of_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 17/62 watchdog: dw_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/dw_wdt.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-)
drivers/watchdog/dw_wdt.c +8 -24
@@ -227,12 +227,15 @@ static int dw_wdt_drv_probe(struct platform_device *pdev) ret =clk_prepare_enable (dw_wdt->clk);if (ret)return ret; + ret =devm_add_action_or_reset (dev, + (void (*)(void *))clk_disable_unprepare, + dw_wdt->clk); +if (ret) +return ret; dw_wdt->rate =clk_get_rate (dw_wdt->clk); -if (dw_wdt->rate ==0 ) { - ret = -EINVAL ; - goto out_disable_clk; - } +if (dw_wdt->rate ==0 ) +return -EINVAL ; wdd = &dw_wdt->wdd; wdd->info = &dw_wdt_ident;
@@ -263,25 +266,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)watchdog_set_restart_priority (wdd,128 ); - ret =watchdog_register_device (wdd); -if (ret) - goto out_disable_clk; - -return 0 ; - -out_disable_clk: -clk_disable_unprepare (dw_wdt->clk); -return ret; -} - -static int dw_wdt_drv_remove (struct platform_device *pdev) -{ -struct dw_wdt *dw_wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&dw_wdt->wdd); -clk_disable_unprepare (dw_wdt->clk); - -return 0 ; +return devm_watchdog_register_device (dev, wdd); }#ifdef CONFIG_OF
@@ -294,7 +279,6 @@ MODULE_DEVICE_TABLE(of, dw_wdt_of_match);static struct platform_driver dw_wdt_driver = { .probe = dw_wdt_drv_probe, - .remove = dw_wdt_drv_remove, .driver = { .name ="dw_wdt" , .of_match_table =of_match_ptr (dw_wdt_of_match),
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 18/62 watchdog: ep93xx_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/ep93xx_wdt.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/watchdog/ep93xx_wdt.c +1 -8
@@ -138,7 +138,7 @@ static int ep93xx_wdt_probe(struct platform_device *pdev)setup_timer (&timer, ep93xx_wdt_timer_ping,1 ); - err =watchdog_register_device (&ep93xx_wdt_wdd); + err =devm_watchdog_register_device (&pdev->dev, &ep93xx_wdt_wdd);if (err)return err;
@@ -149,18 +149,11 @@ static int ep93xx_wdt_probe(struct platform_device *pdev)return 0 ; } -static int ep93xx_wdt_remove (struct platform_device *pdev) -{ -watchdog_unregister_device (&ep93xx_wdt_wdd); -return 0 ; -} -static struct platform_driver ep93xx_wdt_driver = { .driver = { .name ="ep93xx-wdt" , }, .probe = ep93xx_wdt_probe, - .remove = ep93xx_wdt_remove, };module_platform_driver (ep93xx_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 19/62 watchdog: gpio_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Call del_timer_sync() using devm_add_action()
Introduce helper function since we can not call del_timer_sync() directly
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/gpio_wdt.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/watchdog/gpio_wdt.c +9 -14
@@ -138,6 +138,11 @@ static const struct watchdog_ops gpio_wdt_ops = { .set_timeout = gpio_wdt_set_timeout, }; +static void __del_timer_sync_cb (void *t) +{ +del_timer_sync (t); +} +static int gpio_wdt_probe (struct platform_device *pdev) {struct gpio_wdt_priv *priv;
@@ -151,8 +156,6 @@ static int gpio_wdt_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; -platform_set_drvdata (pdev, priv); - priv->gpio =of_get_gpio_flags (pdev->dev.of_node,0 , &flags);if (!gpio_is_valid (priv->gpio))return priv->gpio;
@@ -203,10 +206,13 @@ static int gpio_wdt_probe(struct platform_device *pdev) priv->wdd.timeout =SOFT_TIMEOUT_DEF ;setup_timer (&priv->timer, gpio_wdt_hwping, (unsigned long )&priv->wdd); + ret =devm_add_action (&pdev->dev, __del_timer_sync_cb, &priv->timer); +if (ret) +return ret;watchdog_stop_on_reboot (&priv->wdd); - ret =watchdog_register_device (&priv->wdd); + ret =devm_watchdog_register_device (&pdev->dev, &priv->wdd);if (ret)return ret;
@@ -216,16 +222,6 @@ static int gpio_wdt_probe(struct platform_device *pdev)return 0 ; } -static int gpio_wdt_remove (struct platform_device *pdev) -{ -struct gpio_wdt_priv *priv =platform_get_drvdata (pdev); - -del_timer_sync (&priv->timer); -watchdog_unregister_device (&priv->wdd); - -return 0 ; -} -static const struct of_device_id gpio_wdt_dt_ids[] = { { .compatible ="linux,wdt-gpio" , }, { }
@@ -238,7 +234,6 @@ static struct platform_driver gpio_wdt_driver = { .of_match_table = gpio_wdt_dt_ids, }, .probe = gpio_wdt_probe, - .remove = gpio_wdt_remove, };#ifdef CONFIG_GPIO_WATCHDOG_ARCH_INITCALL
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 20/62 watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot
In reply to Guenter RoeckThe shutdown function calls the stop function. Call watchdog_stop_on_reboot() from probe instead.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/iTCO_wdt.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/watchdog/iTCO_wdt.c +1 -8
@@ -520,6 +520,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev) WATCHDOG_TIMEOUT); } +watchdog_stop_on_reboot (&p->wddev); ret =devm_watchdog_register_device (dev, &p->wddev);if (ret !=0 ) {pr_err ("cannot register watchdog device (err=%d)\n" , ret);
@@ -543,13 +544,6 @@ static int iTCO_wdt_remove(struct platform_device *pdev)return 0 ; } -static void iTCO_wdt_shutdown (struct platform_device *pdev) -{ -struct iTCO_wdt_private *p =platform_get_drvdata (pdev); - -iTCO_wdt_stop (&p->wddev); -} -#ifdef CONFIG_PM_SLEEP /* * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so
@@ -603,7 +597,6 @@ static const struct dev_pm_ops iTCO_wdt_pm = {static struct platform_driver iTCO_wdt_driver = { .probe = iTCO_wdt_probe, .remove = iTCO_wdt_remove, - .shutdown = iTCO_wdt_shutdown, .driver = { .name =DRV_NAME , .pm =ITCO_WDT_PM_OPS ,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 21/62 watchdog: imgpdc_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/imgpdc_wdt.c | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-)
drivers/watchdog/imgpdc_wdt.c +15 -27
@@ -211,25 +211,33 @@ static int pdc_wdt_probe(struct platform_device *pdev)dev_err (&pdev->dev,"could not prepare or enable sys clock\n" );return ret; } + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + pdc_wdt->sys_clk); +if (ret) +return ret; ret =clk_prepare_enable (pdc_wdt->wdt_clk);if (ret) {dev_err (&pdev->dev,"could not prepare or enable wdt clock\n" ); - goto disable_sys_clk; +return ret; } + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + pdc_wdt->wdt_clk); +if (ret) +return ret;/* We use the clock rate to calculate the max timeout */ clk_rate =clk_get_rate (pdc_wdt->wdt_clk);if (clk_rate ==0 ) {dev_err (&pdev->dev,"failed to get clock rate\n" ); - ret = -EINVAL ; - goto disable_wdt_clk; +return -EINVAL ; }if (order_base_2 (clk_rate) >PDC_WDT_CONFIG_DELAY_MASK +1 ) {dev_err (&pdev->dev,"invalid clock rate\n" ); - ret = -EINVAL ; - goto disable_wdt_clk; +return -EINVAL ; }if (order_base_2 (clk_rate) ==0 )
@@ -284,24 +292,8 @@ static int pdc_wdt_probe(struct platform_device *pdev)platform_set_drvdata (pdev, pdc_wdt); - ret =watchdog_register_device (&pdc_wdt->wdt_dev); -if (ret) - goto disable_wdt_clk; - -return 0 ; - -disable_wdt_clk: -clk_disable_unprepare (pdc_wdt->wdt_clk); -disable_sys_clk: -clk_disable_unprepare (pdc_wdt->sys_clk); -return ret; -} - -static void pdc_wdt_shutdown (struct platform_device *pdev) -{ -struct pdc_wdt_dev *pdc_wdt =platform_get_drvdata (pdev); - -pdc_wdt_stop (&pdc_wdt->wdt_dev); +watchdog_stop_on_reboot (&pdc_wdt->wdt_dev); +return devm_watchdog_register_device (&pdev->dev, &pdc_wdt->wdt_dev); }static int pdc_wdt_remove (struct platform_device *pdev)
@@ -309,9 +301,6 @@ static int pdc_wdt_remove(struct platform_device *pdev)struct pdc_wdt_dev *pdc_wdt =platform_get_drvdata (pdev);pdc_wdt_stop (&pdc_wdt->wdt_dev); -watchdog_unregister_device (&pdc_wdt->wdt_dev); -clk_disable_unprepare (pdc_wdt->wdt_clk); -clk_disable_unprepare (pdc_wdt->sys_clk);return 0 ; }
@@ -329,7 +318,6 @@ static struct platform_driver pdc_wdt_driver = { }, .probe = pdc_wdt_probe, .remove = pdc_wdt_remove, - .shutdown = pdc_wdt_shutdown, };module_platform_driver (pdc_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 22/62 watchdog: imx2_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/imx2_wdt.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/watchdog/imx2_wdt.c +7 -8
@@ -287,6 +287,11 @@ static int __init imx2_wdt_probe(struct platform_device *pdev) ret =clk_prepare_enable (wdev->clk);if (ret)return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + wdev->clk); +if (ret) +return ret;regmap_read (wdev->regmap,IMX2_WDT_WRSR , &val); wdog->bootstatus = val &IMX2_WDT_WRSR_TOUT ?WDIOF_CARDRESET :0 ;
@@ -316,20 +321,16 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)*/ regmap_write (wdev->regmap,IMX2_WDT_WMCR ,0 ); - ret =watchdog_register_device (wdog); + ret =devm_watchdog_register_device (&pdev->dev, wdog);if (ret) {dev_err (&pdev->dev,"cannot register watchdog device\n" ); - goto disable_clk; +return ret; }dev_info (&pdev->dev,"timeout %d sec (nowayout=%d)\n" , wdog->timeout, nowayout);return 0 ; - -disable_clk: -clk_disable_unprepare (wdev->clk); -return ret; } static int __exit imx2_wdt_remove(struct platform_device *pdev)
@@ -337,8 +338,6 @@ static int __exit imx2_wdt_remove(struct platform_device *pdev)struct watchdog_device *wdog =platform_get_drvdata (pdev);struct imx2_wdt_device *wdev =watchdog_get_drvdata (wdog); -watchdog_unregister_device (wdog); -if (imx2_wdt_is_running (wdev)) {imx2_wdt_ping (wdog);dev_crit (&pdev->dev,"Device removed: Expect reboot!\n" );
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 23/62 watchdog: intel-mid_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/intel-mid_wdt.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/watchdog/intel-mid_wdt.c +1 -10
@@ -137,7 +137,6 @@ static int mid_wdt_probe(struct platform_device *pdev) wdt_dev->parent = &pdev->dev;watchdog_set_drvdata (wdt_dev, &pdev->dev); -platform_set_drvdata (pdev, wdt_dev); ret = devm_request_irq(&pdev->dev, pdata->irq, mid_wdt_irq, IRQF_SHARED | IRQF_NO_SUSPEND, "watchdog",
@@ -151,7 +150,7 @@ static int mid_wdt_probe(struct platform_device *pdev)/* Make sure the watchdog is not running */ wdt_stop (wdt_dev); - ret =watchdog_register_device (wdt_dev); + ret =devm_watchdog_register_device (&pdev->dev, wdt_dev);if (ret) {dev_err (&pdev->dev,"error registering watchdog device\n" );return ret;
@@ -162,16 +161,8 @@ static int mid_wdt_probe(struct platform_device *pdev)return 0 ; } -static int mid_wdt_remove (struct platform_device *pdev) -{ -struct watchdog_device *wd =platform_get_drvdata (pdev); -watchdog_unregister_device (wd); -return 0 ; -} -static struct platform_driver mid_wdt_driver = { .probe = mid_wdt_probe, - .remove = mid_wdt_remove, .driver = { .name ="intel_mid_wdt" , },
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 24/62 watchdog: jz4740_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_clk_get() if the device parameter is not NULL
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/jz4740_wdt.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
drivers/watchdog/jz4740_wdt.c +6 -16
@@ -178,29 +178,21 @@ static int jz4740_wdt_probe(struct platform_device *pdev) res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); drvdata->base =devm_ioremap_resource (&pdev->dev, res); -if (IS_ERR (drvdata->base)) { - ret =PTR_ERR (drvdata->base); - goto err_out; - } +if (IS_ERR (drvdata->base)) +return PTR_ERR (drvdata->base); - drvdata->rtc_clk =clk_get (&pdev->dev,"rtc" ); + drvdata->rtc_clk =devm_clk_get (&pdev->dev,"rtc" );if (IS_ERR (drvdata->rtc_clk)) {dev_err (&pdev->dev,"cannot find RTC clock\n" ); - ret =PTR_ERR (drvdata->rtc_clk); - goto err_out; +return PTR_ERR (drvdata->rtc_clk); } - ret =watchdog_register_device (&drvdata->wdt); + ret =devm_watchdog_register_device (&pdev->dev, &drvdata->wdt);if (ret <0 ) - goto err_disable_clk; +return ret;platform_set_drvdata (pdev, drvdata);return 0 ; - -err_disable_clk: -clk_put (drvdata->rtc_clk); -err_out: -return ret; }static int jz4740_wdt_remove (struct platform_device *pdev)
@@ -208,8 +200,6 @@ static int jz4740_wdt_remove(struct platform_device *pdev)struct jz4740_wdt_drvdata *drvdata =platform_get_drvdata (pdev);jz4740_wdt_stop (&drvdata->wdt); -watchdog_unregister_device (&drvdata->wdt); -clk_put (drvdata->rtc_clk);return 0 ; }
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 25/62 watchdog: kempld_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/kempld_wdt.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/watchdog/kempld_wdt.c +2 -10
@@ -490,7 +490,8 @@ static int kempld_wdt_probe(struct platform_device *pdev) }platform_set_drvdata (pdev, wdt_data); - ret =watchdog_register_device (wdd); +watchdog_stop_on_reboot (wdd); + ret =devm_watchdog_register_device (dev, wdd);if (ret)return ret;
@@ -499,13 +500,6 @@ static int kempld_wdt_probe(struct platform_device *pdev)return 0 ; } -static void kempld_wdt_shutdown (struct platform_device *pdev) -{ -struct kempld_wdt_data *wdt_data =platform_get_drvdata (pdev); - -kempld_wdt_stop (&wdt_data->wdd); -} -static int kempld_wdt_remove (struct platform_device *pdev) {struct kempld_wdt_data *wdt_data =platform_get_drvdata (pdev);
@@ -514,7 +508,6 @@ static int kempld_wdt_remove(struct platform_device *pdev)if (!nowayout) ret =kempld_wdt_stop (wdd); -watchdog_unregister_device (wdd);return ret; }
@@ -566,7 +559,6 @@ static struct platform_driver kempld_wdt_driver = { }, .probe = kempld_wdt_probe, .remove = kempld_wdt_remove, - .shutdown = kempld_wdt_shutdown, .suspend = kempld_wdt_suspend, .resume = kempld_wdt_resume, };
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 26/62 watchdog: loongson1_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/loongson1_wdt.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-)
drivers/watchdog/loongson1_wdt.c +9 -22
@@ -109,12 +109,15 @@ static int ls1x_wdt_probe(struct platform_device *pdev)dev_err (&pdev->dev,"clk enable failed\n" );return err; } + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + drvdata->clk); +if (err) +return err; clk_rate =clk_get_rate (drvdata->clk); -if (!clk_rate) { - err = -EINVAL ; - goto err0; - } +if (!clk_rate) +return -EINVAL ; drvdata->clk_rate = clk_rate; ls1x_wdt = &drvdata->wdt;
@@ -129,35 +132,19 @@ static int ls1x_wdt_probe(struct platform_device *pdev)watchdog_set_nowayout (ls1x_wdt, nowayout);watchdog_set_drvdata (ls1x_wdt, drvdata); - err =watchdog_register_device (&drvdata->wdt); + err =devm_watchdog_register_device (&pdev->dev, &drvdata->wdt);if (err) {dev_err (&pdev->dev,"failed to register watchdog device\n" ); - goto err0; +return err; } -platform_set_drvdata (pdev, drvdata); -dev_info (&pdev->dev,"Loongson1 Watchdog driver registered\n" );return 0 ; -err0: -clk_disable_unprepare (drvdata->clk); -return err; -} - -static int ls1x_wdt_remove (struct platform_device *pdev) -{ -struct ls1x_wdt_drvdata *drvdata =platform_get_drvdata (pdev); - -watchdog_unregister_device (&drvdata->wdt); -clk_disable_unprepare (drvdata->clk); - -return 0 ; }static struct platform_driver ls1x_wdt_driver = { .probe = ls1x_wdt_probe, - .remove = ls1x_wdt_remove, .driver = { .name ="ls1x-wdt" , },
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 27/62 watchdog: lpc18xx_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Call del_timer() using devm_add_action()
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/lpc18xx_wdt.c | 58 ++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 39 deletions(-)
drivers/watchdog/lpc18xx_wdt.c +19 -39
@@ -231,19 +231,28 @@ static int lpc18xx_wdt_probe(struct platform_device *pdev)dev_err (dev,"could not prepare or enable sys clock\n" );return ret; } + ret =devm_add_action_or_reset (dev, + (void (*)(void *))clk_disable_unprepare, + lpc18xx_wdt->reg_clk); +if (ret) +return ret; ret =clk_prepare_enable (lpc18xx_wdt->wdt_clk);if (ret) {dev_err (dev,"could not prepare or enable wdt clock\n" ); - goto disable_reg_clk; +return ret; } + ret =devm_add_action_or_reset (dev, + (void (*)(void *))clk_disable_unprepare, + lpc18xx_wdt->wdt_clk); +if (ret) +return ret;/* We use the clock rate to calculate timeouts */ lpc18xx_wdt->clk_rate =clk_get_rate (lpc18xx_wdt->wdt_clk);if (lpc18xx_wdt->clk_rate ==0 ) {dev_err (dev,"failed to get clock rate\n" ); - ret = -EINVAL ; - goto disable_wdt_clk; +return -EINVAL ; } lpc18xx_wdt->wdt_dev.info = &lpc18xx_wdt_info;
@@ -269,44 +278,17 @@ static int lpc18xx_wdt_probe(struct platform_device *pdev)setup_timer (&lpc18xx_wdt->timer, lpc18xx_wdt_timer_feed, (unsigned long )&lpc18xx_wdt->wdt_dev); + ret =devm_add_action (dev, (void (*)(void *))del_timer, + &lpc18xx_wdt->timer); +if (ret) +return ret;watchdog_set_nowayout (&lpc18xx_wdt->wdt_dev, nowayout);watchdog_set_restart_priority (&lpc18xx_wdt->wdt_dev,128 ); -platform_set_drvdata (pdev, lpc18xx_wdt); - - ret =watchdog_register_device (&lpc18xx_wdt->wdt_dev); -if (ret) - goto disable_wdt_clk; - -return 0 ; - -disable_wdt_clk: -clk_disable_unprepare (lpc18xx_wdt->wdt_clk); -disable_reg_clk: -clk_disable_unprepare (lpc18xx_wdt->reg_clk); -return ret; -} - -static void lpc18xx_wdt_shutdown (struct platform_device *pdev) -{ -struct lpc18xx_wdt_dev *lpc18xx_wdt =platform_get_drvdata (pdev); - -lpc18xx_wdt_stop (&lpc18xx_wdt->wdt_dev); -} - -static int lpc18xx_wdt_remove (struct platform_device *pdev) -{ -struct lpc18xx_wdt_dev *lpc18xx_wdt =platform_get_drvdata (pdev); - -dev_warn (&pdev->dev,"I quit now, hardware will probably reboot!\n" ); -del_timer (&lpc18xx_wdt->timer); - -watchdog_unregister_device (&lpc18xx_wdt->wdt_dev); -clk_disable_unprepare (lpc18xx_wdt->wdt_clk); -clk_disable_unprepare (lpc18xx_wdt->reg_clk); - -return 0 ; +watchdog_stop_on_reboot (&lpc18xx_wdt->wdt_dev); +return devm_watchdog_register_device (dev, + &lpc18xx_wdt->wdt_dev); }static const struct of_device_id lpc18xx_wdt_match[] = {
@@ -321,8 +303,6 @@ static struct platform_driver lpc18xx_wdt_driver = { .of_match_table = lpc18xx_wdt_match, }, .probe = lpc18xx_wdt_probe, - .remove = lpc18xx_wdt_remove, - .shutdown = lpc18xx_wdt_shutdown, };module_platform_driver (lpc18xx_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 28/62 watchdog: max63xx_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/max63xx_wdt.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/watchdog/max63xx_wdt.c +1 -11
@@ -225,7 +225,6 @@ static int max63xx_wdt_probe(struct platform_device *pdev)if (err)return err; -platform_set_drvdata (pdev, &wdt->wdd);watchdog_set_drvdata (&wdt->wdd, wdt); wdt->wdd.parent = &pdev->dev;
@@ -235,7 +234,7 @@ static int max63xx_wdt_probe(struct platform_device *pdev)watchdog_set_nowayout (&wdt->wdd, nowayout); - err =watchdog_register_device (&wdt->wdd); + err =devm_watchdog_register_device (&pdev->dev, &wdt->wdd);if (err)return err;
@@ -244,14 +243,6 @@ static int max63xx_wdt_probe(struct platform_device *pdev)return 0 ; } -static int max63xx_wdt_remove (struct platform_device *pdev) -{ -struct watchdog_device *wdd =platform_get_drvdata (pdev); - -watchdog_unregister_device (wdd); -return 0 ; -} -static const struct platform_device_id max63xx_id_table[] = { {"max6369_wdt" , (kernel_ulong_t )max6369_table, }, {"max6370_wdt" , (kernel_ulong_t )max6369_table, },
@@ -265,7 +256,6 @@ MODULE_DEVICE_TABLE(platform, max63xx_id_table);static struct platform_driver max63xx_wdt_driver = { .probe = max63xx_wdt_probe, - .remove = max63xx_wdt_remove, .id_table = max63xx_id_table, .driver = { .name ="max63xx_wdt" ,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 29/62 watchdog: max77620_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/max77620_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/max77620_wdt.c +1 -2
@@ -182,7 +182,7 @@ static int max77620_wdt_probe(struct platform_device *pdev)watchdog_set_nowayout (wdt_dev, nowayout);watchdog_set_drvdata (wdt_dev, wdt); - ret =watchdog_register_device (wdt_dev); + ret =devm_watchdog_register_device (&pdev->dev, wdt_dev);if (ret <0 ) {dev_err (&pdev->dev,"watchdog registration failed: %d\n" , ret);return ret;
@@ -196,7 +196,6 @@ static int max77620_wdt_remove(struct platform_device *pdev)struct max77620_wdt *wdt =platform_get_drvdata (pdev);max77620_wdt_stop (&wdt->wdt_dev); -watchdog_unregister_device (&wdt->wdt_dev);return 0 ; }
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 30/62 watchdog: mena21_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop unnecessary mutex_destroy() on allocated data
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/mena21_wdt.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/watchdog/mena21_wdt.c +2 -22
@@ -212,34 +212,15 @@ static int a21_wdt_probe(struct platform_device *pdev) drv->wdt = a21_wdt;dev_set_drvdata (&pdev->dev, drv); - ret =watchdog_register_device (&a21_wdt); + ret =devm_watchdog_register_device (&pdev->dev, &a21_wdt);if (ret) {dev_err (&pdev->dev,"Cannot register watchdog device\n" ); - goto err_register_wd; +return ret; }dev_info (&pdev->dev,"MEN A21 watchdog timer driver enabled\n" );return 0 ; - -err_register_wd: -mutex_destroy (&drv->lock); - -return ret; -} - -static int a21_wdt_remove (struct platform_device *pdev) -{ -struct a21_wdt_drv *drv =dev_get_drvdata (&pdev->dev); - -dev_warn (&pdev->dev, -"Unregistering A21 watchdog driver, board may reboot\n" ); - -watchdog_unregister_device (&drv->wdt); - -mutex_destroy (&drv->lock); - -return 0 ; }static void a21_wdt_shutdown (struct platform_device *pdev)
@@ -257,7 +238,6 @@ MODULE_DEVICE_TABLE(of, a21_wdt_ids);static struct platform_driver a21_wdt_driver = { .probe = a21_wdt_probe, - .remove = a21_wdt_remove, .shutdown = a21_wdt_shutdown, .driver = { .name ="a21-watchdog" ,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 31/62 watchdog: menf21bmc_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/menf21bmc_wdt.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/watchdog/menf21bmc_wdt.c +1 -14
@@ -155,7 +155,7 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev)return ret; } - ret =watchdog_register_device (&drv_data->wdt); + ret =devm_watchdog_register_device (&pdev->dev, &drv_data->wdt);if (ret) {dev_err (&pdev->dev,"failed to register Watchdog device\n" );return ret;
@@ -166,18 +166,6 @@ static int menf21bmc_wdt_probe(struct platform_device *pdev)return 0 ; } -static int menf21bmc_wdt_remove (struct platform_device *pdev) -{ -struct menf21bmc_wdt *drv_data =platform_get_drvdata (pdev); - -dev_warn (&pdev->dev, -"Unregister MEN 14F021P00 BMC Watchdog device, board may reset\n" ); - -watchdog_unregister_device (&drv_data->wdt); - -return 0 ; -} -static void menf21bmc_wdt_shutdown (struct platform_device *pdev) {struct menf21bmc_wdt *drv_data =platform_get_drvdata (pdev);
@@ -191,7 +179,6 @@ static struct platform_driver menf21bmc_wdt = { .name = DEVNAME, }, .probe = menf21bmc_wdt_probe, - .remove = menf21bmc_wdt_remove, .shutdown = menf21bmc_wdt_shutdown, };
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 32/62 watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Check return value from clk_prepare_enable()
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/meson_gxbb_wdt.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-)
drivers/watchdog/meson_gxbb_wdt.c +10 -28
@@ -203,7 +203,14 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)if (IS_ERR (data->clk))return PTR_ERR (data->clk); -clk_prepare_enable (data->clk); + ret =clk_prepare_enable (data->clk); +if (ret) +return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + data->clk); +if (ret) +return ret;platform_set_drvdata (pdev, data);
@@ -224,37 +231,12 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)meson_gxbb_wdt_set_timeout (&data->wdt_dev, data->wdt_dev.timeout); - ret =watchdog_register_device (&data->wdt_dev); -if (ret) { -clk_disable_unprepare (data->clk); -return ret; - } - -return 0 ; -} - -static int meson_gxbb_wdt_remove (struct platform_device *pdev) -{ -struct meson_gxbb_wdt *data =platform_get_drvdata (pdev); - -watchdog_unregister_device (&data->wdt_dev); - -clk_disable_unprepare (data->clk); - -return 0 ; -} - -static void meson_gxbb_wdt_shutdown (struct platform_device *pdev) -{ -struct meson_gxbb_wdt *data =platform_get_drvdata (pdev); - -meson_gxbb_wdt_stop (&data->wdt_dev); +watchdog_stop_on_reboot (&data->wdt_dev); +return devm_watchdog_register_device (&pdev->dev, &data->wdt_dev); }static struct platform_driver meson_gxbb_wdt_driver = { .probe = meson_gxbb_wdt_probe, - .remove = meson_gxbb_wdt_remove, - .shutdown = meson_gxbb_wdt_shutdown, .driver = { .name ="meson-gxbb-wdt" , .pm = &meson_gxbb_wdt_pm_ops,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 33/62 watchdog: meson_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/meson_wdt.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-)
drivers/watchdog/meson_wdt.c +2 -21
@@ -201,38 +201,19 @@ static int meson_wdt_probe(struct platform_device *pdev)meson_wdt_stop (&meson_wdt->wdt_dev); - err =watchdog_register_device (&meson_wdt->wdt_dev); +watchdog_stop_on_reboot (&meson_wdt->wdt_dev); + err =devm_watchdog_register_device (&pdev->dev, &meson_wdt->wdt_dev);if (err)return err; -platform_set_drvdata (pdev, meson_wdt); -dev_info (&pdev->dev,"Watchdog enabled (timeout=%d sec, nowayout=%d)" , meson_wdt->wdt_dev.timeout, nowayout);return 0 ; } -static int meson_wdt_remove (struct platform_device *pdev) -{ -struct meson_wdt_dev *meson_wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&meson_wdt->wdt_dev); - -return 0 ; -} - -static void meson_wdt_shutdown (struct platform_device *pdev) -{ -struct meson_wdt_dev *meson_wdt =platform_get_drvdata (pdev); - -meson_wdt_stop (&meson_wdt->wdt_dev); -} -static struct platform_driver meson_wdt_driver = { .probe = meson_wdt_probe, - .remove = meson_wdt_remove, - .shutdown = meson_wdt_shutdown, .driver = { .name =DRV_NAME , .of_match_table = meson_wdt_dt_ids,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 34/62 watchdog: moxart_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Replace 'of_clk_get(np, 0)' with 'devm_clk_get(dev, NULL)'
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/moxart_wdt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/watchdog/moxart_wdt.c +2 -3
@@ -90,7 +90,6 @@ static int moxart_wdt_probe(struct platform_device *pdev) {struct moxart_wdt_dev *moxart_wdt;struct device *dev = &pdev->dev; -struct device_node *node = dev->of_node;struct resource *res;struct clk *clk;int err;
@@ -108,7 +107,7 @@ static int moxart_wdt_probe(struct platform_device *pdev)if (IS_ERR (moxart_wdt->base))return PTR_ERR (moxart_wdt->base); - clk =of_clk_get (node,0 ); + clk =devm_clk_get (dev,NULL );if (IS_ERR (clk)) {pr_err ("%s: of_clk_get failed\n" , __func__);return PTR_ERR (clk);
@@ -135,7 +134,7 @@ static int moxart_wdt_probe(struct platform_device *pdev)watchdog_set_drvdata (&moxart_wdt->dev, moxart_wdt); - err =watchdog_register_device (&moxart_wdt->dev); + err =devm_watchdog_register_device (dev, &moxart_wdt->dev);if (err)return err;
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 35/62 watchdog: mpc8xxx_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Call del_timer_sync() using devm_add_action()
Introduce helper function since we can not call del_timer_sync() directly
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/mpc8xxx_wdt.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/watchdog/mpc8xxx_wdt.c +10 -15
@@ -140,6 +140,11 @@ static struct watchdog_ops mpc8xxx_wdt_ops = { .stop = mpc8xxx_wdt_stop, }; +static void __del_timer_sync_cb (void *t) +{ +del_timer_sync (t); +} +static int mpc8xxx_wdt_probe (struct platform_device *ofdev) {int ret;
@@ -175,6 +180,10 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)spin_lock_init (&ddata->lock);setup_timer (&ddata->timer, mpc8xxx_wdt_timer_ping, (unsigned long )ddata); + ret =devm_add_action (&ofdev->dev, __del_timer_sync_cb, + &ddata->timer); +if (ret) +return ret; ddata->wdd.info = &mpc8xxx_wdt_info, ddata->wdd.ops = &mpc8xxx_wdt_ops,
@@ -186,7 +195,7 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)watchdog_set_nowayout (&ddata->wdd, nowayout); - ret =watchdog_register_device (&ddata->wdd); + ret =devm_watchdog_register_device (&ofdev->dev, &ddata->wdd);if (ret) {pr_err ("cannot register watchdog device (err=%d)\n" , ret);return ret;
@@ -203,19 +212,6 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)if (enabled)mod_timer (&ddata->timer, jiffies); -platform_set_drvdata (ofdev, ddata); -return 0 ; -} - -static int mpc8xxx_wdt_remove (struct platform_device *ofdev) -{ -struct mpc8xxx_wdt_ddata *ddata =platform_get_drvdata (ofdev); - -pr_crit ("Watchdog removed, expect the %s soon!\n" , - reset ?"reset" :"machine check exception" ); -del_timer_sync (&ddata->timer); -watchdog_unregister_device (&ddata->wdd); -return 0 ; }
@@ -246,7 +242,6 @@ MODULE_DEVICE_TABLE(of, mpc8xxx_wdt_match);static struct platform_driver mpc8xxx_wdt_driver = { .probe = mpc8xxx_wdt_probe, - .remove = mpc8xxx_wdt_remove, .driver = { .name ="mpc8xxx_wdt" , .of_match_table = mpc8xxx_wdt_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 36/62 watchdog: mt7621_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/mt7621_wdt.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/watchdog/mt7621_wdt.c +2 -15
@@ -145,23 +145,12 @@ static int mt7621_wdt_probe(struct platform_device *pdev) &pdev->dev);watchdog_set_nowayout (&mt7621_wdt_dev, nowayout); - ret =watchdog_register_device (&mt7621_wdt_dev); +watchdog_stop_on_reboot (&mt7621_wdt_dev); + ret =devm_watchdog_register_device (&pdev->dev, &mt7621_wdt_dev);return 0 ; } -static int mt7621_wdt_remove (struct platform_device *pdev) -{ -watchdog_unregister_device (&mt7621_wdt_dev); - -return 0 ; -} - -static void mt7621_wdt_shutdown (struct platform_device *pdev) -{ -mt7621_wdt_stop (&mt7621_wdt_dev); -} -static const struct of_device_id mt7621_wdt_match[] = { { .compatible ="mediatek,mt7621-wdt" }, {},
@@ -170,8 +159,6 @@ MODULE_DEVICE_TABLE(of, mt7621_wdt_match);static struct platform_driver mt7621_wdt_driver = { .probe = mt7621_wdt_probe, - .remove = mt7621_wdt_remove, - .shutdown = mt7621_wdt_shutdown, .driver = { .name =KBUILD_MODNAME , .of_match_table = mt7621_wdt_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 37/62 watchdog: mtk_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/mtk_wdt.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-)
drivers/watchdog/mtk_wdt.c +2 -20
@@ -192,7 +192,8 @@ static int mtk_wdt_probe(struct platform_device *pdev)mtk_wdt_stop (&mtk_wdt->wdt_dev); - err =watchdog_register_device (&mtk_wdt->wdt_dev); +watchdog_stop_on_reboot (&mtk_wdt->wdt_dev); + err =devm_watchdog_register_device (&pdev->dev, &mtk_wdt->wdt_dev);if (unlikely (err))return err;
@@ -202,23 +203,6 @@ static int mtk_wdt_probe(struct platform_device *pdev)return 0 ; } -static void mtk_wdt_shutdown (struct platform_device *pdev) -{ -struct mtk_wdt_dev *mtk_wdt =platform_get_drvdata (pdev); - -if (watchdog_active (&mtk_wdt->wdt_dev)) -mtk_wdt_stop (&mtk_wdt->wdt_dev); -} - -static int mtk_wdt_remove (struct platform_device *pdev) -{ -struct mtk_wdt_dev *mtk_wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&mtk_wdt->wdt_dev); - -return 0 ; -} -#ifdef CONFIG_PM_SLEEP static int mtk_wdt_suspend (struct device *dev) {
@@ -256,8 +240,6 @@ static const struct dev_pm_ops mtk_wdt_pm_ops = {static struct platform_driver mtk_wdt_driver = { .probe = mtk_wdt_probe, - .remove = mtk_wdt_remove, - .shutdown = mtk_wdt_shutdown, .driver = { .name =DRV_NAME , .pm = &mtk_wdt_pm_ops,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 38/62 watchdog: nic7018_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/nic7018_wdt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/watchdog/nic7018_wdt.c +1 -3
@@ -219,7 +219,7 @@ static int nic7018_probe(struct platform_device *pdev)/* Unlock WDT register */ outb (UNLOCK , wdt->io_base +WDT_REG_LOCK ); - ret =watchdog_register_device (wdd); + ret =devm_watchdog_register_device (dev, wdd);if (ret) {outb (LOCK , wdt->io_base +WDT_REG_LOCK );dev_err (dev,"failed to register watchdog\n" );
@@ -235,8 +235,6 @@ static int nic7018_remove(struct platform_device *pdev) {struct nic7018_wdt *wdt =platform_get_drvdata (pdev); -watchdog_unregister_device (&wdt->wdd); -/* Lock WDT register */ outb (LOCK , wdt->io_base +WDT_REG_LOCK );
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 39/62 watchdog: of_xilinx_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/of_xilinx_wdt.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)
drivers/watchdog/of_xilinx_wdt.c +8 -20
@@ -210,38 +210,27 @@ static int xwdt_probe(struct platform_device *pdev)dev_err (&pdev->dev,"unable to enable clock\n" );return rc; } + rc =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + xdev->clk); +if (rc) +return rc; rc =xwdt_selftest (xdev);if (rc ==XWT_TIMER_FAILED ) {dev_err (&pdev->dev,"SelfTest routine error\n" ); - goto err_clk_disable; +return rc; } - rc =watchdog_register_device (xilinx_wdt_wdd); + rc =devm_watchdog_register_device (&pdev->dev, xilinx_wdt_wdd);if (rc) {dev_err (&pdev->dev,"Cannot register watchdog (err=%d)\n" , rc); - goto err_clk_disable; +return rc; }dev_info (&pdev->dev,"Xilinx Watchdog Timer at %p with timeout %ds\n" , xdev->base, xilinx_wdt_wdd->timeout); -platform_set_drvdata (pdev, xdev); - -return 0 ; -err_clk_disable: -clk_disable_unprepare (xdev->clk); - -return rc; -} - -static int xwdt_remove (struct platform_device *pdev) -{ -struct xwdt_device *xdev =platform_get_drvdata (pdev); - -watchdog_unregister_device (&xdev->xilinx_wdt_wdd); -clk_disable_unprepare (xdev->clk); -return 0 ; }
@@ -255,7 +244,6 @@ MODULE_DEVICE_TABLE(of, xwdt_of_match);static struct platform_driver xwdt_driver = { .probe = xwdt_probe, - .remove = xwdt_remove, .driver = { .name =WATCHDOG_NAME , .of_match_table = xwdt_of_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 40/62 watchdog: omap_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/omap_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/omap_wdt.c +1 -2
@@ -274,7 +274,7 @@ static int omap_wdt_probe(struct platform_device *pdev)if (!early_enable)omap_wdt_disable (wdev); - ret =watchdog_register_device (&wdev->wdog); + ret =devm_watchdog_register_device (&pdev->dev, &wdev->wdog);if (ret) {pm_runtime_disable (wdev->dev);return ret;
@@ -309,7 +309,6 @@ static int omap_wdt_remove(struct platform_device *pdev)struct omap_wdt_dev *wdev =platform_get_drvdata (pdev);pm_runtime_disable (wdev->dev); -watchdog_unregister_device (&wdev->wdog);return 0 ; }
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 41/62 watchdog: orion_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_clk_get() if the device parameter is not NULL
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Replace 'of_clk_get_by_name(np, name)' with 'devm_clk_get(dev, name)'
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/orion_wdt.c | 87 ++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 48 deletions(-)
drivers/watchdog/orion_wdt.c +39 -48
@@ -78,14 +78,17 @@ static int orion_wdt_clock_init(struct platform_device *pdev, {int ret; - dev->clk =clk_get (&pdev->dev,NULL ); + dev->clk =devm_clk_get (&pdev->dev,NULL );if (IS_ERR (dev->clk))return PTR_ERR (dev->clk); ret =clk_prepare_enable (dev->clk); -if (ret) { -clk_put (dev->clk); +if (ret) +return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (ret)return ret; - } dev->clk_rate =clk_get_rate (dev->clk);return 0 ;
@@ -96,14 +99,17 @@ static int armada370_wdt_clock_init(struct platform_device *pdev, {int ret; - dev->clk =clk_get (&pdev->dev,NULL ); + dev->clk =devm_clk_get (&pdev->dev,NULL );if (IS_ERR (dev->clk))return PTR_ERR (dev->clk); ret =clk_prepare_enable (dev->clk); -if (ret) { -clk_put (dev->clk); +if (ret) +return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (ret)return ret; - }/* Setup watchdog input clock */ atomic_io_modify(dev->reg + TIMER_CTRL,
@@ -119,13 +125,16 @@ static int armada375_wdt_clock_init(struct platform_device *pdev, {int ret; - dev->clk =of_clk_get_by_name (pdev->dev.of_node,"fixed" ); + dev->clk =devm_clk_get (&pdev->dev,"fixed" );if (!IS_ERR (dev->clk)) { ret =clk_prepare_enable (dev->clk); -if (ret) { -clk_put (dev->clk); +if (ret) +return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (ret)return ret; - } atomic_io_modify(dev->reg + TIMER_CTRL, WDT_AXP_FIXED_ENABLE_BIT,
@@ -136,15 +145,18 @@ static int armada375_wdt_clock_init(struct platform_device *pdev, }/* Mandatory fallback for proper devicetree backward compatibility */ - dev->clk =clk_get (&pdev->dev,NULL ); + dev->clk =devm_clk_get (&pdev->dev,NULL );if (IS_ERR (dev->clk))return PTR_ERR (dev->clk); ret =clk_prepare_enable (dev->clk); -if (ret) { -clk_put (dev->clk); +if (ret) +return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (ret)return ret; - } atomic_io_modify(dev->reg + TIMER_CTRL, WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT),
@@ -159,14 +171,17 @@ static int armadaxp_wdt_clock_init(struct platform_device *pdev, {int ret; - dev->clk =of_clk_get_by_name (pdev->dev.of_node,"fixed" ); + dev->clk =devm_clk_get (&pdev->dev,"fixed" );if (IS_ERR (dev->clk))return PTR_ERR (dev->clk); ret =clk_prepare_enable (dev->clk); -if (ret) { -clk_put (dev->clk); +if (ret) +return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (ret)return ret; - }/* Enable the fixed watchdog clock input */ atomic_io_modify(dev->reg + TIMER_CTRL,
@@ -570,7 +585,6 @@ static int orion_wdt_probe(struct platform_device *pdev) dev->wdt.parent = &pdev->dev;watchdog_init_timeout (&dev->wdt, heartbeat, &pdev->dev); -platform_set_drvdata (pdev, &dev->wdt);watchdog_set_drvdata (&dev->wdt, dev);/*
@@ -593,46 +607,23 @@ static int orion_wdt_probe(struct platform_device *pdev) pdev->name, dev);if (ret <0 ) {dev_err (&pdev->dev,"failed to request IRQ\n" ); - goto disable_clk; +return ret; } }watchdog_set_nowayout (&dev->wdt, nowayout); - ret =watchdog_register_device (&dev->wdt); +watchdog_stop_on_reboot (&dev->wdt); + ret =devm_watchdog_register_device (&pdev->dev, &dev->wdt);if (ret) - goto disable_clk; +return ret;pr_info ("Initial timeout %d sec%s\n" , dev->wdt.timeout, nowayout ?", nowayout" :"" );return 0 ; - -disable_clk: -clk_disable_unprepare (dev->clk); -clk_put (dev->clk); -return ret; -} - -static int orion_wdt_remove (struct platform_device *pdev) -{ -struct watchdog_device *wdt_dev =platform_get_drvdata (pdev); -struct orion_watchdog *dev =watchdog_get_drvdata (wdt_dev); - -watchdog_unregister_device (wdt_dev); -clk_disable_unprepare (dev->clk); -clk_put (dev->clk); -return 0 ; -} - -static void orion_wdt_shutdown (struct platform_device *pdev) -{ -struct watchdog_device *wdt_dev =platform_get_drvdata (pdev); -orion_wdt_stop (wdt_dev); }static struct platform_driver orion_wdt_driver = { .probe = orion_wdt_probe, - .remove = orion_wdt_remove, - .shutdown = orion_wdt_shutdown, .driver = { .name ="orion_wdt" , .of_match_table = orion_wdt_of_match_table,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 44/62 watchdog: pnx4008_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/pnx4008_wdt.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/watchdog/pnx4008_wdt.c +7 -16
@@ -202,6 +202,11 @@ static int pnx4008_wdt_probe(struct platform_device *pdev) ret =clk_prepare_enable (wdt_clk);if (ret)return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + wdt_clk); +if (ret) +return ret; pnx4008_wdd.bootstatus = (readl (WDTIM_RES (wdt_base)) &WDOG_RESET ) ?WDIOF_CARDRESET :0 ;
@@ -211,28 +216,15 @@ static int pnx4008_wdt_probe(struct platform_device *pdev)pnx4008_wdt_stop (&pnx4008_wdd);/* disable for now */ - ret =watchdog_register_device (&pnx4008_wdd); + ret =devm_watchdog_register_device (&pdev->dev, &pnx4008_wdd);if (ret <0 ) {dev_err (&pdev->dev,"cannot register watchdog device\n" ); - goto disable_clk; +return ret; }dev_info (&pdev->dev,"heartbeat %d sec\n" , pnx4008_wdd.timeout);return 0 ; - -disable_clk: -clk_disable_unprepare (wdt_clk); -return ret; -} - -static int pnx4008_wdt_remove (struct platform_device *pdev) -{ -watchdog_unregister_device (&pnx4008_wdd); - -clk_disable_unprepare (wdt_clk); - -return 0 ; }#ifdef CONFIG_OF
@@ -249,7 +241,6 @@ static struct platform_driver platform_wdt_driver = { .of_match_table = of_match_ptr(pnx4008_wdt_match), }, .probe = pnx4008_wdt_probe, - .remove = pnx4008_wdt_remove, };module_platform_driver (platform_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 43/62 watchdog: pic32-wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/pic32-wdt.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-)
drivers/watchdog/pic32-wdt.c +9 -25
@@ -197,19 +197,22 @@ static int pic32_wdt_drv_probe(struct platform_device *pdev)dev_err (&pdev->dev,"clk enable failed\n" );return ret; } + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + wdt->clk); +if (ret) +return ret;if (pic32_wdt_is_win_enabled (wdt)) {dev_err (&pdev->dev,"windowed-clear mode is not supported.\n" ); - ret = -ENODEV ; - goto out_disable_clk; +return -ENODEV ; } wdd->timeout =pic32_wdt_get_timeout_secs (wdt, &pdev->dev);if (!wdd->timeout) {dev_err (&pdev->dev,"failed to read watchdog register timeout\n" ); - ret = -EINVAL ; - goto out_disable_clk; +return -EINVAL ; }dev_info (&pdev->dev,"timeout %d\n" , wdd->timeout);
@@ -219,36 +222,17 @@ static int pic32_wdt_drv_probe(struct platform_device *pdev)watchdog_set_nowayout (wdd,WATCHDOG_NOWAYOUT );watchdog_set_drvdata (wdd, wdt); - ret =watchdog_register_device (wdd); + ret =devm_watchdog_register_device (&pdev->dev, wdd);if (ret) {dev_err (&pdev->dev,"watchdog register failed, err %d\n" , ret); - goto out_disable_clk; +return ret; } -platform_set_drvdata (pdev, wdd); - -return 0 ; - -out_disable_clk: -clk_disable_unprepare (wdt->clk); - -return ret; -} - -static int pic32_wdt_drv_remove (struct platform_device *pdev) -{ -struct watchdog_device *wdd =platform_get_drvdata (pdev); -struct pic32_wdt *wdt =watchdog_get_drvdata (wdd); - -watchdog_unregister_device (wdd); -clk_disable_unprepare (wdt->clk); -return 0 ; }static struct platform_driver pic32_wdt_driver = { .probe = pic32_wdt_drv_probe, - .remove = pic32_wdt_drv_remove, .driver = { .name ="pic32-wdt" , .of_match_table =of_match_ptr (pic32_wdt_dt_ids),
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 42/62 watchdog: pic32-dmt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/pic32-dmt.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-)
drivers/watchdog/pic32-dmt.c +8 -21
@@ -193,13 +193,17 @@ static int pic32_dmt_probe(struct platform_device *pdev) ret =clk_prepare_enable (dmt->clk);if (ret)return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dmt->clk); +if (ret) +return ret; wdd->timeout =pic32_dmt_get_timeout_secs (dmt);if (!wdd->timeout) {dev_err (&pdev->dev,"failed to read watchdog register timeout\n" ); - ret = -EINVAL ; - goto out_disable_clk; +return -EINVAL ; }dev_info (&pdev->dev,"timeout %d\n" , wdd->timeout);
@@ -209,28 +213,12 @@ static int pic32_dmt_probe(struct platform_device *pdev)watchdog_set_nowayout (wdd,WATCHDOG_NOWAYOUT );watchdog_set_drvdata (wdd, dmt); - ret =watchdog_register_device (wdd); + ret =devm_watchdog_register_device (&pdev->dev, wdd);if (ret) {dev_err (&pdev->dev,"watchdog register failed, err %d\n" , ret); - goto out_disable_clk; +return ret; } -platform_set_drvdata (pdev, wdd); -return 0 ; - -out_disable_clk: -clk_disable_unprepare (dmt->clk); -return ret; -} - -static int pic32_dmt_remove (struct platform_device *pdev) -{ -struct watchdog_device *wdd =platform_get_drvdata (pdev); -struct pic32_dmt *dmt =watchdog_get_drvdata (wdd); - -watchdog_unregister_device (wdd); -clk_disable_unprepare (dmt->clk); -return 0 ; }
@@ -242,7 +230,6 @@ MODULE_DEVICE_TABLE(of, pic32_dmt_of_ids);static struct platform_driver pic32_dmt_driver = { .probe = pic32_dmt_probe, - .remove = pic32_dmt_remove, .driver = { .name ="pic32-dmt" , .of_match_table =of_match_ptr (pic32_dmt_of_ids),
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 45/62 watchdog: qcom-wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/qcom-wdt.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)
drivers/watchdog/qcom-wdt.c +8 -19
@@ -185,6 +185,11 @@ static int qcom_wdt_probe(struct platform_device *pdev)dev_err (&pdev->dev,"failed to setup clock\n" );return ret; } + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + wdt->clk); +if (ret) +return ret;/* * We use the clock rate to calculate the max timeout, so ensure it's
@@ -198,8 +203,7 @@ static int qcom_wdt_probe(struct platform_device *pdev)if (wdt->rate ==0 || wdt->rate >0x10000000U ) {dev_err (&pdev->dev,"invalid clock rate\n" ); - ret = -EINVAL ; - goto err_clk_unprepare; +return -EINVAL ; } wdt->wdd.info = &qcom_wdt_info;
@@ -220,26 +224,12 @@ static int qcom_wdt_probe(struct platform_device *pdev) wdt->wdd.timeout =min (wdt->wdd.max_timeout,30U );watchdog_init_timeout (&wdt->wdd,0 , &pdev->dev); - ret =watchdog_register_device (&wdt->wdd); + ret =devm_watchdog_register_device (&pdev->dev, &wdt->wdd);if (ret) {dev_err (&pdev->dev,"failed to register watchdog\n" ); - goto err_clk_unprepare; +return ret; } -platform_set_drvdata (pdev, wdt); -return 0 ; - -err_clk_unprepare: -clk_disable_unprepare (wdt->clk); -return ret; -} - -static int qcom_wdt_remove (struct platform_device *pdev) -{ -struct qcom_wdt *wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&wdt->wdd); -clk_disable_unprepare (wdt->clk);return 0 ; }
@@ -253,7 +243,6 @@ MODULE_DEVICE_TABLE(of, qcom_wdt_of_table);static struct platform_driver qcom_watchdog_driver = { .probe = qcom_wdt_probe, - .remove = qcom_wdt_remove, .driver = { .name =KBUILD_MODNAME , .of_match_table = qcom_wdt_of_table,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 46/62 watchdog: renesas_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/renesas_wdt.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/watchdog/renesas_wdt.c +1 -5
@@ -157,7 +157,6 @@ static int rwdt_probe(struct platform_device *pdev) priv->wdev.max_timeout =65536 / clks_per_sec; priv->wdev.timeout =min (priv->wdev.max_timeout,RWDT_DEFAULT_TIMEOUT ); -platform_set_drvdata (pdev, priv);watchdog_set_drvdata (&priv->wdev, priv);watchdog_set_nowayout (&priv->wdev, nowayout);
@@ -166,7 +165,7 @@ static int rwdt_probe(struct platform_device *pdev)if (ret)dev_warn (&pdev->dev,"Specified timeout value invalid, using default\n" ); - ret =watchdog_register_device (&priv->wdev); + ret =devm_watchdog_register_device (&pdev->dev, &priv->wdev);if (ret <0 ) {pm_runtime_put (&pdev->dev);pm_runtime_disable (&pdev->dev);
@@ -178,9 +177,6 @@ static int rwdt_probe(struct platform_device *pdev)static int rwdt_remove (struct platform_device *pdev) { -struct rwdt_priv *priv =platform_get_drvdata (pdev); - -watchdog_unregister_device (&priv->wdev);pm_runtime_put (&pdev->dev);pm_runtime_disable (&pdev->dev);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 47/62 watchdog: retu_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Call cancel_delayed_work_sync() using devm_add_action_or_reset()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/retu_wdt.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/watchdog/retu_wdt.c +6 -15
@@ -136,8 +136,13 @@ static int retu_wdt_probe(struct platform_device *pdev) wdev->dev = &pdev->dev;INIT_DELAYED_WORK (&wdev->ping_work, retu_wdt_ping_work); + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))cancel_delayed_work_sync, + &wdev->ping_work); +if (ret) +return ret; - ret =watchdog_register_device (retu_wdt); + ret =devm_watchdog_register_device (&pdev->dev, retu_wdt);if (ret <0 )return ret;
@@ -146,25 +151,11 @@ static int retu_wdt_probe(struct platform_device *pdev)else retu_wdt_ping_enable (wdev); -platform_set_drvdata (pdev, retu_wdt); - -return 0 ; -} - -static int retu_wdt_remove (struct platform_device *pdev) -{ -struct watchdog_device *wdog =platform_get_drvdata (pdev); -struct retu_wdt_dev *wdev =watchdog_get_drvdata (wdog); - -watchdog_unregister_device (wdog); -cancel_delayed_work_sync (&wdev->ping_work); -return 0 ; }static struct platform_driver retu_wdt_driver = { .probe = retu_wdt_probe, - .remove = retu_wdt_remove, .driver = { .name ="retu-wdt" , },
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 48/62 watchdog: rt2880_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/rt2880_wdt.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/watchdog/rt2880_wdt.c +2 -15
@@ -166,25 +166,14 @@ static int rt288x_wdt_probe(struct platform_device *pdev) &pdev->dev);watchdog_set_nowayout (&rt288x_wdt_dev, nowayout); - ret =watchdog_register_device (&rt288x_wdt_dev); +watchdog_stop_on_reboot (&rt288x_wdt_dev); + ret =devm_watchdog_register_device (&pdev->dev, &rt288x_wdt_dev);if (!ret)dev_info (&pdev->dev,"Initialized\n" );return 0 ; } -static int rt288x_wdt_remove (struct platform_device *pdev) -{ -watchdog_unregister_device (&rt288x_wdt_dev); - -return 0 ; -} - -static void rt288x_wdt_shutdown (struct platform_device *pdev) -{ -rt288x_wdt_stop (&rt288x_wdt_dev); -} -static const struct of_device_id rt288x_wdt_match[] = { { .compatible ="ralink,rt2880-wdt" }, {},
@@ -193,8 +182,6 @@ MODULE_DEVICE_TABLE(of, rt288x_wdt_match);static struct platform_driver rt288x_wdt_driver = { .probe = rt288x_wdt_probe, - .remove = rt288x_wdt_remove, - .shutdown = rt288x_wdt_shutdown, .driver = { .name =KBUILD_MODNAME , .of_match_table = rt288x_wdt_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 49/62 watchdog: sama5d4_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/sama5d4_wdt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/watchdog/sama5d4_wdt.c +1 -3
@@ -234,7 +234,7 @@ static int sama5d4_wdt_probe(struct platform_device *pdev)watchdog_set_nowayout (wdd, nowayout); - ret =watchdog_register_device (wdd); + ret =devm_watchdog_register_device (&pdev->dev, wdd);if (ret) {dev_err (&pdev->dev,"failed to register watchdog device\n" );return ret;
@@ -254,8 +254,6 @@ static int sama5d4_wdt_remove(struct platform_device *pdev)sama5d4_wdt_stop (&wdt->wdd); -watchdog_unregister_device (&wdt->wdd); -return 0 ; }
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 50/62 watchdog: sbsa_gwdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Replace &pdev->dev with dev if 'struct device *dev' is a declared variable
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/sbsa_gwdt.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)
drivers/watchdog/sbsa_gwdt.c +2 -19
@@ -312,7 +312,8 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)*/ sbsa_gwdt_set_timeout (wdd, wdd->timeout); - ret =watchdog_register_device (wdd); +watchdog_stop_on_reboot (wdd); + ret =devm_watchdog_register_device (dev, wdd);if (ret)return ret;
@@ -323,22 +324,6 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)return 0 ; } -static void sbsa_gwdt_shutdown (struct platform_device *pdev) -{ -struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); - -sbsa_gwdt_stop (&gwdt->wdd); -} - -static int sbsa_gwdt_remove (struct platform_device *pdev) -{ -struct sbsa_gwdt *gwdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&gwdt->wdd); - -return 0 ; -} -/* Disable watchdog if it is active during suspend */ static int __maybe_unused sbsa_gwdt_suspend (struct device *dev) {
@@ -384,8 +369,6 @@ static struct platform_driver sbsa_gwdt_driver = { .of_match_table = sbsa_gwdt_of_match, }, .probe = sbsa_gwdt_probe, - .remove = sbsa_gwdt_remove, - .shutdown = sbsa_gwdt_shutdown, .id_table = sbsa_gwdt_pdev_match, };
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 51/62 watchdog: shwdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/shwdt.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/watchdog/shwdt.c +2 -9
@@ -269,7 +269,8 @@ static int sh_wdt_probe(struct platform_device *pdev)dev_info (&pdev->dev,"configured with heartbeat=%d sec (nowayout=%d)\n" , sh_wdt_dev.timeout, nowayout); - rc =watchdog_register_device (&sh_wdt_dev); +watchdog_stop_on_reboot (&sh_wdt_dev); + rc =devm_watchdog_register_device (&pdev->dev, &sh_wdt_dev);if (unlikely (rc)) {dev_err (&pdev->dev,"Can't register watchdog (err=%d)\n" , rc);return rc;
@@ -287,18 +288,11 @@ static int sh_wdt_probe(struct platform_device *pdev)static int sh_wdt_remove (struct platform_device *pdev) { -watchdog_unregister_device (&sh_wdt_dev); -pm_runtime_disable (&pdev->dev);return 0 ; } -static void sh_wdt_shutdown (struct platform_device *pdev) -{ -sh_wdt_stop (&sh_wdt_dev); -} -static struct platform_driver sh_wdt_driver = { .driver = { .name =DRV_NAME ,
@@ -306,7 +300,6 @@ static struct platform_driver sh_wdt_driver = { .probe = sh_wdt_probe, .remove = sh_wdt_remove, - .shutdown = sh_wdt_shutdown, };static int __init sh_wdt_init (void )
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 52/62 watchdog: sirfsoc_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/sirfsoc_wdt.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/watchdog/sirfsoc_wdt.c +3 -10
@@ -161,7 +161,8 @@ static int sirfsoc_wdt_probe(struct platform_device *pdev)watchdog_set_nowayout (&sirfsoc_wdd, nowayout); sirfsoc_wdd.parent = &pdev->dev; - ret =watchdog_register_device (&sirfsoc_wdd); +watchdog_stop_on_reboot (&sirfsoc_wdd); + ret =devm_watchdog_register_device (&pdev->dev, &sirfsoc_wdd);if (ret)return ret;
@@ -170,16 +171,9 @@ static int sirfsoc_wdt_probe(struct platform_device *pdev)return 0 ; } -static void sirfsoc_wdt_shutdown (struct platform_device *pdev) -{ -struct watchdog_device *wdd =platform_get_drvdata (pdev); - -sirfsoc_wdt_disable (wdd); -} -static int sirfsoc_wdt_remove (struct platform_device *pdev) { -sirfsoc_wdt_shutdown (pdev); +sirfsoc_wdt_disable (platform_get_drvdata (pdev));return 0 ; }
@@ -221,7 +215,6 @@ static struct platform_driver sirfsoc_wdt_driver = { }, .probe = sirfsoc_wdt_probe, .remove = sirfsoc_wdt_remove, - .shutdown = sirfsoc_wdt_shutdown, };module_platform_driver (sirfsoc_wdt_driver);
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 53/62 watchdog: st_lpc_wdt: Convert to use device managed functions
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/st_lpc_wdt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/watchdog/st_lpc_wdt.c +6 -5
@@ -215,6 +215,11 @@ static int st_wdog_probe(struct platform_device *pdev)dev_err (&pdev->dev,"Unable to enable clock\n" );return ret; } + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + clk); +if (ret) +return ret;watchdog_set_drvdata (&st_wdog_dev, st_wdog);watchdog_set_nowayout (&st_wdog_dev,WATCHDOG_NOWAYOUT );
@@ -223,14 +228,12 @@ static int st_wdog_probe(struct platform_device *pdev) ret =watchdog_init_timeout (&st_wdog_dev,0 , &pdev->dev);if (ret) {dev_err (&pdev->dev,"Unable to initialise watchdog timeout\n" ); -clk_disable_unprepare (clk);return ret; } - ret =watchdog_register_device (&st_wdog_dev); + ret =devm_watchdog_register_device (&pdev->dev, &st_wdog_dev);if (ret) {dev_err (&pdev->dev,"Unable to register watchdog\n" ); -clk_disable_unprepare (clk);return ret; }
@@ -247,8 +250,6 @@ static int st_wdog_remove(struct platform_device *pdev)struct st_wdog *st_wdog =watchdog_get_drvdata (&st_wdog_dev);st_wdog_setup (st_wdog, false); -watchdog_unregister_device (&st_wdog_dev); -clk_disable_unprepare (st_wdog->clk);return 0 ; }
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 54/62 watchdog: stmp3xxx_rtc_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/stmp3xxx_rtc_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/stmp3xxx_rtc_wdt.c +1 -2
@@ -99,7 +99,7 @@ static int stmp3xxx_wdt_probe(struct platform_device *pdev) stmp3xxx_wdd.timeout =clamp_t (unsigned, heartbeat,1 ,STMP3XXX_MAX_TIMEOUT ); stmp3xxx_wdd.parent = &pdev->dev; - ret =watchdog_register_device (&stmp3xxx_wdd); + ret =devm_watchdog_register_device (&pdev->dev, &stmp3xxx_wdd);if (ret <0 ) {dev_err (&pdev->dev,"cannot register watchdog device\n" );return ret;
@@ -116,7 +116,6 @@ static int stmp3xxx_wdt_probe(struct platform_device *pdev)static int stmp3xxx_wdt_remove (struct platform_device *pdev) {unregister_reboot_notifier (&wdt_notifier); -watchdog_unregister_device (&stmp3xxx_wdd);return 0 ; }
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 55/62 watchdog: sunxi_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/sunxi_wdt.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/watchdog/sunxi_wdt.c +2 -22
@@ -242,8 +242,6 @@ static int sunxi_wdt_probe(struct platform_device *pdev)if (!sunxi_wdt)return -EINVAL ; -platform_set_drvdata (pdev, sunxi_wdt); - device =of_match_device (sunxi_wdt_dt_ids, &pdev->dev);if (!device)return -ENODEV ;
@@ -270,7 +268,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev)sunxi_wdt_stop (&sunxi_wdt->wdt_dev); - err =watchdog_register_device (&sunxi_wdt->wdt_dev); +watchdog_stop_on_reboot (&sunxi_wdt->wdt_dev); + err =devm_watchdog_register_device (&pdev->dev, &sunxi_wdt->wdt_dev);if (unlikely (err))return err;
@@ -280,27 +279,8 @@ static int sunxi_wdt_probe(struct platform_device *pdev)return 0 ; } -static int sunxi_wdt_remove (struct platform_device *pdev) -{ -struct sunxi_wdt_dev *sunxi_wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&sunxi_wdt->wdt_dev); -watchdog_set_drvdata (&sunxi_wdt->wdt_dev,NULL ); - -return 0 ; -} - -static void sunxi_wdt_shutdown (struct platform_device *pdev) -{ -struct sunxi_wdt_dev *sunxi_wdt =platform_get_drvdata (pdev); - -sunxi_wdt_stop (&sunxi_wdt->wdt_dev); -} -static struct platform_driver sunxi_wdt_driver = { .probe = sunxi_wdt_probe, - .remove = sunxi_wdt_remove, - .shutdown = sunxi_wdt_shutdown, .driver = { .name =DRV_NAME , .of_match_table = sunxi_wdt_dt_ids,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 56/62 watchdog: tangox_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/tangox_wdt.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/watchdog/tangox_wdt.c +9 -13
@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err; dev->clk_rate =clk_get_rate (dev->clk); -if (!dev->clk_rate) { - err = -EINVAL ; - goto err; - } +if (!dev->clk_rate) +return -EINVAL ; dev->wdt.parent = &pdev->dev; dev->wdt.info = &tangox_wdt_info;
@@ -173,19 +176,15 @@ static int tangox_wdt_probe(struct platform_device *pdev)watchdog_set_restart_priority (&dev->wdt,128 ); - err =watchdog_register_device (&dev->wdt); + err =devm_watchdog_register_device (&pdev->dev, &dev->wdt);if (err) - goto err; +return err;platform_set_drvdata (pdev, dev);dev_info (&pdev->dev,"SMP86xx/SMP87xx watchdog registered\n" );return 0 ; - - err: -clk_disable_unprepare (dev->clk); -return err; }static int tangox_wdt_remove (struct platform_device *pdev)
@@ -193,9 +192,6 @@ static int tangox_wdt_remove(struct platform_device *pdev)struct tangox_wdt_device *dev =platform_get_drvdata (pdev);tangox_wdt_stop (&dev->wdt); -clk_disable_unprepare (dev->clk); - -watchdog_unregister_device (&dev->wdt);return 0 ; }
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 57/62 watchdog: tegra_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/tegra_wdt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/watchdog/tegra_wdt.c +1 -3
@@ -226,7 +226,7 @@ static int tegra_wdt_probe(struct platform_device *pdev)watchdog_set_nowayout (wdd, nowayout); - ret =watchdog_register_device (wdd); + ret =devm_watchdog_register_device (&pdev->dev, wdd);if (ret) {dev_err (&pdev->dev,"failed to register watchdog device\n" );
@@ -248,8 +248,6 @@ static int tegra_wdt_remove(struct platform_device *pdev)tegra_wdt_stop (&wdt->wdd); -watchdog_unregister_device (&wdt->wdd); -dev_info (&pdev->dev,"removed wdt\n" );return 0 ;
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 58/62 watchdog: ts4800_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/ts4800_wdt.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/watchdog/ts4800_wdt.c +1 -13
@@ -168,15 +168,13 @@ static int ts4800_wdt_probe(struct platform_device *pdev)*/ ts4800_wdt_stop (wdd); - ret =watchdog_register_device (wdd); + ret =devm_watchdog_register_device (&pdev->dev, wdd);if (ret) {dev_err (&pdev->dev,"failed to register watchdog device\n" );return ret; } -platform_set_drvdata (pdev, wdt); -dev_info (&pdev->dev,"initialized (timeout = %d sec, nowayout = %d)\n" , wdd->timeout, nowayout);
@@ -184,15 +182,6 @@ static int ts4800_wdt_probe(struct platform_device *pdev)return 0 ; } -static int ts4800_wdt_remove (struct platform_device *pdev) -{ -struct ts4800_wdt *wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&wdt->wdd); - -return 0 ; -} -static const struct of_device_id ts4800_wdt_of_match[] = { { .compatible ="technologic,ts4800-wdt" , }, { },
@@ -201,7 +190,6 @@ MODULE_DEVICE_TABLE(of, ts4800_wdt_of_match);static struct platform_driver ts4800_wdt_driver = { .probe = ts4800_wdt_probe, - .remove = ts4800_wdt_remove, .driver = { .name ="ts4800_wdt" , .of_match_table = ts4800_wdt_of_match,
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 59/62 watchdog: twl4030_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/twl4030_wdt.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)
drivers/watchdog/twl4030_wdt.c +1 -16
@@ -70,7 +70,6 @@ static const struct watchdog_ops twl4030_wdt_ops = {static int twl4030_wdt_probe (struct platform_device *pdev) { -int ret =0 ;struct watchdog_device *wdt; wdt =devm_kzalloc (&pdev->dev,sizeof (*wdt),GFP_KERNEL );
@@ -90,20 +89,7 @@ static int twl4030_wdt_probe(struct platform_device *pdev)twl4030_wdt_stop (wdt); - ret =watchdog_register_device (wdt); -if (ret) -return ret; - -return 0 ; -} - -static int twl4030_wdt_remove (struct platform_device *pdev) -{ -struct watchdog_device *wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (wdt); - -return 0 ; +return devm_watchdog_register_device (&pdev->dev, wdt); }#ifdef CONFIG_PM
@@ -137,7 +123,6 @@ MODULE_DEVICE_TABLE(of, twl_wdt_of_match);static struct platform_driver twl4030_wdt_driver = { .probe = twl4030_wdt_probe, - .remove = twl4030_wdt_remove, .suspend = twl4030_wdt_suspend, .resume = twl4030_wdt_resume, .driver = {
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 60/62 watchdog: txx9wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Use devm_add_action_or_reset() for calls to clk_disable_unprepare
- Use devm_clk_get() if the device parameter is not NULL
- Use devm_add_action_or_reset() for calls to clk_put() after clk_get() with NULL device parameter
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
- Replace shutdown function with call to watchdog_stop_on_reboot()
--- drivers/watchdog/txx9wdt.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-)
drivers/watchdog/txx9wdt.c +16 -30
@@ -110,21 +110,27 @@ static int __init txx9wdt_probe(struct platform_device *dev)if (IS_ERR (txx9_imclk)) { ret =PTR_ERR (txx9_imclk); txx9_imclk =NULL ; - goto exit; +return ret; } + ret =devm_add_action_or_reset (&dev->dev, (void (*)(void *))clk_put, +"imbus_clk" ); +if (ret) +return ret; ret =clk_prepare_enable (txx9_imclk);if (ret) { -clk_put (txx9_imclk); txx9_imclk =NULL ; - goto exit; +return ret; } + ret =devm_add_action_or_reset (&dev->dev, + (void (*)(void *))clk_disable_unprepare, + txx9_imclk); +if (ret) +return ret; res =platform_get_resource (dev,IORESOURCE_MEM ,0 ); txx9wdt_reg =devm_ioremap_resource (&dev->dev, res); -if (IS_ERR (txx9wdt_reg)) { - ret =PTR_ERR (txx9wdt_reg); - goto exit; - } +if (IS_ERR (txx9wdt_reg)) +return PTR_ERR (txx9wdt_reg);if (timeout <1 || timeout >WD_MAX_TIMEOUT ) timeout =TIMER_MARGIN ;
@@ -134,38 +140,18 @@ static int __init txx9wdt_probe(struct platform_device *dev) txx9wdt.parent = &dev->dev;watchdog_set_nowayout (&txx9wdt, nowayout); - ret =watchdog_register_device (&txx9wdt); +watchdog_stop_on_reboot (&txx9wdt); + ret =devm_watchdog_register_device (&dev->dev, &txx9wdt);if (ret) - goto exit; +return ret;pr_info ("Hardware Watchdog Timer: timeout=%d sec (max %ld) (nowayout= %d)\n" , timeout,WD_MAX_TIMEOUT , nowayout);return 0 ; -exit: -if (txx9_imclk) { -clk_disable_unprepare (txx9_imclk); -clk_put (txx9_imclk); - } -return ret; -} - -static int __exit txx9wdt_remove(struct platform_device *dev) -{ -watchdog_unregister_device (&txx9wdt); -clk_disable_unprepare (txx9_imclk); -clk_put (txx9_imclk); -return 0 ; -} - -static void txx9wdt_shutdown (struct platform_device *dev) -{ -txx9wdt_stop (&txx9wdt); }static struct platform_driver txx9wdt_driver = { - .remove =__exit_p (txx9wdt_remove), - .shutdown = txx9wdt_shutdown, .driver = { .name ="txx9wdt" , },
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 61/62 watchdog: ux500_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Drop remove function
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/ux500_wdt.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/watchdog/ux500_wdt.c +1 -9
@@ -105,7 +105,7 @@ static int ux500_wdt_probe(struct platform_device *pdev)/* set HW initial value */ prcmu_load_a9wdog (PRCMU_WDOG_ALL , timeout *1000 ); - ret =watchdog_register_device (&ux500_wdt); + ret =devm_watchdog_register_device (&pdev->dev, &ux500_wdt);if (ret)return ret;
@@ -114,13 +114,6 @@ static int ux500_wdt_probe(struct platform_device *pdev)return 0 ; } -static int ux500_wdt_remove (struct platform_device *dev) -{ -watchdog_unregister_device (&ux500_wdt); - -return 0 ; -} -#ifdef CONFIG_PM static int ux500_wdt_suspend (struct platform_device *pdev,pm_message_t state)
@@ -153,7 +146,6 @@ static int ux500_wdt_resume(struct platform_device *pdev)static struct platform_driver ux500_wdt_driver = { .probe = ux500_wdt_probe, - .remove = ux500_wdt_remove, .suspend = ux500_wdt_suspend, .resume = ux500_wdt_resume, .driver = {
Signature · 1 line
2.7.4
Guenter Roeck
maintainerPATCH 62/62 watchdog: wm831x_wdt: Convert to use device managed functions
In reply to Guenter RoeckUse device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Drop platform_set_drvdata()
- Use devm_watchdog_register_driver() to register watchdog device
--- drivers/watchdog/wm831x_wdt.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-)
drivers/watchdog/wm831x_wdt.c +7 -24
@@ -194,7 +194,7 @@ static int wm831x_wdt_probe(struct platform_device *pdev)if (ret <0 ) {dev_err (wm831x->dev,"Failed to read watchdog status: %d\n" , ret); - goto err; +return ret; } reg = ret;
@@ -203,10 +203,8 @@ static int wm831x_wdt_probe(struct platform_device *pdev) driver_data =devm_kzalloc (&pdev->dev,sizeof (*driver_data),GFP_KERNEL ); -if (!driver_data) { - ret = -ENOMEM ; - goto err; - } +if (!driver_data) +return -ENOMEM ;mutex_init (&driver_data->lock); driver_data->wm831x = wm831x;
@@ -253,7 +251,7 @@ static int wm831x_wdt_probe(struct platform_device *pdev)dev_err (wm831x->dev,"Failed to request update GPIO: %d\n" , ret); - goto err; +return ret; } driver_data->update_gpio = pdata->update_gpio;
@@ -269,37 +267,22 @@ static int wm831x_wdt_probe(struct platform_device *pdev) }else {dev_err (wm831x->dev,"Failed to unlock security key: %d\n" , ret); - goto err; +return ret; } } - ret =watchdog_register_device (&driver_data->wdt); + ret =devm_watchdog_register_device (&pdev->dev, &driver_data->wdt);if (ret !=0 ) {dev_err (wm831x->dev,"watchdog_register_device() failed: %d\n" , ret); - goto err; +return ret; } -platform_set_drvdata (pdev, driver_data); - -return 0 ; - -err: -return ret; -} - -static int wm831x_wdt_remove (struct platform_device *pdev) -{ -struct wm831x_wdt_drvdata *driver_data =platform_get_drvdata (pdev); - -watchdog_unregister_device (&driver_data->wdt); -return 0 ; }static struct platform_driver wm831x_wdt_driver = { .probe = wm831x_wdt_probe, - .remove = wm831x_wdt_remove, .driver = { .name ="wm831x-watchdog" , },
Signature · 1 line
2.7.4
Re: [PATCH 02/62] watchdog: aspeed_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 8 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
Quoted 7 lines
- Drop assignments to otherwise unused variables
- Drop remove function
- Dropplatform_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog deviceCc Joel Stanley <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Cheers,
Joel
Quoted 49 lines
--- drivers/watchdog/aspeed_wdt.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)drivers/watchdog/aspeed_wdt.c +1
-14@@ -136,15 +136,6 @@ static const struct watchdog_info aspeed_wdt_info = { .identity = KBUILD_MODNAME, }; -static int aspeed_wdt_remove (struct platform_device *pdev) -{ -struct aspeed_wdt *wdt =platform_get_drvdata (pdev); - -watchdog_unregister_device (&wdt->wdd); - -return 0 ; -} -static int aspeed_wdt_probe (struct platform_device *pdev) {struct aspeed_wdt *wdt;@@ -187,20 +178,17 @@ static int aspeed_wdt_probe(struct platform_device *pdev)set_bit (WDOG_HW_RUNNING , &wdt->wdd.status); } - ret =watchdog_register_device (&wdt->wdd); + ret =devm_watchdog_register_device (&pdev->dev, &wdt->wdd);if (ret) {dev_err (&pdev->dev,"failed to register\n" );return ret; } -platform_set_drvdata (pdev, wdt); -return 0 ; }static struct platform_driver aspeed_watchdog_driver = { .probe = aspeed_wdt_probe, - .remove = aspeed_wdt_remove, .driver = { .name =KBUILD_MODNAME , .of_match_table =of_match_ptr (aspeed_wdt_of_table), --2.7.4
Re: [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckQuoted 77 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Use
devm_add_action_or_reset()for calls toclk_disable_unprepare
- Check return value fromclk_prepare_enable()
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Usedevm_watchdog_register_driver()to register watchdog device
- Replace shutdown function with call towatchdog_stop_on_reboot()Cc Carlo Caione <[email protected]>Cc Kevin Hilman <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/watchdog/meson_gxbb_wdt.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-)drivers/watchdog/meson_gxbb_wdt.c +9
-26@@ -203,7 +203,14 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)if (IS_ERR (data->clk))return PTR_ERR (data->clk); -clk_prepare_enable (data->clk); + ret =clk_prepare_enable (data->clk); +if (ret) +return ret; + ret =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + data->clk); +if (ret) +return ret;platform_set_drvdata (pdev, data);@@ -224,37 +231,12 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)meson_gxbb_wdt_set_timeout (&data->wdt_dev, data->wdt_dev.timeout); - ret =watchdog_register_device (&data->wdt_dev); -if (ret) { -clk_disable_unprepare (data->clk); -return ret; - } - -return 0 ; -} - -static int meson_gxbb_wdt_remove (struct platform_device *pdev) -{ -struct meson_gxbb_wdt *data =platform_get_drvdata (pdev); - -watchdog_unregister_device (&data->wdt_dev); - -clk_disable_unprepare (data->clk); - -return 0 ; -} - -static void meson_gxbb_wdt_shutdown (struct platform_device *pdev) -{ -struct meson_gxbb_wdt *data =platform_get_drvdata (pdev); - -meson_gxbb_wdt_stop (&data->wdt_dev); +watchdog_stop_on_reboot (&data->wdt_dev);
drivers/watchdog/meson_gxbb_wdt.c static int meson_gxbb_wdt_probe(struct platform_device *pdev) · line 242
Quoted 10 lines
drivers/watchdog/meson_gxbb_wdt.c +1
-2+return devm_watchdog_register_device (&pdev->dev, &data->wdt_dev); }static struct platform_driver meson_gxbb_wdt_driver = { .probe = meson_gxbb_wdt_probe, - .remove = meson_gxbb_wdt_remove, - .shutdown = meson_gxbb_wdt_shutdown, .driver = { .name ="meson-gxbb-wdt" , .pm = &meson_gxbb_wdt_pm_ops,
Was on my todo list, glad you did this !
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 25 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Use
devm_add_action_or_reset()for calls toclk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Usedevm_watchdog_register_driver()to register watchdog deviceCc Marc Gonzalez <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/watchdog/tangox_wdt.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)drivers/watchdog/tangox_wdt.c +0
-0
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 8 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;
Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?
clk_disable_unprepare() is static inline, so gcc will have to define an auxiliary function either way. What do you think?
Regards.
drivers/watchdog/tangox_wdt.c +9 -0
@@ -114,6 +114,11 @@ static int tangox_wdt_restart(struct notifier_block *nb, unsigned long action,return NOTIFY_DONE ; } +static void cleanup (void *clk) +{ +clk_disable_unprepare (clk); +} +static int tangox_wdt_probe (struct platform_device *pdev) {struct tangox_wdt_device *dev;
@@ -138,6 +143,10 @@ static int tangox_wdt_probe(struct platform_device *pdev)if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, cleanup, dev->clk); +if (err) +return err; + dev->clk_rate =clk_get_rate (dev->clk);if (!dev->clk_rate) { err = -EINVAL ;
Guenter Roeck
maintainerRe: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
Quoted 12 lines · Marc Gonzalez
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;Hello Guenter,
Quoted 6 lines
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?
Not really. It would just make it more complicated to replace the call with devm_clk_prepare_enable(), should it ever find its way into the light of day.
Guenter
Re: [PATCH 55/62] watchdog: sunxi_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckQuoted 15 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Drop assignments to otherwise unused variables
- Drop remove function
- Dropplatform_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog device
- Replace shutdown function with call towatchdog_stop_on_reboot()
Quoted 3 lines
Cc Maxime Ripard <[email protected]>Cc Chen-Yu Tsai <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170111/51fbbf9a/attachment-0001.sig>
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 17 lines · Guenter Roeck
Quoted 15 lines · Marc Gonzalez
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?
Quoted 6 lines
Quoted 2 lines
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?Not really. It would just make it more complicated to replace the call with
devm_clk_prepare_enable(), should it ever find its way into the light of day.
More complicated, because the cleanup function will have to be deleted later? The compiler will warn if someone forgets to do that.
In my opinion, it's not a good idea to rely on the fact that casting void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected on most platforms. (It has undefined behavior, strictly speaking.)
Do you really dislike the portable solution I suggested? :-(
Regards.
Guenter Roeck
maintainerRe: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
Quoted 26 lines · Marc Gonzalez
Quoted 17 lines · Guenter Roeck
Quoted 15 lines · Marc Gonzalez
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?Quoted 6 lines
Quoted 2 lines
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?Not really. It would just make it more complicated to replace the call with
devm_clk_prepare_enable(), should it ever find its way into the light of day.
Quoted 7 lines
More complicated, because the cleanup function will have to be deleted later? The compiler will warn if someone forgets to do that.
In my opinion, it's not a good idea to rely on the fact that casting void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected on most platforms. (It has undefined behavior, strictly speaking.)
I do hear that you object to this code.
However, I must admit that you completely lost me here. It is a cast from one function pointer to another, passed as argument to another function, with a secondary cast of its argument from a typed pointer to a void pointer. I don't think C permits for "undefined behavior, strictly speaking". Besides, that same mechanism is already used elsewhere, which is how I got the idea. Are you claiming that there are situations where it won't work ?
Quoted 2 lines
Do you really dislike the portable solution I suggested? :-(
It is not more portable than the above. It is more expensive and adds more code.
Thanks,
Guenter
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Marc GonzalezQuoted 4 lines · Marc Gonzalez
Quoted 2 lines · Guenter Roeck
On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;
This looks wrong. There is no clk_unprepare_disable when devm_add_action_or_reset fails.
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?Quoted 6 lines
Quoted 2 lines
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?Not really. It would just make it more complicated to replace the call with
devm_clk_prepare_enable(), should it ever find its way into the light of day.
Quoted 6 lines
More complicated, because the cleanup function will have to be deleted later? The compiler will warn if someone forgets to do that.
In my opinion, it's not a good idea to rely on the fact that casting void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected on most platforms. (It has undefined behavior, strictly speaking.)
I would expect it to work on all (Linux) platforms. Anyhow, I wonder if there couldn't be found a better solution.
If in the end it looks like the following that would be good I think:
clk = devm_clk_get(...); if (IS_ERR(clk)) ... ret = devm_clk_prepare_enable(clk) if (ret) return ret; ...
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 36 lines · Guenter Roeck
Quoted 26 lines · Marc Gonzalez
Quoted 17 lines · Guenter Roeck
Quoted 15 lines · Marc Gonzalez
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?Quoted 6 lines
Quoted 2 lines
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?Not really. It would just make it more complicated to replace the call with
devm_clk_prepare_enable(), should it ever find its way into the light of day.Quoted 7 lines
More complicated, because the cleanup function will have to be deleted later? The compiler will warn if someone forgets to do that.
In my opinion, it's not a good idea to rely on the fact that casting void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected on most platforms. (It has undefined behavior, strictly speaking.)
I do hear that you object to this code.
Quoted 7 lines
However, I must admit that you completely lost me here. It is a cast from one function pointer to another, passed as argument to another function, with a secondary cast of its argument from a typed pointer to a void pointer. I don't think C permits for "undefined behavior, strictly speaking". Besides, that same mechanism is already used elsewhere, which is how I got the idea. Are you claiming that there are situations where it won't work ?
A pointer to void is interchangeable with any other pointer type. That doesn't necessarily imply that pointers to functions taking arguments of different pointer types (as we have here) are always compatible. I'd have to read the C standard carefully to see if there's any such promise, and I have other things to do right now. I am, however, not aware of any ABI (certainly none used by Linux) where it would pose a problem.
Signature · 1 line
M?ns Rullg?rd
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Uwe Kleine-KönigHello Uwe,
Quoted 5 lines · Uwe Kleine-K?nig
Quoted 4 lines · Marc Gonzalez
Quoted 2 lines · Guenter Roeck
On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
Quoted 12 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;This looks wrong. There is no
clk_unprepare_disablewhendevm_add_action_or_resetfails.
actually there is a call to clk_disable_unprepare() on error path, you may take a look at devm_add_action_or_reset() implementation.
Your comment is valid for devm_add_action() function though, but it's not the case here.
--
With best wishes,
Vladimir
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 30 lines · Guenter Roeck
Quoted 29 lines · Marc Gonzalez
Quoted 17 lines · Guenter Roeck
Quoted 15 lines · Marc Gonzalez
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?Quoted 6 lines
Quoted 2 lines
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?Not really. It would just make it more complicated to replace the call with
devm_clk_prepare_enable(), should it ever find its way into the light of day.More complicated, because the cleanup function will have to be deleted later? The compiler will warn if someone forgets to do that.
Quoted 8 lines
Quoted 3 lines
In my opinion, it's not a good idea to rely on the fact that casting void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected on most platforms. (It has undefined behavior, strictly speaking.)
I do hear that you object to this code.
However, I must admit that you completely lost me here. It is a cast from one function pointer to another,
Perhaps you are used to work at the assembly level, where pointers are just addresses, and all pointers are interchangeable.
At a slightly higher level (C abstract machine), it is not so.
Quoted 3 lines
passed as argument to another function,
with a secondary cast of its argument from a typed pointer to a void pointer. I don't think C permits for "undefined behavior, strictly speaking".
The C standard leaves quite a lot of behavior undefined, e.g.
char *foo = "hello";
foo[1] = 'a'; // UB
char buf[4];
*(int *)&buf = 0xdeadbeef; // UB
1 << 64; // UB
Quoted 3 lines
Besides, that same mechanism is already used elsewhere, which is how I got the idea. Are you claiming that there are situations where it won't work ?
If this technique is already used elsewhere in the kernel, then I'll crawl back under my rock (and weep).
I can see two issues with the code you propose.
First is the same for all casts: silencing potential warnings, e.g. if the prototype of clk_disable_unprepare ever changed. (Though casts are required for vararg function arguments.)
Second is just theory and not a real-world concern.
Quoted 4 lines
Quoted 1 line
Do you really dislike the portable solution I suggested? :-(
It is not more portable than the above. It is more expensive and adds more code.
Maybe I am mistaken. Can you tell me why adding an auxiliary function is more expensive? (In CPU cycles?)
clk_disable_unprepare() is static inline, so an auxiliary function exists either way (implicit or explicit).
Regards.
Re: [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 19 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Use
devm_add_action_or_reset()for calls toclk_disable_unprepare
- Usedevm_clk_get()if the device parameter is not NULL
- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Replacerequest_irq,request_threaded_irq, andrequest_any_context_irqwith their device managed equivalent
- Replace&pdev->devwith dev if 'struct device *dev' is a declared variable
- Usedevm_watchdog_register_driver()to register watchdog device
Quoted 2 lines
Cc Linus Walleij <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Yours,
Linus Walleij
Guenter Roeck
maintainerRe: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Uwe Kleine-KönigQuoted 5 lines · Uwe Kleine-K?nig
Quoted 4 lines · Marc Gonzalez
Quoted 2 lines · Guenter Roeck
On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;This looks wrong. There is no
clk_unprepare_disablewhendevm_add_action_or_resetfails.
That is what the _or_reset part of devm_add_action_or_reset() is for.
Quoted 25 lines
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?Quoted 6 lines
Quoted 2 lines
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?Not really. It would just make it more complicated to replace the call with
devm_clk_prepare_enable(), should it ever find its way into the light of day.Quoted 6 lines
More complicated, because the cleanup function will have to be deleted later? The compiler will warn if someone forgets to do that.
In my opinion, it's not a good idea to rely on the fact that casting void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected on most platforms. (It has undefined behavior, strictly speaking.)
I would expect it to work on all (Linux) platforms. Anyhow, I wonder if there couldn't be found a better solution.
If in the end it looks like the following that would be good I think:
Quoted 8 lines
clk = devm_clk_get(...); if (IS_ERR(clk)) ... ret = devm_clk_prepare_enable(clk) if (ret) return ret;
Yes, Dmitry tried to introduce devm_clk_prepare_enable() some 5 years ago, but the effort stalled.
My take is that it will be easy to write another coccinelle script to convert to devm_clk_prepare_enable() once that is available, but I didn't see the point of waiting for that, especially since it may never happen.
Guenter
Guenter Roeck
maintainerRe: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Marc GonzalezQuoted 51 lines · Marc Gonzalez
Quoted 30 lines · Guenter Roeck
Quoted 29 lines · Marc Gonzalez
Quoted 17 lines · Guenter Roeck
Quoted 15 lines · Marc Gonzalez
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?Quoted 6 lines
Quoted 2 lines
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?Not really. It would just make it more complicated to replace the call with
devm_clk_prepare_enable(), should it ever find its way into the light of day.More complicated, because the cleanup function will have to be deleted later? The compiler will warn if someone forgets to do that.
Quoted 8 lines
Quoted 3 lines
In my opinion, it's not a good idea to rely on the fact that casting void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected on most platforms. (It has undefined behavior, strictly speaking.)
I do hear that you object to this code.
However, I must admit that you completely lost me here. It is a cast from one function pointer to another,
Perhaps you are used to work at the assembly level, where pointers are just addresses, and all pointers are interchangeable.
At a slightly higher level (C abstract machine), it is not so.
Quoted 3 lines
passed as argument to another function,
with a secondary cast of its argument from a typed pointer to a void pointer. I don't think C permits for "undefined behavior, strictly speaking".The C standard leaves quite a lot of behavior undefined, e.g.
Quoted 8 lines
char *foo = "hello";
foo[1] = 'a'; // UBchar buf[4];
*(int *)&buf =0xdeadbeef; // UB1 << 64; // UB
Ah, yes, I stand corrected.
However, some other unrelated undefined behavior does not mean that this specific behavior is undefined.
So far we have a claim that a cast to a void * may somehow be different to a cast to a different pointer, if used as function argument, and that the behavior with such a cast may be undefined. In other words, you claim that a function implemented as, say,
void func(int *var) {}
might result in undefined behavior if some header file declares it as
void func(void *);
and it is called as
int var;
func(&var);That seems really far fetched to me.
I do get the message that you do not like this kind of cast. But that doesn't mean it is not correct.
Quoted 7 lines
Quoted 3 lines
Besides, that same mechanism is already used elsewhere, which is how I got the idea. Are you claiming that there are situations where it won't work ?
If this technique is already used elsewhere in the kernel, then I'll crawl back under my rock (and weep).
git grep "(void(\*)(void \*))"
and variants thereof:
git grep "(void(\*)"
Quoted 6 lines
I can see two issues with the code you propose.
First is the same for all casts: silencing potential warnings, e.g. if the prototype of
clk_disable_unprepareever changed. (Though casts are required for vararg function arguments.)
Understood. However, one should really hope that anyone changing an API has a look at all its callers and does not just pray that there are no problems.
Quoted 10 lines
Second is just theory and not a real-world concern.
Quoted 4 lines
Quoted 1 line
Do you really dislike the portable solution I suggested? :-(
It is not more portable than the above. It is more expensive and adds more code.
Maybe I am mistaken. Can you tell me why adding an auxiliary function is more expensive? (In CPU cycles?)
In terms of code required. The idea here is to simplify the code, not to make it more complex. The auxiliary function needs to be declared and maintained in each affected file. I do find it easier and better (and safer, for that matter) to let the C compiler handle it.
Guenter
Re: [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckQuoted 19 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Use
devm_add_action_or_reset()for calls toclk_disable_unprepare
- Check return value fromclk_prepare_enable()
- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Usedevm_watchdog_register_driver()to register watchdog device
- Replace shutdown function with call towatchdog_stop_on_reboot()
Quoted 3 lines
Cc Carlo Caione <[email protected]>Cc Kevin Hilman <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Nice, thanks for the cleanup!
Re: [PATCH 33/62] watchdog: meson_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckQuoted 15 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Drop assignments to otherwise unused variables
- Drop remove function
- Dropplatform_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog device
- Replace shutdown function with call towatchdog_stop_on_reboot()
Quoted 3 lines
Cc Carlo Caione <[email protected]>Cc Kevin Hilman <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Re: [PATCH 23/62] watchdog: intel-mid_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 8 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
Quoted 4 lines
- Drop assignments to otherwise unused variables
- Drop remove function
- Dropplatform_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog device
Quoted 47 lines
Signed-off-by Guenter Roeck <[email protected]>--- drivers/watchdog/intel-mid_wdt.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)drivers/watchdog/intel-mid_wdt.c +1
-11@@ -137,7 +137,6 @@ static int mid_wdt_probe(struct platform_device *pdev) wdt_dev->parent = &pdev->dev;watchdog_set_drvdata (wdt_dev, &pdev->dev); -platform_set_drvdata (pdev, wdt_dev); ret = devm_request_irq(&pdev->dev, pdata->irq, mid_wdt_irq, IRQF_SHARED | IRQF_NO_SUSPEND, "watchdog",@@ -151,7 +150,7 @@ static int mid_wdt_probe(struct platform_device *pdev)/* Make sure the watchdog is not running */ wdt_stop (wdt_dev); - ret =watchdog_register_device (wdt_dev); + ret =devm_watchdog_register_device (&pdev->dev, wdt_dev);if (ret) {dev_err (&pdev->dev,"error registering watchdog device\n" );return ret;@@ -162,16 +161,8 @@ static int mid_wdt_probe(struct platform_device *pdev)return 0 ; } -static int mid_wdt_remove (struct platform_device *pdev) -{ -struct watchdog_device *wd =platform_get_drvdata (pdev); -watchdog_unregister_device (wd); -return 0 ; -} -static struct platform_driver mid_wdt_driver = { .probe = mid_wdt_probe, - .remove = mid_wdt_remove, .driver = { .name ="intel_mid_wdt" , }, --2.7.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 20/62] watchdog: iTCO_wdt: Replace shutdown function with call to watchdog_stop_on_reboot
In reply to Guenter RoeckQuoted 10 lines · Guenter Roeck
The shutdown function calls the stop function. Call
watchdog_stop_on_reboot()from probe instead.The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Replace shutdown function with call to
watchdog_stop_on_reboot()
Quoted 42 lines
Signed-off-by Guenter Roeck <[email protected]>--- drivers/watchdog/iTCO_wdt.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/watchdog/iTCO_wdt.c +1
-9@@ -520,6 +520,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev) WATCHDOG_TIMEOUT); } +watchdog_stop_on_reboot (&p->wddev); ret =devm_watchdog_register_device (dev, &p->wddev);if (ret !=0 ) {pr_err ("cannot register watchdog device (err=%d)\n" , ret);@@ -543,13 +544,6 @@ static int iTCO_wdt_remove(struct platform_device *pdev)return 0 ; } -static void iTCO_wdt_shutdown (struct platform_device *pdev) -{ -struct iTCO_wdt_private *p =platform_get_drvdata (pdev); - -iTCO_wdt_stop (&p->wddev); -} -#ifdef CONFIG_PM_SLEEP /* * Suspend-to-idle requires this, because it stops the ticks and timekeeping, so @@ -603,7 +597,6 @@ static const struct dev_pm_ops iTCO_wdt_pm = {static struct platform_driver iTCO_wdt_driver = { .probe = iTCO_wdt_probe, .remove = iTCO_wdt_remove, - .shutdown = iTCO_wdt_shutdown, .driver = { .name =DRV_NAME , .pm =ITCO_WDT_PM_OPS , --2.7.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 4 lines · Guenter Roeck
On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
Not really. It would just make it more complicated to replace the call withdevm_clk_prepare_enable(), should it ever find its way into the light of day.
Actually what is the status to the patch series which brings devm_clk stuff like prepare_enable()? It was submitted 2(?) years ago.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 44/62] watchdog: pnx4008_wdt: Convert to use device managed functions
In reply to Guenter RoeckHi Guenter,
Quoted 8 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches
Quoted 6 lines
- Use
devm_add_action_or_reset()for calls toclk_disable_unprepare
- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop remove function
- Usedevm_watchdog_register_driver()to register watchdog deviceCc Vladimir Zapolskiy <[email protected]>
Thank you for the cleanup.
Quoted 2 lines
Cc Sylvain Lemieux <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
--
With best wishes,
Vladimir
Guenter Roeck
maintainerRe: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
Quoted 4 lines · Guenter Roeck
On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
Not really. It would just make it more complicated to replace the call withdevm_clk_prepare_enable(), should it ever find its way into the light of day.Actually what is the status to the patch series which brings
devm_clkstuff likeprepare_enable()? It was submitted 2(?) years ago.
It stalled.
Guenter
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 2 lines · Guenter Roeck
However, some other unrelated undefined behavior does not mean that this specific behavior is undefined.
True :-)
Let me just give two additional examples of UB that /have/ bitten Linux kernel devs.
int i;
for (i = 1; i > 0; ++i)
/* do_something(); */
=> optimized into an infinite loop
and
void func(struct foo *p) {
int n = p->field;
if (!p) return;=> null-pointer check optimized away
Quoted 11 lines
So far we have a claim that a cast to a void * may somehow be different to a cast to a different pointer, if used as function argument, and that the behavior with such a cast may be undefined. In other words, you claim that a function implemented as, say,
void func(int *var) {}might result in undefined behavior if some header file declares it as
void func(void *);
Quoted 7 lines
and it is called as
int var; func(&var);That seems really far fetched to me.
Thanks for giving me an opportunity to play the language lawyer :-)
C99 6.3.2.3 sub-clause 8 states:
"A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original pointer. If a converted pointer is used to call a function whose type is not compatible with the pointed-to type, the behavior is undefined."
So, the behavior is undefined, not when you cast clk_disable_unprepare, but when clk_disable_unprepare is later called through the devres->action function pointer.
However, I agree that it will work as expected on typical platforms (where all pointers are the same size, and the calling convention treats all pointers the same).
Quoted 2 lines
I do get the message that you do not like this kind of cast. But that doesn't mean it is not correct.
If it's already widely used in the kernel, it seems there is no point fighting it ;-)
Regards.
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
Quoted 60 lines · Marc Gonzalez
Quoted 2 lines · Guenter Roeck
However, some other unrelated undefined behavior does not mean that this specific behavior is undefined.
True :-)
Let me just give two additional examples of UB that /have/ bitten Linux kernel devs.
int i;
for (i = 1; i > 0; ++i)/* do_something(); */=> optimized into an infinite loop
and
void func(struct foo *p) { int n = p->field; if (!p) return;=> null-pointer check optimized away
Quoted 11 lines
So far we have a claim that a cast to a void * may somehow be different to a cast to a different pointer, if used as function argument, and that the behavior with such a cast may be undefined. In other words, you claim that a function implemented as, say,
void func(int *var) {}might result in undefined behavior if some header file declares it as
void func(void *);Quoted 7 lines
and it is called as
int var; func(&var);That seems really far fetched to me.
Thanks for giving me an opportunity to play the language lawyer :-)
C99 6.3.2.3 sub-clause 8 states:
"A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original pointer. If a converted pointer is used to call a function whose type is not compatible with the pointed-to type, the behavior is undefined."
So, the behavior is undefined, not when you cast
clk_disable_unprepare, but whenclk_disable_unprepareis later called through thedevres->actionfunction pointer.However, I agree that it will work as expected on typical platforms (where all pointers are the same size, and the calling convention treats all pointers the same).
Quoted 5 lines
Quoted 2 lines
I do get the message that you do not like this kind of cast. But that doesn't mean it is not correct.
If it's already widely used in the kernel, it seems there is no point fighting it ;-)
I'd say +.5 here (where +1 is an ack). My approach would be to push devm_clk_prepare_enable and use that. It cannot be that hard, can it?
It looks prettier, is well defined, easier to fit into 80 chars per line. I wonder why not everybody jubilates on this new function.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [PATCH 62/62] watchdog: wm831x_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 16 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Dropplatform_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog device
Quoted 2 lines
Signed-off-by Guenter Roeck <[email protected]>---
Looks good to me:
Thanks,
Charles
Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Marc GonzalezQuoted 29 lines · Marc Gonzalez
Quoted 11 lines
So far we have a claim that a cast to a void * may somehow be different to a cast to a different pointer, if used as function argument, and that the behavior with such a cast may be undefined. In other words, you claim that a function implemented as, say,
void func(int *var) {}might result in undefined behavior if some header file declares it as
void func(void *);Quoted 7 lines
and it is called as
int var; func(&var);That seems really far fetched to me.
Thanks for giving me an opportunity to play the language lawyer :-)
C99 6.3.2.3 sub-clause 8 states:
"A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original pointer. If a converted pointer is used to call a function whose type is not compatible with the pointed-to type, the behavior is undefined."
Quoted 3 lines
So, the behavior is undefined, not when you cast
clk_disable_unprepare, but whenclk_disable_unprepareis later called through thedevres->actionfunction pointer.
Only if the function types are incompatible. C99 6.7.5.3 subclause 15:
For two function types to be compatible, both shall specify compatible return types. Moreover, the parameter type lists, if both are present, shall agree in the number of parameters and in use of the ellipsis terminator; corresponding parameters shall have compatible types.
The question then is whether pointer to void and pointer to struct clk are compatible types. 6.7.5.1 subclause 2:
For two pointer types to be compatible, both shall be identically qualified and both shall be pointers to compatible types.
6.2.5 subclause 27:
A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. 39)
39) The same representation and alignment requirements are meant to imply interchangeability as arguments to functions, return values from functions, and members of unions.
6.3.2.3 subclause 1:
A pointer to void may be converted to or from a pointer to any incomplete or object type.
Quoted 1 line
From what I can tell, the standard stops just short of declaring pointer
to void compatible with other pointer types.
Quoted 3 lines
However, I agree that it will work as expected on typical platforms (where all pointers are the same size, and the calling convention treats all pointers the same).
Yes, I don't see how it could possibly go wrong.
Signature · 1 line
M?ns Rullg?rd
Re: [PATCH 16/62] watchdog: digicolor_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckHi Guenter,
Quoted 22 lines · 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 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Replaceof_iomap()withplatform_get_resource()followed bydevm_ioremap_resource()
- Dropplatform_set_drvdata()
- Replace&pdev->devwith dev if 'struct device *dev' is a declared variable
- Usedevm_watchdog_register_driver()to register watchdog device
- Replace shutdown function with call towatchdog_stop_on_reboot()
Quoted 2 lines
Cc Baruch Siach <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Thanks,
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Måns RullgårdQuoted 37 lines · M?ns Rullg?rd
Quoted 29 lines · Marc Gonzalez
Quoted 11 lines
So far we have a claim that a cast to a void * may somehow be different to a cast to a different pointer, if used as function argument, and that the behavior with such a cast may be undefined. In other words, you claim that a function implemented as, say,
void func(int *var) {}might result in undefined behavior if some header file declares it as
void func(void *);Quoted 7 lines
and it is called as
int var; func(&var);That seems really far fetched to me.
Thanks for giving me an opportunity to play the language lawyer :-)
C99 6.3.2.3 sub-clause 8 states:
"A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original pointer. If a converted pointer is used to call a function whose type is not compatible with the pointed-to type, the behavior is undefined."
Quoted 3 lines
So, the behavior is undefined, not when you cast
clk_disable_unprepare, but whenclk_disable_unprepareis later called through thedevres->actionfunction pointer.Only if the function types are incompatible. C99 6.7.5.3 subclause 15:
Quoted 8 lines
For two function types to be compatible, both shall specify compatible return types. Moreover, the parameter type lists, if both are present, shall agree in the number of parameters and in use of the ellipsis terminator; corresponding parameters shall have compatible types.
The question then is whether pointer to void and pointer to struct clk are compatible types.
6.2.7 Compatible type and composite type
sub-clause 1
"Two types have compatible type if their types are the same. Additional rules for determining whether two types are compatible are described in 6.7.2 for type specifiers, in 6.7.3 for type qualifiers, and in 6.7.5 for declarators."
6.7.5.1 Pointer declarators
sub-clause 2
"For two pointer types to be compatible, both shall be identically qualified and both shall be pointers to compatible types."
I don't think void and struct clk are compatible types. AFAIU, conversion and compatibility are two separate subjects.
Regards.
Guenter Roeck
maintainerRe: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions
In reply to Uwe Kleine-KönigQuoted 43 lines · Uwe Kleine-K?nig
Quoted 4 lines · Marc Gonzalez
Quoted 2 lines · Guenter Roeck
On 01/11/2017 01:07 AM, Marc Gonzalez wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/tangox_wdt.c static int tangox_wdt_probe(struct platform_device *pdev) · line 141
Quoted 9 lines
drivers/watchdog/tangox_wdt.c +5
-0@@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) err =clk_prepare_enable (dev->clk);if (err)return err; + err =devm_add_action_or_reset (&pdev->dev, + (void (*)(void *))clk_disable_unprepare, + dev->clk); +if (err) +return err;This looks wrong. There is no
clk_unprepare_disablewhendevm_add_action_or_resetfails.Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Hello Guenter,
I would rather avoid the function pointer cast.
How about defining an auxiliary function for the cleanup action?Quoted 6 lines
Quoted 2 lines
clk_disable_unprepare()is static inline, so gcc will have to define an auxiliary function either way. What do you think?Not really. It would just make it more complicated to replace the call with
devm_clk_prepare_enable(), should it ever find its way into the light of day.Quoted 6 lines
More complicated, because the cleanup function will have to be deleted later? The compiler will warn if someone forgets to do that.
In my opinion, it's not a good idea to rely on the fact that casting void(*)(struct clk *clk) to void(*)(void *) is likely to work as expected on most platforms. (It has undefined behavior, strictly speaking.)
I would expect it to work on all (Linux) platforms. Anyhow, I wonder if there couldn't be found a better solution.
If in the end it looks like the following that would be good I think:
Quoted 8 lines
clk = devm_clk_get(...); if (IS_ERR(clk)) ... ret = devm_clk_prepare_enable(clk) if (ret) return ret;
It turns out that at least one static analyzer complains about different parameter pointer types in situations like this, and at least one embedded compiler manages to create function names with embedded parameter type (eg it appends an 'i' to the function name for each integer parameter).
With that, I consider the typecast to be too risky after all. It may work for all of today's Linux architectures and compilers, but who knows if I get flooded with static analyzer warnings, and who knows if gcc version 18.0 or binutils 35.0 makes it truly incompatible (following the logic of "we can, therefore we do"). Since I also dislike the stub function solution, at least in this situation, I'll drop all patches touching clk_prepare_enable(), and wait for devm_clk_prepare_enable() to be available.
Guenter
Re: [PATCH 30/62] watchdog: mena21_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckQuoted 17 lines
Am 11.01.2017 12:38 vorm. schrieb "Guenter Roeck" <[email protected]>:
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Drop unnecessarymutex_destroy()on allocated data
- Usedevm_watchdog_register_driver()to register watchdog device
Quoted 3 lines
Cc Johannes Thumshirn <[email protected]>Signed-off-by Guenter Roeck <[email protected]>---
Looks good,
Re: [PATCH 05/62] watchdog: bcm2835_wdt: Convert to use device managed functions and other improvements
In reply to Guenter RoeckQuoted 4 lines · 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.
Quoted 8 lines
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
- Replaceof_iomap()withplatform_get_resource()followed bydevm_ioremap_resource()
Every time I see this pattern I wish we had adevm_ioremap_platform_resource().
Quoted 4 lines
- Replace
&pdev->devwith dev if 'struct device *dev' is a declared variable
- Usedevm_watchdog_register_driver()to register watchdog device
- Replace shutdown function with call towatchdog_stop_on_reboot()
I'm trusting you here that this last change is right. All the rest of it looks good:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170113/817a1030/attachment.sig>
RE: [PATCH 12/62] watchdog: da9055_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 14 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Replace 'goto l; ... l: return e;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Dropplatform_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog device
Quoted 3 lines
Cc Support Opensource <[email protected]>Signed-off-by Guenter Roeck <[email protected]>---
RE: [PATCH 11/62] watchdog: da9052_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 16 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Replace 'goto l; ... l: return e;' with 'return e;'
- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Replace 'if (e) { return expr; }' with 'if (e) return expr;'
- Drop remove function
- Dropplatform_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog device
Quoted 3 lines
Cc Support Opensource <[email protected]>Signed-off-by Guenter Roeck <[email protected]>---
RE: [PATCH 13/62] watchdog: da9062_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 14 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Replace 'val = e; return val;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop remove function
- Dropdev_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog device
Quoted 3 lines
Cc Support Opensource <[email protected]>Signed-off-by Guenter Roeck <[email protected]>---
RE: [PATCH 14/62] watchdog: da9063_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 16 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Replace 'val = e; return val;' with 'return e;'
- Replace 'if (e) return e; return 0;' with 'return e;'
- Drop assignments to otherwise unused variables
- Drop unused variables
- Drop remove function
- Dropdev_set_drvdata()
- Usedevm_watchdog_register_driver()to register watchdog device
Quoted 3 lines
Cc Support Opensource <[email protected]>Signed-off-by Guenter Roeck <[email protected]>---
Re: [PATCH 57/62] watchdog: tegra_wdt: Convert to use device managed functions
In reply to Guenter RoeckQuoted 10 lines · Guenter Roeck
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches- Use
devm_watchdog_register_driver()to register watchdog device
Quoted 7 lines
Cc Stephen Warren <[email protected]>Cc Thierry Reding <[email protected]>Cc Alexandre Courbot <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/watchdog/tegra_wdt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)