Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: stmp3xxx_rtc_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

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

Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>

authored by

Guenter Roeck and committed by
Wim Van Sebroeck
55082c03 cfe9ee3a

+8 -8
+8 -8
drivers/watchdog/stmp3xxx_rtc_wdt.c
··· 89 89 90 90 static int stmp3xxx_wdt_probe(struct platform_device *pdev) 91 91 { 92 + struct device *dev = &pdev->dev; 92 93 int ret; 93 94 94 - watchdog_set_drvdata(&stmp3xxx_wdd, &pdev->dev); 95 + watchdog_set_drvdata(&stmp3xxx_wdd, dev); 95 96 96 97 stmp3xxx_wdd.timeout = clamp_t(unsigned, heartbeat, 1, STMP3XXX_MAX_TIMEOUT); 97 - stmp3xxx_wdd.parent = &pdev->dev; 98 + stmp3xxx_wdd.parent = dev; 98 99 99 - ret = watchdog_register_device(&stmp3xxx_wdd); 100 + ret = devm_watchdog_register_device(dev, &stmp3xxx_wdd); 100 101 if (ret < 0) { 101 - dev_err(&pdev->dev, "cannot register watchdog device\n"); 102 + dev_err(dev, "cannot register watchdog device\n"); 102 103 return ret; 103 104 } 104 105 105 106 if (register_reboot_notifier(&wdt_notifier)) 106 - dev_warn(&pdev->dev, "cannot register reboot notifier\n"); 107 + dev_warn(dev, "cannot register reboot notifier\n"); 107 108 108 - dev_info(&pdev->dev, "initialized watchdog with heartbeat %ds\n", 109 - stmp3xxx_wdd.timeout); 109 + dev_info(dev, "initialized watchdog with heartbeat %ds\n", 110 + stmp3xxx_wdd.timeout); 110 111 return 0; 111 112 } 112 113 113 114 static int stmp3xxx_wdt_remove(struct platform_device *pdev) 114 115 { 115 116 unregister_reboot_notifier(&wdt_notifier); 116 - watchdog_unregister_device(&stmp3xxx_wdd); 117 117 return 0; 118 118 } 119 119