From nobody Wed Sep 17 11:46:29 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AD67C001B2 for ; Mon, 19 Dec 2022 21:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232506AbiLSVR1 (ORCPT ); Mon, 19 Dec 2022 16:17:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiLSVRX (ORCPT ); Mon, 19 Dec 2022 16:17:23 -0500 Received: from smtp.smtpout.orange.fr (smtp-20.smtpout.orange.fr [80.12.242.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5982C12776 for ; Mon, 19 Dec 2022 13:17:20 -0800 (PST) Received: from pop-os.home ([86.243.100.34]) by smtp.orange.fr with ESMTPA id 7NVXpqDedLrOW7NVXpZTjE; Mon, 19 Dec 2022 22:17:17 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 19 Dec 2022 22:17:17 +0100 X-ME-IP: 86.243.100.34 From: Christophe JAILLET To: Will Deacon , Robin Murphy , Joerg Roedel , Eric Auger , Jean-Philippe Brucker , Jonathan Cameron Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev Subject: [PATCH] iommu/arm-smmu-v3: Fix an error handling path in arm_smmu_device_probe() Date: Mon, 19 Dec 2022 22:17:09 +0100 Message-Id: <596b9a44410c67d04599cfd4d6825fa8253c8830.1671484609.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In the arm_smmu_device_probe() probe function, we have the following call chain: arm_smmu_device_probe() --> arm_smmu_init_structures() --> arm_smmu_init_queues() --> iopf_queue_alloc() This memory allocation has to be undone in the error handling path of the probe, as already done in the remove function. While at it, also move a iommu_device_sysfs_remove() call to the newly created error handling path so that error handling is all at the same place. Fixes: 395ad89d11fd ("iommu/arm-smmu-v3: Add stall support for platform dev= ices") Signed-off-by: Christophe JAILLET --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index ab160198edd6..2051b1ed1ff6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3826,22 +3826,27 @@ static int arm_smmu_device_probe(struct platform_de= vice *pdev) /* Reset the device */ ret =3D arm_smmu_device_reset(smmu, bypass); if (ret) - return ret; + goto err_free_queue; =20 /* And we're up. Go go go! */ ret =3D iommu_device_sysfs_add(&smmu->iommu, dev, NULL, "smmu3.%pa", &ioaddr); if (ret) - return ret; + goto err_free_queue; =20 ret =3D iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); if (ret) { dev_err(dev, "Failed to register iommu\n"); - iommu_device_sysfs_remove(&smmu->iommu); - return ret; + goto err_remove_sysfs; } =20 return 0; + +err_remove_sysfs: + iommu_device_sysfs_remove(&smmu->iommu); +err_free_queue: + iopf_queue_free(smmu->evtq.iopf); + return ret; } =20 static int arm_smmu_device_remove(struct platform_device *pdev) --=20 2.34.1