From patchwork Tue Jan 10 23:34:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9508813 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 08BF360710 for ; Tue, 10 Jan 2017 23:37:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE8D3283F1 for ; Tue, 10 Jan 2017 23:37:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E342A28488; Tue, 10 Jan 2017 23:37:51 +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=-1.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, SUSPICIOUS_RECIPS, T_DKIM_INVALID autolearn=no 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 6CD08283F1 for ; Tue, 10 Jan 2017 23:37:51 +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 1cR5zB-0002Fn-Jl; Tue, 10 Jan 2017 23:37:49 +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 1cR5z4-0001NC-PO for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2017 23:37:45 +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=LOlsiMAvfzhJuua4xiERLUibD8+/PfIisCwT/Qi4TRo=; b=z07bNJazKNGV4S BjsIJv7HDwll91N1bMQoDgGMJ3BpOYrIWUYFv/IBX295nakMFZSFtOv1c8TlrfAQZxN9Wby3BeXeo Y6ykW/+rpAesEYWnCqUfdBolR+iyeHKsTUhpfzC4CeT1EptGfVIb0s/8ux+sJHnPnVy1lmk9o7s3J eag76BliVrBwru4YM5GNoaJv/jeiNHuxK2WJ4GQwmVmgSUUdrSfiDZjjwfjwhWsXXDY9/lUt5R7T3 4DPztOqSOcFah56RKJyj2yFVfYQMGYEvExgIO3wRR2ZvR9xTu9lvSTUTtUC3aD0+zm7jgDZ3L7CoO j8bB78FjeP0TIs+AHR3g==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:41092 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1cR5y2-0032uC-Re; Tue, 10 Jan 2017 23:36:39 +0000 From: Guenter Roeck To: Wim Van Sebroeck Subject: [PATCH 10/62] watchdog: coh901327_wdt: Convert to use device managed functions Date: Tue, 10 Jan 2017 15:34:27 -0800 Message-Id: <1484091325-9199-11-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484091325-9199-1-git-send-email-linux@roeck-us.net> References: <1484091325-9199-1-git-send-email-linux@roeck-us.net> X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=1.5 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_153742_908105_8863CF4F X-CRM114-Status: GOOD ( 11.41 ) 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-arm-kernel@lists.infradead.org, Linus Walleij , linux-watchdog@vger.kernel.org, Guenter Roeck , linux-kernel@vger.kernel.org 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. 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 - Use devm_clk_get() if the device parameter is not NULL - Replace 'goto l; ... l: return e;' with 'return e;' - Replace 'val = e; return val;' with 'return e;' - Replace 'if (e) { return expr; }' with 'if (e) return expr;' - Replace request_irq, request_threaded_irq, and request_any_context_irq with their device managed equivalent - Replace &pdev->dev with dev if 'struct device *dev' is a declared variable - Use devm_watchdog_register_driver() to register watchdog device Cc: Linus Walleij Signed-off-by: Guenter Roeck Reviewed-by: Linus Walleij --- drivers/watchdog/coh901327_wdt.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/drivers/watchdog/coh901327_wdt.c b/drivers/watchdog/coh901327_wdt.c index 38dd60f0cfcc..8b6f7f35c479 100644 --- a/drivers/watchdog/coh901327_wdt.c +++ b/drivers/watchdog/coh901327_wdt.c @@ -241,11 +241,7 @@ static struct watchdog_device coh901327_wdt = { static int __exit coh901327_remove(struct platform_device *pdev) { - watchdog_unregister_device(&coh901327_wdt); coh901327_disable(); - free_irq(irq, pdev); - clk_disable_unprepare(clk); - clk_put(clk); return 0; } @@ -263,7 +259,7 @@ static int __init coh901327_probe(struct platform_device *pdev) if (IS_ERR(virtbase)) return PTR_ERR(virtbase); - clk = clk_get(dev, NULL); + clk = devm_clk_get(dev, NULL); if (IS_ERR(clk)) { ret = PTR_ERR(clk); dev_err(dev, "could not get clock\n"); @@ -272,8 +268,13 @@ static int __init coh901327_probe(struct platform_device *pdev) ret = clk_prepare_enable(clk); if (ret) { dev_err(dev, "could not prepare and enable clock\n"); - goto out_no_clk_enable; + return ret; } + ret = devm_add_action_or_reset(dev, + (void(*)(void *))clk_disable_unprepare, + clk); + if (ret) + return ret; val = readw(virtbase + U300_WDOG_SR); switch (val) { @@ -309,31 +310,21 @@ static int __init coh901327_probe(struct platform_device *pdev) writew(U300_WDOG_SR_RESET_STATUS_RESET, virtbase + U300_WDOG_SR); irq = platform_get_irq(pdev, 0); - if (request_irq(irq, coh901327_interrupt, 0, - DRV_NAME " Bark", pdev)) { - ret = -EIO; - goto out_no_irq; - } + if (devm_request_irq(dev, irq, coh901327_interrupt, 0, + DRV_NAME " Bark", pdev)) + return -EIO; ret = watchdog_init_timeout(&coh901327_wdt, margin, dev); if (ret < 0) coh901327_wdt.timeout = 60; coh901327_wdt.parent = dev; - ret = watchdog_register_device(&coh901327_wdt); + ret = devm_watchdog_register_device(dev, &coh901327_wdt); if (ret) - goto out_no_wdog; + return ret; dev_info(dev, "initialized. timer margin=%d sec\n", margin); return 0; - -out_no_wdog: - free_irq(irq, pdev); -out_no_irq: - clk_disable_unprepare(clk); -out_no_clk_enable: - clk_put(clk); - return ret; } #ifdef CONFIG_PM