Commit 801cdffe68f3f2479e11e6704e3ac25fcb4b5a98
Committed by
Wim Van Sebroeck
1 parent
7e6437e1b0
watchdog: of_xilinx_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 - Drop assignments to otherwise unused variables - Drop empty remove function - Use devm_add_action_or_reset() for calls to clk_disable_unprepare - Introduce local variable 'struct device *dev' and use it instead of dereferencing it repeatedly - Use devm_watchdog_register_driver() to register watchdog device Cc: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
Showing 1 changed file with 26 additions and 32 deletions Side-by-side Diff
drivers/watchdog/of_xilinx_wdt.c
... | ... | @@ -151,41 +151,46 @@ |
151 | 151 | return XWT_TIMER_FAILED; |
152 | 152 | } |
153 | 153 | |
154 | +static void xwdt_clk_disable_unprepare(void *data) | |
155 | +{ | |
156 | + clk_disable_unprepare(data); | |
157 | +} | |
158 | + | |
154 | 159 | static int xwdt_probe(struct platform_device *pdev) |
155 | 160 | { |
161 | + struct device *dev = &pdev->dev; | |
156 | 162 | int rc; |
157 | 163 | u32 pfreq = 0, enable_once = 0; |
158 | 164 | struct xwdt_device *xdev; |
159 | 165 | struct watchdog_device *xilinx_wdt_wdd; |
160 | 166 | |
161 | - xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL); | |
167 | + xdev = devm_kzalloc(dev, sizeof(*xdev), GFP_KERNEL); | |
162 | 168 | if (!xdev) |
163 | 169 | return -ENOMEM; |
164 | 170 | |
165 | 171 | xilinx_wdt_wdd = &xdev->xilinx_wdt_wdd; |
166 | 172 | xilinx_wdt_wdd->info = &xilinx_wdt_ident; |
167 | 173 | xilinx_wdt_wdd->ops = &xilinx_wdt_ops; |
168 | - xilinx_wdt_wdd->parent = &pdev->dev; | |
174 | + xilinx_wdt_wdd->parent = dev; | |
169 | 175 | |
170 | 176 | xdev->base = devm_platform_ioremap_resource(pdev, 0); |
171 | 177 | if (IS_ERR(xdev->base)) |
172 | 178 | return PTR_ERR(xdev->base); |
173 | 179 | |
174 | - rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-interval", | |
180 | + rc = of_property_read_u32(dev->of_node, "xlnx,wdt-interval", | |
175 | 181 | &xdev->wdt_interval); |
176 | 182 | if (rc) |
177 | - dev_warn(&pdev->dev, | |
178 | - "Parameter \"xlnx,wdt-interval\" not found\n"); | |
183 | + dev_warn(dev, "Parameter \"xlnx,wdt-interval\" not found\n"); | |
179 | 184 | |
180 | - rc = of_property_read_u32(pdev->dev.of_node, "xlnx,wdt-enable-once", | |
185 | + rc = of_property_read_u32(dev->of_node, "xlnx,wdt-enable-once", | |
181 | 186 | &enable_once); |
182 | 187 | if (rc) |
183 | - dev_warn(&pdev->dev, | |
188 | + dev_warn(dev, | |
184 | 189 | "Parameter \"xlnx,wdt-enable-once\" not found\n"); |
185 | 190 | |
186 | 191 | watchdog_set_nowayout(xilinx_wdt_wdd, enable_once); |
187 | 192 | |
188 | - xdev->clk = devm_clk_get(&pdev->dev, NULL); | |
193 | + xdev->clk = devm_clk_get(dev, NULL); | |
189 | 194 | if (IS_ERR(xdev->clk)) { |
190 | 195 | if (PTR_ERR(xdev->clk) != -ENOENT) |
191 | 196 | return PTR_ERR(xdev->clk); |
192 | 197 | |
... | ... | @@ -196,10 +201,10 @@ |
196 | 201 | */ |
197 | 202 | xdev->clk = NULL; |
198 | 203 | |
199 | - rc = of_property_read_u32(pdev->dev.of_node, "clock-frequency", | |
204 | + rc = of_property_read_u32(dev->of_node, "clock-frequency", | |
200 | 205 | &pfreq); |
201 | 206 | if (rc) |
202 | - dev_warn(&pdev->dev, | |
207 | + dev_warn(dev, | |
203 | 208 | "The watchdog clock freq cannot be obtained\n"); |
204 | 209 | } else { |
205 | 210 | pfreq = clk_get_rate(xdev->clk); |
206 | 211 | |
207 | 212 | |
208 | 213 | |
209 | 214 | |
210 | 215 | |
211 | 216 | |
212 | 217 | |
... | ... | @@ -218,46 +223,36 @@ |
218 | 223 | |
219 | 224 | rc = clk_prepare_enable(xdev->clk); |
220 | 225 | if (rc) { |
221 | - dev_err(&pdev->dev, "unable to enable clock\n"); | |
226 | + dev_err(dev, "unable to enable clock\n"); | |
222 | 227 | return rc; |
223 | 228 | } |
229 | + rc = devm_add_action_or_reset(dev, xwdt_clk_disable_unprepare, | |
230 | + xdev->clk); | |
231 | + if (rc) | |
232 | + return rc; | |
224 | 233 | |
225 | 234 | rc = xwdt_selftest(xdev); |
226 | 235 | if (rc == XWT_TIMER_FAILED) { |
227 | - dev_err(&pdev->dev, "SelfTest routine error\n"); | |
228 | - goto err_clk_disable; | |
236 | + dev_err(dev, "SelfTest routine error\n"); | |
237 | + return rc; | |
229 | 238 | } |
230 | 239 | |
231 | - rc = watchdog_register_device(xilinx_wdt_wdd); | |
240 | + rc = devm_watchdog_register_device(dev, xilinx_wdt_wdd); | |
232 | 241 | if (rc) { |
233 | - dev_err(&pdev->dev, "Cannot register watchdog (err=%d)\n", rc); | |
234 | - goto err_clk_disable; | |
242 | + dev_err(dev, "Cannot register watchdog (err=%d)\n", rc); | |
243 | + return rc; | |
235 | 244 | } |
236 | 245 | |
237 | 246 | clk_disable(xdev->clk); |
238 | 247 | |
239 | - dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n", | |
248 | + dev_info(dev, "Xilinx Watchdog Timer at %p with timeout %ds\n", | |
240 | 249 | xdev->base, xilinx_wdt_wdd->timeout); |
241 | 250 | |
242 | 251 | platform_set_drvdata(pdev, xdev); |
243 | 252 | |
244 | 253 | return 0; |
245 | -err_clk_disable: | |
246 | - clk_disable_unprepare(xdev->clk); | |
247 | - | |
248 | - return rc; | |
249 | 254 | } |
250 | 255 | |
251 | -static int xwdt_remove(struct platform_device *pdev) | |
252 | -{ | |
253 | - struct xwdt_device *xdev = platform_get_drvdata(pdev); | |
254 | - | |
255 | - watchdog_unregister_device(&xdev->xilinx_wdt_wdd); | |
256 | - clk_disable_unprepare(xdev->clk); | |
257 | - | |
258 | - return 0; | |
259 | -} | |
260 | - | |
261 | 256 | /** |
262 | 257 | * xwdt_suspend - Suspend the device. |
263 | 258 | * |
... | ... | @@ -303,7 +298,6 @@ |
303 | 298 | |
304 | 299 | static struct platform_driver xwdt_driver = { |
305 | 300 | .probe = xwdt_probe, |
306 | - .remove = xwdt_remove, | |
307 | 301 | .driver = { |
308 | 302 | .name = WATCHDOG_NAME, |
309 | 303 | .of_match_table = xwdt_of_match, |