LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu: Fix unwind goto issue
@ 2023-04-17  3:04 Chao Wang
  2023-04-17  8:20 ` Heiko Stübner
  2023-05-22 15:03 ` Joerg Roedel
  0 siblings, 2 replies; 3+ messages in thread
From: Chao Wang @ 2023-04-17  3:04 UTC (permalink / raw
  To: Joerg Roedel, Will Deacon, Robin Murphy, Heiko Stuebner,
	Marc Zyngier, Olof Johansson
  Cc: hust-os-kernel-patches, Chao Wang, Dongliang Mu, iommu,
	linux-arm-kernel, linux-rockchip, linux-kernel

Smatch complains that
drivers/iommu/rockchip-iommu.c:1306 rk_iommu_probe() warn: missing unwind goto?

The rk_iommu_probe function, after obtaining the irq value through
platform_get_irq, directly returns an error if the returned value
is negative, without releasing any resources.

Fix this by adding a new error handling label "err_pm_disable" and
use a goto statement to redirect to the error handling process. In
order to preserve the original semantics, set err to the value of irq.

Fixes: 1aa55ca9b14a ("iommu/rockchip: Move irq request past pm_runtime_enable")
Signed-off-by: Chao Wang <D202280639@hust.edu.cn>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
---
This issue is found by static analysis and remains untested.
---
 drivers/iommu/rockchip-iommu.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index f30db22ea5d7..31cd1e2929e9 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1302,20 +1302,22 @@ static int rk_iommu_probe(struct platform_device *pdev)
 	for (i = 0; i < iommu->num_irq; i++) {
 		int irq = platform_get_irq(pdev, i);
 
-		if (irq < 0)
-			return irq;
+		if (irq < 0) {
+			err = irq;
+			goto err_pm_disable;
+		}
 
 		err = devm_request_irq(iommu->dev, irq, rk_iommu_irq,
 				       IRQF_SHARED, dev_name(dev), iommu);
-		if (err) {
-			pm_runtime_disable(dev);
-			goto err_remove_sysfs;
-		}
+		if (err)
+			goto err_pm_disable;
 	}
 
 	dma_set_mask_and_coherent(dev, rk_ops->dma_bit_mask);
 
 	return 0;
+err_pm_disable:
+	pm_runtime_disable(dev);
 err_remove_sysfs:
 	iommu_device_sysfs_remove(&iommu->iommu);
 err_put_group:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu: Fix unwind goto issue
  2023-04-17  3:04 [PATCH] iommu: Fix unwind goto issue Chao Wang
@ 2023-04-17  8:20 ` Heiko Stübner
  2023-05-22 15:03 ` Joerg Roedel
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Stübner @ 2023-04-17  8:20 UTC (permalink / raw
  To: Joerg Roedel, Will Deacon, Robin Murphy, Marc Zyngier,
	Olof Johansson, Chao Wang
  Cc: hust-os-kernel-patches, Chao Wang, Dongliang Mu, iommu,
	linux-arm-kernel, linux-rockchip, linux-kernel

Am Montag, 17. April 2023, 05:04:21 CEST schrieb Chao Wang:
> Smatch complains that
> drivers/iommu/rockchip-iommu.c:1306 rk_iommu_probe() warn: missing unwind goto?
> 
> The rk_iommu_probe function, after obtaining the irq value through
> platform_get_irq, directly returns an error if the returned value
> is negative, without releasing any resources.
> 
> Fix this by adding a new error handling label "err_pm_disable" and
> use a goto statement to redirect to the error handling process. In
> order to preserve the original semantics, set err to the value of irq.
> 
> Fixes: 1aa55ca9b14a ("iommu/rockchip: Move irq request past pm_runtime_enable")
> Signed-off-by: Chao Wang <D202280639@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>

Looking at the code, that makes a lot of sense.

Reviewed-by: Heiko Stuebner <heiko@sntech.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu: Fix unwind goto issue
  2023-04-17  3:04 [PATCH] iommu: Fix unwind goto issue Chao Wang
  2023-04-17  8:20 ` Heiko Stübner
@ 2023-05-22 15:03 ` Joerg Roedel
  1 sibling, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2023-05-22 15:03 UTC (permalink / raw
  To: Chao Wang
  Cc: Will Deacon, Robin Murphy, Heiko Stuebner, Marc Zyngier,
	Olof Johansson, hust-os-kernel-patches, Dongliang Mu, iommu,
	linux-arm-kernel, linux-rockchip, linux-kernel

On Mon, Apr 17, 2023 at 03:04:21AM +0000, Chao Wang wrote:
>  drivers/iommu/rockchip-iommu.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)

Applied for 6.4, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-22 15:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-17  3:04 [PATCH] iommu: Fix unwind goto issue Chao Wang
2023-04-17  8:20 ` Heiko Stübner
2023-05-22 15:03 ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).