From patchwork Thu Dec 19 16:30:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 182142 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp702545iln; Thu, 19 Dec 2019 08:31:38 -0800 (PST) X-Google-Smtp-Source: APXvYqyN3IzYTdZzbeTQx8WdZoss/GcX3POR7DyRD/vxdJZtKp/wFP0ZB+D9nWsEcqR3YmogDslI X-Received: by 2002:a9d:708f:: with SMTP id l15mr10021868otj.286.1576773098416; Thu, 19 Dec 2019 08:31:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576773098; cv=none; d=google.com; s=arc-20160816; b=SwmvfjHv+713NEHybaGLXDjjC7Y15mDqKZTDUP4yKMn3wQ/mPHnESROpCcGUhN86Ad TTEvIzpNxa4RdK2Jl9G4eOwzjGllg62l7mwqkktfEHaLvih7/IrjCrTXmXgM9rHQmGfL 9M6+x8Et2ARTzF/GmEHJyfjNs1chM2qV4S30rRlM0VCYKqv8j89TEvXI+sG/lbRmK7RY MQuAzj61kbM3gf0LX9NkmlOECNq9amsoojz2EfZVvGFpXgeGn2M6NdtlhZadnbvF+H8k oIIt/YPJgaVEnuELYRT2BF4BF/mkBB98qcGSuf9+hAOApVi4e0APGfKsTrwbKIilYHCN uiTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=en1Diu3sI6Wm13W9qcASbGXcjcSPf5WXodRzGlHYYvg=; b=S1BXwV0DfDqu8UA3UXh+Ln0RvVLC1hxIwKf1kYhWbj9YB2cukVUqnt26VpeT0mXao3 NtWR0Za4lcInuLigzg/0DQs5fi/ivbuZVOBgtFst253BhHwe+G8nxUjqdKW99OLDBbDb h5phHSygR0xuaMSMMzE4bEkgp3m8ZGJwH9s9VIEksZeUkT36AXzJkYepB4Z5fDycRZnA CKJnaFrMFQoLM1IDV0yGoH5bmTsmaXWYJors/vddqu8gNkWqElgpswo7RcQ6DPxIAGnl +yXWwOwJYKeu3wTuSOxQ+lOhViadBb4tU3RdKKxZu1QZl7OIcNmMHZiPupodc8tricuP fr5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dgEdguI1; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n25si2200080oij.175.2019.12.19.08.31.38; Thu, 19 Dec 2019 08:31:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dgEdguI1; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727014AbfLSQbh (ORCPT + 7 others); Thu, 19 Dec 2019 11:31:37 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:56074 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbfLSQbg (ORCPT ); Thu, 19 Dec 2019 11:31:36 -0500 Received: by mail-wm1-f66.google.com with SMTP id q9so6084225wmj.5 for ; Thu, 19 Dec 2019 08:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=en1Diu3sI6Wm13W9qcASbGXcjcSPf5WXodRzGlHYYvg=; b=dgEdguI1vFCV7YNVUg0oEi5hoedAB5SCo0EHqrgrYN2fDZQP1jM0e2gVFmXjAsarm9 sE3jEiVBfo9bIxoraETghmWio/hExZaK0G2MlaAUWWPlH/s/lgj8y2aPluLIJwIiWDO5 nPCsL9EFTnWUXXPdeHMf2mqD8ncvbLtOVcjLDDmK20sqR/zY19gWGF0iPqJMOqrpBHzU P5l5nDoT+24rRDoL/bDgoMasOpqDS3TpLXI4nHsZ6shxvb0a59G2E8TD5mPZoPT7AZm0 TE/nR/n+4AfO7nup111L94qgV7A8exhXah9vnGXYO9tpJuoHYa73upM3pfuz8aU4XUjD EyRw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=en1Diu3sI6Wm13W9qcASbGXcjcSPf5WXodRzGlHYYvg=; b=UDNHGS9vvPHVsTC7fNX7dOLJ/eM0R3LTm1bRBiXLefibm00IKcSdQZZ4RM8IlaTrKx Zx3Ykl1n6hmJJ9kw9VrU6hJ+2AWjJ0QIuG/XS9O/phdhIDOon5KKWLCZ9bE403ZKnMP5 /dhMaSvX1vR5zoZQEd/QQ88ZCTMa06DqGgN35b3pXRf+fE+UAHpCZbMWYJfewdNe9L55 frx/kc+P7pXPHKu+Yyi9QjcGM/+J+KPVNorvSBvjylZ5VpWjEI3i9vGxLAhQGK9xc1Sg MHnpG6rFilhrX9DkxryoQXbMtsuHSuARrj3U1BO5JLi496Wm4aDST2FG3leC1QjZsqEi OGHQ== X-Gm-Message-State: APjAAAVpkbM7NzpDb6rB48KyPFixxzrw+StzvecqCiPJRUkzsWOK6DeF QWRvVDEYYey3ttWhWCf1dmaXRA== X-Received: by 2002:a1c:7d93:: with SMTP id y141mr11448751wmc.111.1576773093503; Thu, 19 Dec 2019 08:31:33 -0800 (PST) Received: from localhost.localdomain (adsl-84-227-176-239.adslplus.ch. [84.227.176.239]) by smtp.gmail.com with ESMTPSA id u22sm7092068wru.30.2019.12.19.08.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 08:31:33 -0800 (PST) From: Jean-Philippe Brucker To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, iommu@lists.linux-foundation.org Cc: joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, guohanjun@huawei.com, sudeep.holla@arm.com, rjw@rjwysocki.net, lenb@kernel.org, will@kernel.org, robin.murphy@arm.com, bhelgaas@google.com, eric.auger@redhat.com, jonathan.cameron@huawei.com, zhangfei.gao@linaro.org Subject: [PATCH v4 11/13] iommu/arm-smmu-v3: Improve add_device() error handling Date: Thu, 19 Dec 2019 17:30:31 +0100 Message-Id: <20191219163033.2608177-12-jean-philippe@linaro.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219163033.2608177-1-jean-philippe@linaro.org> References: <20191219163033.2608177-1-jean-philippe@linaro.org> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Let add_device() clean up after itself. The iommu_bus_init() function does call remove_device() on error, but other sites (e.g. of_iommu) do not. Don't free level-2 stream tables because we'd have to track if we allocated each of them or if they are used by other endpoints. It's not worth the hassle since they are managed resources. Reviewed-by: Eric Auger Reviewed-by: Jonathan Cameron Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) -- 2.24.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index bf106a7b53eb..e62ca80f2f76 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2837,14 +2837,16 @@ static int arm_smmu_add_device(struct device *dev) for (i = 0; i < master->num_sids; i++) { u32 sid = master->sids[i]; - if (!arm_smmu_sid_in_range(smmu, sid)) - return -ERANGE; + if (!arm_smmu_sid_in_range(smmu, sid)) { + ret = -ERANGE; + goto err_free_master; + } /* Ensure l2 strtab is initialised */ if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { ret = arm_smmu_init_l2_strtab(smmu, sid); if (ret) - return ret; + goto err_free_master; } } @@ -2854,13 +2856,25 @@ static int arm_smmu_add_device(struct device *dev) master->ssid_bits = min_t(u8, master->ssid_bits, CTXDESC_LINEAR_CDMAX); + ret = iommu_device_link(&smmu->iommu, dev); + if (ret) + goto err_free_master; + group = iommu_group_get_for_dev(dev); - if (!IS_ERR(group)) { - iommu_group_put(group); - iommu_device_link(&smmu->iommu, dev); + if (IS_ERR(group)) { + ret = PTR_ERR(group); + goto err_unlink; } - return PTR_ERR_OR_ZERO(group); + iommu_group_put(group); + return 0; + +err_unlink: + iommu_device_unlink(&smmu->iommu, dev); +err_free_master: + kfree(master); + fwspec->iommu_priv = NULL; + return ret; } static void arm_smmu_remove_device(struct device *dev)