From patchwork Mon Jan 20 13:50:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitalii Mordan X-Patchwork-Id: 13945135 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B1EB1E22FC; Mon, 20 Jan 2025 13:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737381095; cv=none; b=JnCm0k1bW9CxezFfRegAVZLswGMBj2syMuHp8/RJuFYUFPiXAae2nJgXYm4F4GY3tL0DBK7bPU6iRM+qgLvesEOPsP40PeOQpBkt3wjPRurIbGl+fSPjd5ht6+pvhOsiteCzEf59JGW9unDwVMQuZ88fD3Qz71bJQ5gE7hljhiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737381095; c=relaxed/simple; bh=7YGT9tUI3LWn0O0I8oAOKgITzrbbgZqghLIdS12F2hU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Z73FoB/b6VLk5p7D2yKZnUVK6R3IewJclovl/8N+9HxvTwKVY6iIrBz2ouv6N80aBwOkn4W4K6rCiIaaDwbXPNzfGo+muTze90vvH8sKWA18SKvYnAb/ZLvSPXSBq1enYvxXEGWtsvjIN//rFUe8Ki9cdq3je4g+2ui9kWZbMB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=E1IJHDTv; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="E1IJHDTv" Received: from ldvnode.intra.ispras.ru (unknown [10.10.2.153]) by mail.ispras.ru (Postfix) with ESMTPSA id 3AD74518E774; Mon, 20 Jan 2025 13:51:23 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 3AD74518E774 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1737381083; bh=4fySs5N2hrgu1v7dESWSAZhLMeG95wbe2hEzl7vKhpQ=; h=From:To:Cc:Subject:Date:From; b=E1IJHDTvqBHJm7dbbahgUlwSa4+5XcwV8y+7MbJUK7H9FBUNAAzSih34ogh7V84te 4/uFef46+gGG0HcU4JUlO9VNs1XkhrAjRoQ5MRTpHji2nXAbILIFVRbNC10tvF46Mo 9epbmpVXtnmVLWrsAHvHeqxWFmYNvbluk5Utp8a0= From: Vitalii Mordan To: Paul Cercueil Cc: Vitalii Mordan , Vinod Koul , Alex Smith , Zubair Lutfullah Kakakhel , linux-mips@vger.kernel.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, Fedor Pchelkin , Alexey Khoroshilov , Vadim Mutilin , lvc-project@linuxtesting.org Subject: [PATCH] dma: jz4780: fix call balance of jzdma->clk handling routines Date: Mon, 20 Jan 2025 16:50:59 +0300 Message-Id: <20250120135059.302273-1-mordan@ispras.ru> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If the clock jzdma->clk was not enabled in jz4780_dma_probe(), it should not be disabled in any path. Conversely, if it was enabled in jz4780_dma_probe(), it must be disabled in all error paths to ensure proper cleanup. Use the devm_clk_get_enabled() helper function to ensure proper call balance for jzdma->clk. Found by Linux Verification Center (linuxtesting.org) with Klever. Fixes: d894fc6046fe ("dmaengine: jz4780: add driver for the Ingenic JZ4780 DMA controller") Signed-off-by: Vitalii Mordan Acked-by: Paul Cercueil --- drivers/dma/dma-jz4780.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c index 100057603fd4..ff9c387fd8c1 100644 --- a/drivers/dma/dma-jz4780.c +++ b/drivers/dma/dma-jz4780.c @@ -896,15 +896,13 @@ static int jz4780_dma_probe(struct platform_device *pdev) return -EINVAL; } - jzdma->clk = devm_clk_get(dev, NULL); + jzdma->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(jzdma->clk)) { - dev_err(dev, "failed to get clock\n"); + dev_err(dev, "failed to get and enable clock\n"); ret = PTR_ERR(jzdma->clk); return ret; } - clk_prepare_enable(jzdma->clk); - /* Property is optional, if it doesn't exist the value will remain 0. */ of_property_read_u32_index(dev->of_node, "ingenic,reserved-channels", 0, &jzdma->chan_reserved); @@ -972,7 +970,7 @@ static int jz4780_dma_probe(struct platform_device *pdev) ret = platform_get_irq(pdev, 0); if (ret < 0) - goto err_disable_clk; + return ret; jzdma->irq = ret; @@ -980,7 +978,7 @@ static int jz4780_dma_probe(struct platform_device *pdev) jzdma); if (ret) { dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq); - goto err_disable_clk; + return ret; } ret = dmaenginem_async_device_register(dd); @@ -1002,9 +1000,6 @@ static int jz4780_dma_probe(struct platform_device *pdev) err_free_irq: free_irq(jzdma->irq, jzdma); - -err_disable_clk: - clk_disable_unprepare(jzdma->clk); return ret; } @@ -1015,7 +1010,6 @@ static void jz4780_dma_remove(struct platform_device *pdev) of_dma_controller_free(pdev->dev.of_node); - clk_disable_unprepare(jzdma->clk); free_irq(jzdma->irq, jzdma); for (i = 0; i < jzdma->soc_data->nb_channels; i++)