From patchwork Fri Feb 2 21:45:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Khoroshilov X-Patchwork-Id: 10198153 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 6B4BF60362 for ; Fri, 2 Feb 2018 21:54:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5945E28C6A for ; Fri, 2 Feb 2018 21:54:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DC8E28F8E; Fri, 2 Feb 2018 21:54:10 +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,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D740628C6A for ; Fri, 2 Feb 2018 21:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=1rKn1odW022CFrDP2UdwDTA3nRdHb3QaJ3zeG5g3FBc=; b=rTg BWwxkOpBk0h4ZUya3nQw5b6QQoCxgfQlanK6TSKpKP5XVG45DQ8V4j+LRvWLOgsdHO98otNeTSvy8 9jP6IrZRECDM9pxObpkfrHt+o3LtNce9z5Fib07bWKqBoAdyrYgMP6bagfQlJyBNk2MrVDLgVLCnF dRTQWj30GGoU9SrPh7XOWHfEUbK6Z+0W9Rm12MKml4jctbvx41G2nvu9r7SPQ0NWfpUPzFRzcEqmy HMirPmCIsCwt5IKhkJUH/tv0e0A/3N1cAYFYNziUY3sMWCqUkfZZ/cWkOJvk7ztCUe3sc23zICsjq OPLny0tQahOh5yHEbAaN0oCT6Rkgb7Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ehjHc-00085p-3G; Fri, 02 Feb 2018 21:54:08 +0000 Received: from mail.ispras.ru ([83.149.199.45]) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ehjHY-00085I-Od for linux-arm-kernel@lists.infradead.org; Fri, 02 Feb 2018 21:54:06 +0000 Received: from localhost.localdomain (ppp85-140-181-201.pppoe.mtu-net.ru [85.140.181.201]) by mail.ispras.ru (Postfix) with ESMTPSA id 0029A540093; Sat, 3 Feb 2018 00:46:11 +0300 (MSK) From: Alexey Khoroshilov To: Hans Ulli Kroll , Linus Walleij , Alessandro Zummo , Alexandre Belloni Subject: [PATCH] rtc: gemini/ftrtc010: disable clk on error paths in ftrtc010_rtc_probe() Date: Sat, 3 Feb 2018 00:45:57 +0300 Message-Id: <1517607957-5664-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 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-rtc@vger.kernel.org, ldv-project@linuxtesting.org, linux-arm-kernel@lists.infradead.org, Alexey Khoroshilov , 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 ftrtc010_rtc_probe() leaves clks enabled in case of errors. The patch adds proper disabling code. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov --- drivers/rtc/rtc-ftrtc010.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/rtc/rtc-ftrtc010.c b/drivers/rtc/rtc-ftrtc010.c index af8d6beae20c..67a0aadf488c 100644 --- a/drivers/rtc/rtc-ftrtc010.c +++ b/drivers/rtc/rtc-ftrtc010.c @@ -147,33 +147,52 @@ static int ftrtc010_rtc_probe(struct platform_device *pdev) ret = clk_prepare_enable(rtc->extclk); if (ret) { dev_err(dev, "failed to enable EXTCLK\n"); - return ret; + goto err_pclk; } } res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!res) - return -ENODEV; + if (!res) { + ret = -ENODEV; + goto err_extclk; + } rtc->rtc_irq = res->start; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return -ENODEV; + if (!res) { + ret = -ENODEV; + goto err_extclk; + } rtc->rtc_base = devm_ioremap(dev, res->start, resource_size(res)); - if (!rtc->rtc_base) - return -ENOMEM; + if (!rtc->rtc_base) { + ret = -ENOMEM; + goto err_extclk; + } ret = devm_request_irq(dev, rtc->rtc_irq, ftrtc010_rtc_interrupt, IRQF_SHARED, pdev->name, dev); if (unlikely(ret)) - return ret; + goto err_extclk; rtc->rtc_dev = rtc_device_register(pdev->name, dev, &ftrtc010_rtc_ops, THIS_MODULE); - return PTR_ERR_OR_ZERO(rtc->rtc_dev); + if (IS_ERR(rtc->rtc_dev)) { + ret = PTR_ERR(rtc->rtc_dev); + goto err_extclk; + } + + return 0; + +err_extclk: + if (!IS_ERR(rtc->extclk)) + clk_disable_unprepare(rtc->extclk); +err_pclk: + if (!IS_ERR(rtc->pclk)) + clk_disable_unprepare(rtc->pclk); + return ret; } static int ftrtc010_rtc_remove(struct platform_device *pdev)