From patchwork Wed Jan 11 00:44:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9508917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A7C16075F for ; Wed, 11 Jan 2017 00:45:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B88428406 for ; Wed, 11 Jan 2017 00:45:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E01D28577; Wed, 11 Jan 2017 00:45:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B9AC528406 for ; Wed, 11 Jan 2017 00:45:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cR734-0001jb-1w; Wed, 11 Jan 2017 00:45:54 +0000 Received: from bh-25.webhostbox.net ([208.91.199.152]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cR72z-0001cM-7m; Wed, 11 Jan 2017 00:45:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=References:In-Reply-To:Message-Id:Date:Subject: Cc:To:From; bh=IvPu6eS/RgDxsz88m5XakzarfChdVZBIsSV0tb7nL2w=; b=DftS2v6HITAlOF Efc1bxktOcL0jTFwcQYSftPuRl2aATnUlye0mEdRKSxR36x/Ahba6ow/4pIrNevc5kebTM0oH3kTM vOJp+qs68dovKQzlA/VvNH+OFE31kbdT7mrwDqTKn3z2j5UXA2Wy6QPV1ImVW9wtwK7gGmjjBpYcP 8LIiAe+JPMDfyzwGeu692NhD/sqNM3CC56bI1JkI1DdCQXVs1Ri8rW81w+Zwyw/4+oXvwpqhGdQhW N1ck4raiXu/fK0lvDIfsxxfpfTlFQL4lChJRWO32y8Aqo+bJ+rvw6IUy9WnFRmB4ouIKcRhj7avuL XHln+xjX+deaYvVWecAg==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:41650 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1cR72c-001xZo-1D; Wed, 11 Jan 2017 00:45:27 +0000 From: Guenter Roeck To: Wim Van Sebroeck Subject: [PATCH 32/62] watchdog: meson_gxbb_wdt: Convert to use device managed functions and other improvements Date: Tue, 10 Jan 2017 16:44:41 -0800 Message-Id: <1484095516-12720-2-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484095516-12720-1-git-send-email-linux@roeck-us.net> References: <1484091325-9199-1-git-send-email-linux@roeck-us.net> <1484095516-12720-1-git-send-email-linux@roeck-us.net> X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170110_164549_359074_A36B7489 X-CRM114-Status: GOOD ( 10.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-watchdog@vger.kernel.org, Kevin Hilman , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Carlo Caione , linux-amlogic@lists.infradead.org, Guenter Roeck MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Kevin Hilman Signed-off-by: Guenter Roeck Acked-by: Neil Armstrong Acked-by: Kevin Hilman --- 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,