From patchwork Fri Jan 19 21:53:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Khoroshilov X-Patchwork-Id: 10176019 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 B573E6055D for ; Fri, 19 Jan 2018 21:54:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A66B0287E6 for ; Fri, 19 Jan 2018 21:54:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A4E5287E9; Fri, 19 Jan 2018 21:54:06 +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=unavailable 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 25F7B287E6 for ; Fri, 19 Jan 2018 21:54:06 +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=pwK4YjbjZlqgXyjQXiotnlcGKORURWdKAN5Ga5whuVQ=; b=Mxh w/k1l8FqeWiPp3Wpp7O1Gp5hQdJsEpyRS9/ZWugm+wzR+owdQiblOKup6pClyhnN9nEqzuBo5wzm2 KB72u43L8a/0V0SLQMrMdtscXK+q8C1PZ0tlWI/zriTmSm83KNplLo/UHw7dDlxKVn9bxBYkC6SLg SKhv72nCahULNIgYD/BEZh3UTtiEsHqOEQQM/JfE+m3LNwOin6G1va7RmZ4PWd2l5fq1SIjIomdHR jEoa/9VfiLkEc7CgPv+6tNQ8JUdzy8IRarsbCvI9CEM3TOEW0k6E1kU5jDDICqRp949zU0R9wbDBk XEnMCGBHP6Lv2vcB8dJfshP0kRyzxjg==; 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 1ecebr-0006VL-7L; Fri, 19 Jan 2018 21:54:03 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ecebq-0006VF-8M for linux-arm-kernel@bombadil.infradead.org; Fri, 19 Jan 2018 21:54:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PZd620Wnwp++xCOdjGZt1IgZ7+U7YWgsq5H7nCaRsNg=; b=bBt2Go8NCsAYdB7iAzaH+Spj2 fG+Dq3PV5pRcJcD/wyzGDlKbViv8Vg7Fw3fDwY1B3wkZqs9OJIGTBE6PEsjfX0+bFluHesfy08jkv IjIbOr+LOXHnGMMpihreIOKtQQYTsOXOmbGZVq+fzmVRwzYix0pdny68DK1V4Ms2gkl9bh5rb/S4v pbUbrbkUs3/cG0duN9bg+8bi3739a5oBQOjRK0qEKcB68NuCqwpujDOqFiCDf0HS96NRKPlJhMpWs ErSF7VJYK9+XnqPbP/nBGPQyV2m9DZH+XfEnY3cKzQ5Wy/r0+aJRq9m+hIWJx+/YToEtX5yJQAcvH VvW3yCwVQ==; Received: from mail.ispras.ru ([83.149.199.45]) by casper.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ecebm-00049e-SX for linux-arm-kernel@lists.infradead.org; Fri, 19 Jan 2018 21:54:00 +0000 Received: from localhost.localdomain (ppp85-140-180-203.pppoe.mtu-net.ru [85.140.180.203]) by mail.ispras.ru (Postfix) with ESMTPSA id E181C54006A; Sat, 20 Jan 2018 00:53:26 +0300 (MSK) From: Alexey Khoroshilov To: Jamie Iles , Javier Martinez Canillas Subject: [PATCH] crypto: picoxcell - Fix error handling in spacc_probe() Date: Sat, 20 Jan 2018 00:53:15 +0300 Message-Id: <1516398795-9018-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180119_215358_981595_A2770101 X-CRM114-Status: GOOD ( 11.81 ) 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: ldv-project@linuxtesting.org, Herbert Xu , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Alexey Khoroshilov , "David S. Miller" , linux-arm-kernel@lists.infradead.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 If clk_get() fails, device_remove_file() looks inappropriate. The error path, where all crypto_register fail, misses resource deallocations. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov Reviewed-by: Jamie Iles --- drivers/crypto/picoxcell_crypto.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/picoxcell_crypto.c b/drivers/crypto/picoxcell_crypto.c index 5a6dc53b2b9d..4ef52c9d72fc 100644 --- a/drivers/crypto/picoxcell_crypto.c +++ b/drivers/crypto/picoxcell_crypto.c @@ -1618,7 +1618,7 @@ MODULE_DEVICE_TABLE(of, spacc_of_id_table); static int spacc_probe(struct platform_device *pdev) { - int i, err, ret = -EINVAL; + int i, err, ret; struct resource *mem, *irq; struct device_node *np = pdev->dev.of_node; struct spacc_engine *engine = devm_kzalloc(&pdev->dev, sizeof(*engine), @@ -1679,22 +1679,18 @@ static int spacc_probe(struct platform_device *pdev) engine->clk = clk_get(&pdev->dev, "ref"); if (IS_ERR(engine->clk)) { dev_info(&pdev->dev, "clk unavailable\n"); - device_remove_file(&pdev->dev, &dev_attr_stat_irq_thresh); return PTR_ERR(engine->clk); } if (clk_prepare_enable(engine->clk)) { dev_info(&pdev->dev, "unable to prepare/enable clk\n"); - clk_put(engine->clk); - return -EIO; + ret = -EIO; + goto err_clk_put; } - err = device_create_file(&pdev->dev, &dev_attr_stat_irq_thresh); - if (err) { - clk_disable_unprepare(engine->clk); - clk_put(engine->clk); - return err; - } + ret = device_create_file(&pdev->dev, &dev_attr_stat_irq_thresh); + if (ret) + goto err_clk_disable; /* @@ -1725,6 +1721,7 @@ static int spacc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, engine); + ret = -EINVAL; INIT_LIST_HEAD(&engine->registered_algs); for (i = 0; i < engine->num_algs; ++i) { engine->algs[i].engine = engine; @@ -1759,6 +1756,16 @@ static int spacc_probe(struct platform_device *pdev) engine->aeads[i].alg.base.cra_name); } + if (!ret) + return 0; + + del_timer_sync(&engine->packet_timeout); + device_remove_file(&pdev->dev, &dev_attr_stat_irq_thresh); +err_clk_disable: + clk_disable_unprepare(engine->clk); +err_clk_put: + clk_put(engine->clk); + return ret; }