In case of an error (e.g. dev_add_param_tristate_ro() returns -ENOSYS), device registration must be reverted. Signed-off-by: Christian Eggers <ceggers@xxxxxxx> --- drivers/watchdog/wd_core.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c index b6e2a37b1..34040408f 100644 --- a/drivers/watchdog/wd_core.c +++ b/drivers/watchdog/wd_core.c @@ -171,8 +171,10 @@ int watchdog_register(struct watchdog *wd) return ret; p = dev_add_param_tristate_ro(&wd->dev, "running", &wd->running); - if (IS_ERR(p)) - return PTR_ERR(p); + if (IS_ERR(p)) { + ret = PTR_ERR(p); + goto error_unregister; + } if (!wd->priority) wd->priority = dev_get_watchdog_priority(wd->hwdev); @@ -180,8 +182,10 @@ int watchdog_register(struct watchdog *wd) p = dev_add_param_uint32(&wd->dev, "priority", watchdog_set_priority, NULL, &wd->priority, "%u", wd); - if (IS_ERR(p)) - return PTR_ERR(p); + if (IS_ERR(p)) { + ret = PTR_ERR(p); + goto error_unregister; + } /* set some default sane value */ if (!wd->timeout_max) @@ -189,8 +193,10 @@ int watchdog_register(struct watchdog *wd) p = dev_add_param_uint32_ro(&wd->dev, "timeout_max", &wd->timeout_max, "%u"); - if (IS_ERR(p)) - return PTR_ERR(p); + if (IS_ERR(p)) { + ret = PTR_ERR(p); + goto error_unregister; + } if (IS_ENABLED(CONFIG_WATCHDOG_POLLER)) { if (!wd->poller_timeout_cur || @@ -199,12 +205,14 @@ int watchdog_register(struct watchdog *wd) p = dev_add_param_uint32(&wd->dev, "timeout_cur", watchdog_set_cur, NULL, &wd->poller_timeout_cur, "%u", wd); - if (IS_ERR(p)) - return PTR_ERR(p); + if (IS_ERR(p)) { + ret = PTR_ERR(p); + goto error_unregister; + } ret = watchdog_register_poller(wd); if (ret) - return ret; + goto error_unregister; } list_add_tail(&wd->list, &watchdog_list); @@ -213,6 +221,10 @@ int watchdog_register(struct watchdog *wd) wd->priority); return 0; + +error_unregister: + unregister_device(&wd->dev); + return ret; } EXPORT_SYMBOL(watchdog_register); -- Christian Eggers Embedded software developer Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918 Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477 Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox