summaryrefslogtreecommitdiffstats
path: root/drivers/watchdog
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2017-01-10 18:21:48 -0500
committerGuenter Roeck <linux@roeck-us.net>2017-02-24 17:00:23 -0500
commitdd36f6ce680d55fcafa62b35e589549cd53199b1 (patch)
treec4354aa1edada3789ef6cab207982b496d027506 /drivers/watchdog
parentd3d77b5abc175684a3c42a240ee49931ca51d10d (diff)
watchdog: digicolor_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 - 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() Acked-by: Baruch Siach <baruch@tkos.co.il> Tested-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r--drivers/watchdog/digicolor_wdt.c48
1 files changed, 12 insertions, 36 deletions
diff --git a/drivers/watchdog/digicolor_wdt.c b/drivers/watchdog/digicolor_wdt.c
index dfe72944822d..870694d9ebc7 100644
--- a/drivers/watchdog/digicolor_wdt.c
+++ b/drivers/watchdog/digicolor_wdt.c
@@ -119,62 +119,40 @@ static struct watchdog_device dc_wdt_wdd = {
119 119
120static int dc_wdt_probe(struct platform_device *pdev) 120static int dc_wdt_probe(struct platform_device *pdev)
121{ 121{
122 struct resource *res;
122 struct device *dev = &pdev->dev; 123 struct device *dev = &pdev->dev;
123 struct device_node *np = dev->of_node;
124 struct dc_wdt *wdt; 124 struct dc_wdt *wdt;
125 int ret; 125 int ret;
126 126
127 wdt = devm_kzalloc(dev, sizeof(struct dc_wdt), GFP_KERNEL); 127 wdt = devm_kzalloc(dev, sizeof(struct dc_wdt), GFP_KERNEL);
128 if (!wdt) 128 if (!wdt)
129 return -ENOMEM; 129 return -ENOMEM;
130 platform_set_drvdata(pdev, wdt);
131 130
132 wdt->base = of_iomap(np, 0); 131 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
133 if (!wdt->base) { 132 wdt->base = devm_ioremap_resource(dev, res);
134 dev_err(dev, "Failed to remap watchdog regs"); 133 if (IS_ERR(wdt->base))
135 return -ENODEV; 134 return PTR_ERR(wdt->base);
136 }
137 135
138 wdt->clk = devm_clk_get(&pdev->dev, NULL); 136 wdt->clk = devm_clk_get(dev, NULL);
139 if (IS_ERR(wdt->clk)) { 137 if (IS_ERR(wdt->clk))
140 ret = PTR_ERR(wdt->clk); 138 return PTR_ERR(wdt->clk);
141 goto err_iounmap;
142 }
143 dc_wdt_wdd.max_timeout = U32_MAX / clk_get_rate(wdt->clk); 139 dc_wdt_wdd.max_timeout = U32_MAX / clk_get_rate(wdt->clk);
144 dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout; 140 dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout;
145 dc_wdt_wdd.parent = &pdev->dev; 141 dc_wdt_wdd.parent = dev;
146 142
147 spin_lock_init(&wdt->lock); 143 spin_lock_init(&wdt->lock);
148 144
149 watchdog_set_drvdata(&dc_wdt_wdd, wdt); 145 watchdog_set_drvdata(&dc_wdt_wdd, wdt);
150 watchdog_set_restart_priority(&dc_wdt_wdd, 128); 146 watchdog_set_restart_priority(&dc_wdt_wdd, 128);
151 watchdog_init_timeout(&dc_wdt_wdd, timeout, dev); 147 watchdog_init_timeout(&dc_wdt_wdd, timeout, dev);
152 ret = watchdog_register_device(&dc_wdt_wdd); 148 watchdog_stop_on_reboot(&dc_wdt_wdd);
149 ret = devm_watchdog_register_device(dev, &dc_wdt_wdd);
153 if (ret) { 150 if (ret) {
154 dev_err(dev, "Failed to register watchdog device"); 151 dev_err(dev, "Failed to register watchdog device");
155 goto err_iounmap; 152 return ret;
156 } 153 }
157 154
158 return 0; 155 return 0;
159
160err_iounmap:
161 iounmap(wdt->base);
162 return ret;
163}
164
165static int dc_wdt_remove(struct platform_device *pdev)
166{
167 struct dc_wdt *wdt = platform_get_drvdata(pdev);
168
169 watchdog_unregister_device(&dc_wdt_wdd);
170 iounmap(wdt->base);
171
172 return 0;
173}
174
175static void dc_wdt_shutdown(struct platform_device *pdev)
176{
177 dc_wdt_stop(&dc_wdt_wdd);
178} 156}
179 157
180static const struct of_device_id dc_wdt_of_match[] = { 158static const struct of_device_id dc_wdt_of_match[] = {
@@ -185,8 +163,6 @@ MODULE_DEVICE_TABLE(of, dc_wdt_of_match);
185 163
186static struct platform_driver dc_wdt_driver = { 164static struct platform_driver dc_wdt_driver = {
187 .probe = dc_wdt_probe, 165 .probe = dc_wdt_probe,
188 .remove = dc_wdt_remove,
189 .shutdown = dc_wdt_shutdown,
190 .driver = { 166 .driver = {
191 .name = "digicolor-wdt", 167 .name = "digicolor-wdt",
192 .of_match_table = dc_wdt_of_match, 168 .of_match_table = dc_wdt_of_match,