* [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements [not found] ` <1484095516-12720-1-git-send-email-linux@roeck-us.net> @ 2017-01-11 0:44 ` Guenter Roeck 2017-01-11 8:42 ` Neil Armstrong 2017-01-11 18:44 ` Kevin Hilman 2017-01-11 0:44 ` [PATCH 33/62] watchdog: meson_wdt: " Guenter Roeck 1 sibling, 2 replies; 5+ messages in thread From: Guenter Roeck @ 2017-01-11 0:44 UTC (permalink / raw) To: linus-amlogic 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() Cc: Carlo Caione <carlo@caione.org> Cc: Kevin Hilman <khilman@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> --- drivers/watchdog/meson_gxbb_wdt.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c index 45d47664a00a..913d8a644460 100644 --- a/drivers/watchdog/meson_gxbb_wdt.c +++ b/drivers/watchdog/meson_gxbb_wdt.c @@ -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, -- 2.7.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements 2017-01-11 0:44 ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck @ 2017-01-11 8:42 ` Neil Armstrong 2017-01-11 18:44 ` Kevin Hilman 1 sibling, 0 replies; 5+ messages in thread From: Neil Armstrong @ 2017-01-11 8:42 UTC (permalink / raw) To: linus-amlogic On 01/11/2017 01:44 AM, Guenter Roeck wrote: > Use device managed functions to simplify error handling, reduce > source code size, improve readability, and reduce the likelyhood of bugs. > Other improvements as listed below. > > The conversion was done automatically with coccinelle using the > following semantic patches. The semantic patches and the scripts used > to generate this commit log are available at > https://github.com/groeck/coccinelle-patches > > - 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() > > Cc: Carlo Caione <carlo@caione.org> > Cc: Kevin Hilman <khilman@baylibre.com> > Signed-off-by: Guenter Roeck <linux@roeck-us.net> > --- > drivers/watchdog/meson_gxbb_wdt.c | 38 ++++++++++---------------------------- > 1 file changed, 10 insertions(+), 28 deletions(-) > > diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c > index 45d47664a00a..913d8a644460 100644 > --- a/drivers/watchdog/meson_gxbb_wdt.c > +++ b/drivers/watchdog/meson_gxbb_wdt.c > @@ -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, > Was on my todo list, glad you did this ! Acked-by: Neil Armstrong <narmstrong@baylibre.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements 2017-01-11 0:44 ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck 2017-01-11 8:42 ` Neil Armstrong @ 2017-01-11 18:44 ` Kevin Hilman 1 sibling, 0 replies; 5+ messages in thread From: Kevin Hilman @ 2017-01-11 18:44 UTC (permalink / raw) To: linus-amlogic Guenter Roeck <linux@roeck-us.net> writes: > Use device managed functions to simplify error handling, reduce > source code size, improve readability, and reduce the likelyhood of bugs. > Other improvements as listed below. > > The conversion was done automatically with coccinelle using the > following semantic patches. The semantic patches and the scripts used > to generate this commit log are available at > https://github.com/groeck/coccinelle-patches > > - 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() > > Cc: Carlo Caione <carlo@caione.org> > Cc: Kevin Hilman <khilman@baylibre.com> > Signed-off-by: Guenter Roeck <linux@roeck-us.net> Nice, thanks for the cleanup! Acked-by: Kevin Hilman <khilman@baylibre.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 33/62] watchdog: meson_wdt: Convert to use device managed functions and other improvements [not found] ` <1484095516-12720-1-git-send-email-linux@roeck-us.net> 2017-01-11 0:44 ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck @ 2017-01-11 0:44 ` Guenter Roeck 2017-01-11 18:45 ` Kevin Hilman 1 sibling, 1 reply; 5+ messages in thread From: Guenter Roeck @ 2017-01-11 0:44 UTC (permalink / raw) To: linus-amlogic 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 - Drop platform_set_drvdata() - Use devm_watchdog_register_driver() to register watchdog device - Replace shutdown function with call to watchdog_stop_on_reboot() Cc: Carlo Caione <carlo@caione.org> Cc: Kevin Hilman <khilman@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> --- drivers/watchdog/meson_wdt.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/drivers/watchdog/meson_wdt.c b/drivers/watchdog/meson_wdt.c index 56ea1caf71c3..491b9bf13d84 100644 --- a/drivers/watchdog/meson_wdt.c +++ b/drivers/watchdog/meson_wdt.c @@ -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, -- 2.7.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 33/62] watchdog: meson_wdt: Convert to use device managed functions and other improvements 2017-01-11 0:44 ` [PATCH 33/62] watchdog: meson_wdt: " Guenter Roeck @ 2017-01-11 18:45 ` Kevin Hilman 0 siblings, 0 replies; 5+ messages in thread From: Kevin Hilman @ 2017-01-11 18:45 UTC (permalink / raw) To: linus-amlogic Guenter Roeck <linux@roeck-us.net> writes: > Use device managed functions to simplify error handling, reduce > source code size, improve readability, and reduce the likelyhood of bugs. > Other improvements as listed below. > > The conversion was done automatically with coccinelle using the > following semantic patches. The semantic patches and the scripts used > to generate this commit log are available at > https://github.com/groeck/coccinelle-patches > > - Drop assignments to otherwise unused variables > - Drop 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() > > Cc: Carlo Caione <carlo@caione.org> > Cc: Kevin Hilman <khilman@baylibre.com> > Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Kevin Hilman <khilman@baylibre.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-01-11 18:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1484091325-9199-1-git-send-email-linux@roeck-us.net>
[not found] ` <1484095516-12720-1-git-send-email-linux@roeck-us.net>
2017-01-11 0:44 ` [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Guenter Roeck
2017-01-11 8:42 ` Neil Armstrong
2017-01-11 18:44 ` Kevin Hilman
2017-01-11 0:44 ` [PATCH 33/62] watchdog: meson_wdt: " Guenter Roeck
2017-01-11 18:45 ` Kevin Hilman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).