From patchwork Wed Jan 11 09:07:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Gonzalez X-Patchwork-Id: 9509585 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 76B5460231 for ; Wed, 11 Jan 2017 09:07:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FA6A2851D for ; Wed, 11 Jan 2017 09:07:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50B0F284A9; Wed, 11 Jan 2017 09:07:45 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable 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 D3A4F284A9 for ; Wed, 11 Jan 2017 09:07:44 +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 1cREsd-0006w0-UH; Wed, 11 Jan 2017 09:07:39 +0000 Received: from mail1.bemta8.messagelabs.com ([216.82.243.208]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cREsa-0006RI-H7 for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2017 09:07:38 +0000 Received: from [216.82.242.46] by server-16.bemta-8.messagelabs.com id E7/54-21963-0C5F5785; Wed, 11 Jan 2017 09:07:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNIsWRWlGSWpSXmKPExsVy+LrFKt39X0s jDM716VhsenyN1eLyrjlsFjfW7WO3eLLwDJPFj4fTmSxuzXjB6sDmcW2zmMfmJfUeb06fYvfY +b2B3ePzJrkA1ijWzLyk/IoE1oyJH56zF0wXqfi5q7yB8ZBAFyMXh5DAMkaJuf1LmLsYOTmEB SIlHiydww5iiwioSTSfamEDKWIWeMooMbv/EAtEx0ZGiY6Z78A62ARMJG7eP8cCYvMKOEvMX/ UayObgYBFQlZhyOBIkLCqQILHi3BwmiBJBiZMzn4CVcwKVt83fDzaGWUBPYsrVFkYIW1Biyes 1ULa8xPa3c8BqhAS0Jd5vXMwKYksIKEhMndzKPIFRYBaSsbOQjJqFZNQsJKMWMLKsYlQvTi0q Sy3SNdVLKspMzyjJTczM0TU0sNDLTS0uTkxPzUlMKtZLzs/dxAiMBAYg2ME4ucH5EKMkB5OSK O+Z16URQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4db8A5QSLUtNTK9Iyc4AxCZOW4OBREuF9+R kozVtckJhbnJkOkTrFqCglzhsF0icAksgozYNrg6WBS4yyUsK8jECHCPEUpBblZpagyr9iFOd gVBLm7QKZwpOZVwI3/RXQYiagxZF2xSCLSxIRUlINjAqvv62WrLLTuqtbuOXqkRXMdefm//d9 v+lM+mm5L8kJx87Fi3g870j/8klOfc9b065Xd4+6OCuuyr6Uu+XI1v620rKwx5WJlp2T3YskT EW0r4sJ6l/efFDihIF4QuKtCywuers3v8zWnHhl1sL1T16Z1m6ekXhL6e6SzkemU9a436r7Jj FnT6sSS3FGoqEWc1FxIgBervBi/gIAAA== X-Env-Sender: Marc_Gonzalez@sigmadesigns.com X-Msg-Ref: server-9.tower-96.messagelabs.com!1484125630!58265284!1 X-Originating-IP: [195.215.56.170] X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1838 invoked from network); 11 Jan 2017 09:07:11 -0000 Received: from 195-215-56-170-static.dk.customer.tdc.net (HELO CPH-EX1.SDESIGNS.COM) (195.215.56.170) by server-9.tower-96.messagelabs.com with AES128-SHA encrypted SMTP; 11 Jan 2017 09:07:11 -0000 Received: from [172.27.0.114] (172.27.0.114) by CPH-EX1.sdesigns.com (192.168.10.36) with Microsoft SMTP Server (TLS) id 14.3.294.0; Wed, 11 Jan 2017 10:07:10 +0100 Subject: Re: [PATCH 56/62] watchdog: tangox_wdt: Convert to use device managed functions To: Guenter Roeck References: <1484091325-9199-1-git-send-email-linux@roeck-us.net> <1484100561-17638-1-git-send-email-linux@roeck-us.net> <1484100561-17638-5-git-send-email-linux@roeck-us.net> From: Marc Gonzalez Message-ID: Date: Wed, 11 Jan 2017 10:07:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0 SeaMonkey/2.47 MIME-Version: 1.0 In-Reply-To: <1484100561-17638-5-git-send-email-linux@roeck-us.net> Content-Language: X-Originating-IP: [172.27.0.114] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170111_010736_668194_B246ECAC X-CRM114-Status: GOOD ( 18.62 ) 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: Mans Rullgard , linux-watchdog@vger.kernel.org, Thibaud Cornic , linux-kernel@vger.kernel.org, Wim Van Sebroeck , linux-arm-kernel@lists.infradead.org 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 On 11/01/2017 03:09, Guenter Roeck wrote: > 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 > - 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;' > - Use devm_watchdog_register_driver() to register watchdog device > > Cc: Marc Gonzalez > Signed-off-by: Guenter Roeck > --- > drivers/watchdog/tangox_wdt.c | 22 +++++++++------------- > 1 file changed, 9 insertions(+), 13 deletions(-) > > diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c > index d5fcce062920..7688e1b35867 100644 > --- a/drivers/watchdog/tangox_wdt.c > +++ b/drivers/watchdog/tangox_wdt.c > @@ -134,12 +134,15 @@ static int tangox_wdt_probe(struct platform_device *pdev) > err = clk_prepare_enable(dev->clk); > if (err) > return err; > + err = devm_add_action_or_reset(&pdev->dev, > + (void(*)(void *))clk_disable_unprepare, > + dev->clk); > + if (err) > + return err; Hello Guenter, I would rather avoid the function pointer cast. How about defining an auxiliary function for the cleanup action? clk_disable_unprepare() is static inline, so gcc will have to define an auxiliary function either way. What do you think? Regards. diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c index 202c4b9cc921..1a4f6d245a83 100644 --- a/drivers/watchdog/tangox_wdt.c +++ b/drivers/watchdog/tangox_wdt.c @@ -114,6 +114,11 @@ static int tangox_wdt_restart(struct notifier_block *nb, unsigned long action, return NOTIFY_DONE; } +static void cleanup(void *clk) +{ + clk_disable_unprepare(clk); +} + static int tangox_wdt_probe(struct platform_device *pdev) { struct tangox_wdt_device *dev; @@ -138,6 +143,10 @@ static int tangox_wdt_probe(struct platform_device *pdev) if (err) return err; + err = devm_add_action_or_reset(&pdev->dev, cleanup, dev->clk); + if (err) + return err; + dev->clk_rate = clk_get_rate(dev->clk); if (!dev->clk_rate) { err = -EINVAL;