Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6499109ybi; Mon, 8 Jul 2019 04:03:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwx42Dq8dUsKFrGhSnpX5G31KzZ6kNL8qOVlc1zlNEcdZhP+WafyiFIgXegA51wD4JOu3eC X-Received: by 2002:a63:6cc3:: with SMTP id h186mr22450722pgc.292.1562583812675; Mon, 08 Jul 2019 04:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562583812; cv=none; d=google.com; s=arc-20160816; b=S/DEYXO5uzFZyV3I1O0OEWJc2/NqHlTUt6UrwN6gr49EoHG38nkpHwu8NAFMlCOtuk 23h4bcnEmi88WP3R1c8z65iVDpcVPG8u/95tn8SjP/ei2QtYweKEdVvoc3iwxu/3GMwl OTxChhfWJMIVA/i7vI7j8CYqGOc4Q3KNaqrpWS7fSpXxDYNRGvQVc8nr7r2fSWiZWWIB mJRWSyDxG3d3hy5YhKX5Ehvu4pkN2oINChY1VHkFss/V+msBxmuXsdQQFohEGLDENtih 9FuY6z1OfM5CAP4dj313q8G3dn4WpD3jQ+US3wgokIF+xUXpeglr/7MKfYvU0v/gbABF x+YQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=jBz7hfXHxoRJ01d9bkimWwYdZfbZmUErZLqcx40H4Lk=; b=eRZzBJu0iKFuk5mwK2RLeR7ZsR+8QxU9tPN4c2M6O2xvq4U/ssJtphxH95cSeVBWRM Kl821NZSqh0184AV/vmDfbq/RQBTaLkuKEKcM5kl2+tMspNWueQIOhtEjSPTBpzyuZOU BVdgASfW6Y44XE2ZEqZGjw2bMAuPf7Xzk8i9+jdQpcDbbyiiIzhxA8aJzpxsfImHQWol TpajBTRo2tn/esRdXyzk0bADvVCTsH6HTQbfetiIJKQ/FZmdcbOlkE5X8UrsTm0e/8MA ukMQ2tZS7MrolXxKx1JYezElzpa1gWtCLDlYxYjgAOJEn9sBSmpqL6GuUXQpNi/pqb5C kGMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si18406044pgb.166.2019.07.08.04.03.17; Mon, 08 Jul 2019 04:03:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728479AbfGHH6c (ORCPT + 99 others); Mon, 8 Jul 2019 03:58:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45588 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbfGHH6b (ORCPT ); Mon, 8 Jul 2019 03:58:31 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9F72300602A; Mon, 8 Jul 2019 07:58:30 +0000 (UTC) Received: from [10.36.116.46] (ovpn-116-46.ams2.redhat.com [10.36.116.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC44D5D9E2; Mon, 8 Jul 2019 07:58:27 +0000 (UTC) Subject: Re: [PATCH 7/8] iommu/arm-smmu-v3: Improve add_device() error handling To: Jean-Philippe Brucker , will.deacon@arm.com Cc: joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, robin.murphy@arm.com, jacob.jun.pan@linux.intel.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20190610184714.6786-1-jean-philippe.brucker@arm.com> <20190610184714.6786-8-jean-philippe.brucker@arm.com> From: Auger Eric Message-ID: <1e35f298-25bb-719a-b314-c46ded4886a3@redhat.com> Date: Mon, 8 Jul 2019 09:58:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190610184714.6786-8-jean-philippe.brucker@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 08 Jul 2019 07:58:30 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jean, On 6/10/19 8:47 PM, Jean-Philippe Brucker wrote: > Let add_device() clean up behind 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. > > Signed-off-by: Jean-Philippe Brucker Reviewed-by: Eric Auger Thanks Eric > --- > drivers/iommu/arm-smmu-v3.c | 28 +++++++++++++++++++++------- > 1 file changed, 21 insertions(+), 7 deletions(-) > > diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c > index 633d829f246f..972bfb80f964 100644 > --- a/drivers/iommu/arm-smmu-v3.c > +++ b/drivers/iommu/arm-smmu-v3.c > @@ -2398,14 +2398,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; > } > } > > @@ -2419,13 +2421,25 @@ static int arm_smmu_add_device(struct device *dev) > if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB)) > master->ssid_bits = min(master->ssid_bits, 10U); > > + 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) >