From patchwork Tue Jun 8 16:45:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ameynarkhede03 X-Patchwork-Id: 12307545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF4F3C47082 for ; Tue, 8 Jun 2021 16:47:54 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 893A4611BD for ; Tue, 8 Jun 2021 16:47:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 893A4611BD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=gDzSDRKIwR8moS1CbNRRdAp4esdIobeR8DfsOFoIzu8=; b=GSq85mi0FkYJlu fGxmF3u3RWwrNFN8yyOiFBh+jFH3laQv0irwfzvI96Z2KehIqHfmLycfPN2s5KBC8aSMFVO1TuPHo JQPcfFvCNtW7Wo82lC3DXmYL/iiQKNpTJe4IKKG2hMFRpt010VBM2pmJTrc8kKI/13pDwBPYenW2b PKOb/BDWMT1s0htLd6f7LoqbISn9fj2x6Cxp14XbIqtN7YuUKCnrpd7ZAQo1L7ST/vUMu/PqkcHHS VU/GXJBTYH+B5LH5NZ/Wn7Aqk3iGna1afdeSnaCEoXYG+KtU9ry7lCFlgH4ce+5nWVEqPLX+0PeMg P/AzhVv8Aksvx0lFfRmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqerk-009ZqC-V7; Tue, 08 Jun 2021 16:46:13 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqerh-009Zpd-8O for linux-arm-kernel@lists.infradead.org; Tue, 08 Jun 2021 16:46:10 +0000 Received: by mail-pj1-x102e.google.com with SMTP id d5-20020a17090ab305b02901675357c371so14092803pjr.1 for ; Tue, 08 Jun 2021 09:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2t+iT1aOdYCZU2AlXESXqTpbLz1wOUqv173mhLsP5Jc=; b=TY6Sk2eZt08YqlpdA2cn4pVa+JehYb0k4OUYb4sO8TTUbHYJeVSegoOB78bUraCAT/ fv7Ic76M+WjKuz5VcW3wInudkLbyQLWyRjQQe2xT9eZ43uLOdX6MZU9CylSpv6oY01vN jLSx70QPKb7cIG8M+Vlb04dKoWfQNVS9rhla0EbeIKEOwAIgjMPC4AM5fI4mz1krklc8 IpR+dokjcJ5myPc6sUULCwy1cOJoGF6+/2y+Gi41QP7SEmSzyV9xaSMmK3ahaLZAMBIh lif10rY7YaVrrZ/JD4GpT3udb6QZ3FvsVvbjQ0MQrVdBcyXVuTbPtI8iJOnwRS87Y78N BBDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2t+iT1aOdYCZU2AlXESXqTpbLz1wOUqv173mhLsP5Jc=; b=bkek4GJk4G4wa0iILm+jkqyAUCaVyc3OwzIGpST7xIqK+EbVjOMR75hF6Fiuw1wx5+ osc3NmdHNlhUkk3tCGRwXJ/34ODIxMEW8F8+v5WM930pT0Pvt7EQ0Zsf1+6ehwniJ1hd Lmyc2smCTWC5TjqgzT2KMmvc4JaAwGgRxMRdp16pEAXyt9B8ElxhTg9styWuPNOWZRz6 XqFSCH9hlnPniu5eG5x9xbrduDz5r6TMBlk6DXMBNobBILIHz6aWDw5tsk+dNKlzW3I9 WQSknQIjaVLmMsgQseSzW2A7GGnBfU8gk/+MtJfuzd4na09g78pkd/9BRcO+U/DCAKAm 5UuQ== X-Gm-Message-State: AOAM532xKx4ZT7dYE3AqyrIIfLojqboUwoeg4o7CbJ8h2sq5GMw0RrGU kZe9MHoPp+tCEIVAPIKQGoY= X-Google-Smtp-Source: ABdhPJxo8z0gKm9nyddE2hgbA+4T56fMWkoWk4WJ05zb+Et72S0ZZzGhKucyCJluOysvsJpLM1gyLg== X-Received: by 2002:a17:90a:5998:: with SMTP id l24mr7427786pji.169.1623170768185; Tue, 08 Jun 2021 09:46:08 -0700 (PDT) Received: from localhost.localdomain ([103.200.106.115]) by smtp.googlemail.com with ESMTPSA id t6sm2864863pjo.4.2021.06.08.09.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 09:46:07 -0700 (PDT) From: Amey Narkhede To: Rob Clark Subject: [PATCH] iommu/arm: Cleanup resources in case of probe error path Date: Tue, 8 Jun 2021 22:15:59 +0530 Message-Id: <20210608164559.204023-1-ameynarkhede03@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210608_094609_345108_34E16ECB X-CRM114-Status: GOOD ( 14.01 ) 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: , Cc: Barry Song , Jean-Philippe Brucker , Sai Prakash Ranjan , Will Deacon , Joerg Roedel , Jonathan Cameron , linux-kernel@vger.kernel.org, Jon Hunter , iommu@lists.linux-foundation.org, linux-arm-msm@vger.kernel.org, Zenghui Yu , Amey Narkhede , Robin Murphy , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If device registration fails, remove sysfs attribute and if setting bus callbacks fails, unregister the device and cleanup the sysfs attribute. Signed-off-by: Amey Narkhede --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 14 ++++++++++++-- drivers/iommu/arm/arm-smmu/arm-smmu.c | 15 ++++++++++++--- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 13 +++++++++++-- 3 files changed, 35 insertions(+), 7 deletions(-) -- 2.31.1 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 54b2f27b81d4..de2499754025 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3669,10 +3669,20 @@ static int arm_smmu_device_probe(struct platform_device *pdev) ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); if (ret) { dev_err(dev, "Failed to register iommu\n"); - return ret; + goto err_sysfs_remove; } - return arm_smmu_set_bus_ops(&arm_smmu_ops); + ret = arm_smmu_set_bus_ops(&arm_smmu_ops); + if (ret) + goto err_unregister_device; + + return 0; + +err_unregister_device: + iommu_device_unregister(&smmu->iommu); +err_sysfs_remove: + iommu_device_sysfs_remove(&smmu->iommu); + return ret; } static int arm_smmu_device_remove(struct platform_device *pdev) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 6f72c4d208ca..88a3023676ce 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -2164,7 +2164,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev) err = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); if (err) { dev_err(dev, "Failed to register iommu\n"); - return err; + goto err_sysfs_remove; } platform_set_drvdata(pdev, smmu); @@ -2187,10 +2187,19 @@ static int arm_smmu_device_probe(struct platform_device *pdev) * any device which might need it, so we want the bus ops in place * ready to handle default domain setup as soon as any SMMU exists. */ - if (!using_legacy_binding) - return arm_smmu_bus_init(&arm_smmu_ops); + if (!using_legacy_binding) { + err = arm_smmu_bus_init(&arm_smmu_ops); + if (err) + goto err_unregister_device; + } return 0; + +err_unregister_device: + iommu_device_unregister(&smmu->iommu); +err_sysfs_remove: + iommu_device_sysfs_remove(&smmu->iommu); + return err; } static int arm_smmu_device_remove(struct platform_device *pdev) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 4294abe389b2..b785d9fb7602 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -850,10 +850,12 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) ret = iommu_device_register(&qcom_iommu->iommu, &qcom_iommu_ops, dev); if (ret) { dev_err(dev, "Failed to register iommu\n"); - return ret; + goto err_sysfs_remove; } - bus_set_iommu(&platform_bus_type, &qcom_iommu_ops); + ret = bus_set_iommu(&platform_bus_type, &qcom_iommu_ops); + if (ret) + goto err_unregister_device; if (qcom_iommu->local_base) { pm_runtime_get_sync(dev); @@ -862,6 +864,13 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) } return 0; + +err_unregister_device: + iommu_device_unregister(&qcom_iommu->iommu); + +err_sysfs_remove: + iommu_device_sysfs_remove(&qcom_iommu->iommu); + return ret; } static int qcom_iommu_device_remove(struct platform_device *pdev)