From patchwork Mon Dec 19 21:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13077168 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0AB56C4332F for ; Mon, 19 Dec 2022 21:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=uIew5L1Yn3RmXSx4F1B35p+8i/PsKfE3yiU4mkFb/64=; b=oIeGqLLsX0q2qJ c6pJWQl0xFDfkinikU9jO96o/7GTtO4EIsZ7llSWzJdF89agdI4PoKSvpqQ9zjFDV9wVgR9B2yaGN fmH7zF6hV2NYHoh9ftTymjTsOlI4vK6ZQnnM3gleCo2WYPDqQDBGABmYV1Edv8Noo16Ro0L8uwU66 nk+sOMtvUfGduo6aDcnho1F/DkTt5QTbBRtnhTJ4QwnKFfAjn/TES7J9zm8hKENPLGJPwze1pzvdo OXjwknKOFzQmWqMvyPkTAX171m/dqVbE9RQ9FDzCBOOUzZHAnDQhg1pkVan/q7EH7F5bB9Yi1hKOg f62Egwrs6OmKtufsBHRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p7NVq-003s2b-SL; Mon, 19 Dec 2022 21:17:30 +0000 Received: from smtp-19.smtpout.orange.fr ([80.12.242.19] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p7NVl-003rxE-Pj for linux-arm-kernel@lists.infradead.org; Mon, 19 Dec 2022 21:17:28 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221219_131725_996122_6B2A3514 X-CRM114-Status: GOOD ( 12.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 devices") 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/arm/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_device *pdev) /* Reset the device */ ret = arm_smmu_device_reset(smmu, bypass); if (ret) - return ret; + goto err_free_queue; /* And we're up. Go go go! */ ret = iommu_device_sysfs_add(&smmu->iommu, dev, NULL, "smmu3.%pa", &ioaddr); if (ret) - return ret; + goto err_free_queue; ret = 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; } return 0; + +err_remove_sysfs: + iommu_device_sysfs_remove(&smmu->iommu); +err_free_queue: + iopf_queue_free(smmu->evtq.iopf); + return ret; } static int arm_smmu_device_remove(struct platform_device *pdev)