From patchwork Tue Apr 11 09:22:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Klauser X-Patchwork-Id: 9674795 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 0032E60383 for ; Tue, 11 Apr 2017 09:23:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0122C28517 for ; Tue, 11 Apr 2017 09:23:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA42F28521; Tue, 11 Apr 2017 09:23:49 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C70728520 for ; Tue, 11 Apr 2017 09:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754636AbdDKJXF (ORCPT ); Tue, 11 Apr 2017 05:23:05 -0400 Received: from mail.zhinst.com ([212.126.164.98]:41618 "EHLO mail.zhinst.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754349AbdDKJXB (ORCPT ); Tue, 11 Apr 2017 05:23:01 -0400 Received: from ziws08.zhinst.com ([10.42.0.7]) by mail.zhinst.com (Kerio Connect 9.2.2 patch 1) with ESMTP; Tue, 11 Apr 2017 11:22:54 +0200 From: Tobias Klauser To: Alan Tull , Moritz Fischer Cc: linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe() Date: Tue, 11 Apr 2017 11:22:54 +0200 Message-Id: <20170411092254.19712-1-tklauser@distanz.ch> X-Mailer: git-send-email 2.12.2 Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If either _alt_hps2fpga_enable_set() or fpga_bridge_register() fail in alt_fpga_bridge_probe(), the clock remains enabled and prepared. Also, in the error path for _alt_hps2fpga_enable_set() a call to fpga_bridge_unregister() is made even though the bridge was not registered yet. Remove the unnecessary call to fpga_bridge_unregister() and call clk_disable_unprepare() in both error paths in order to make sure the clock gets properly disabled and unprepared. Signed-off-by: Tobias Klauser Signed-off-by: Alan Tull Acked-by: Moritz Fischer --- drivers/fpga/altera-hps2fpga.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/fpga/altera-hps2fpga.c b/drivers/fpga/altera-hps2fpga.c index 4b354c79be31..3066b805f2d0 100644 --- a/drivers/fpga/altera-hps2fpga.c +++ b/drivers/fpga/altera-hps2fpga.c @@ -181,15 +181,18 @@ static int alt_fpga_bridge_probe(struct platform_device *pdev) (enable ? "enabling" : "disabling")); ret = _alt_hps2fpga_enable_set(priv, enable); - if (ret) { - fpga_bridge_unregister(&pdev->dev); - return ret; - } + if (ret) + goto err; } } - return fpga_bridge_register(dev, priv->name, &altera_hps2fpga_br_ops, - priv); + ret = fpga_bridge_register(dev, priv->name, &altera_hps2fpga_br_ops, + priv); +err: + if (ret) + clk_disable_unprepare(priv->clk); + + return ret; } static int alt_fpga_bridge_remove(struct platform_device *pdev)