Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3892884pxb; Mon, 1 Feb 2021 07:19:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHcoY249FnaSBIB1fxO778AM6vrbmjNYlPpS+WUKKa82RGfIIABaNav6TGyt/ErwGu4dYA X-Received: by 2002:a17:906:b0c2:: with SMTP id bk2mr18424225ejb.223.1612192796499; Mon, 01 Feb 2021 07:19:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612192796; cv=none; d=google.com; s=arc-20160816; b=NJ8TiBnazo/E3B5bOCceACOvrCO+hzp/HpasRwkfAAKfzwVPXu4VFMgzVYlkNxl9Tg lEwetKZRQUcV35VUFjE7pnUkuKOt2vTzFUw5A3fd8ZldjE+JpTlSRP/AXbmuHLOC0lGW W7U2fnzZP9Q7PxpZTtX7mhPXaflqk21ZwB2ea87v9JfCR1TcGHn1o478Hly3jnxw/sjp tPuTZpbQTNDGpc/khe7bm5wwQPV7uxf4zujumD8mgQZtJGxFRVq6rUfCdp2oMEXGcX2e cIvhjrYKXRcY2nDcp/lWjz/8o0jWU43bZwjHJnTZDpAHrT6l2q7hxdWyooXBlJEDVAs7 qsuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iCud/oZ0jp00VRdDLSDWa/VPzMcKe48VJwPVpyKJcE8=; b=FnyDo17oh+wpk4j55SiO3JNEY3WgXDSFyqf+/TLGbY9OpU3FMiz88S7aBZsbd595v6 NyHYM3oe3TjqjCvsD+rxRkkPSr3pF9hCNjhGnazLsNqJXR8x0BIjB0Nng44uHZm2hrjy gDCAKgFeCPMNZW7E2K4J9cnt2PmpLiwRVL1OSXg5tRbW8V9a+B4ZUICxLMGeVtHPjh9e +xSGq82J9kup8jhnilngAqLP4fq7DTwZYqLT+kWLnwd2xD83GKFBWlv/ZWGQX8CYMd8J CEFimfAjBub6rlnYG+pi9wPwo4l/OBnNCf27mLwalo+aq022M45cRT3E+5cJ/8a256oM 04iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bljmv40v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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. [23.128.96.18]) by mx.google.com with ESMTP id j25si249652ejy.187.2021.02.01.07.19.30; Mon, 01 Feb 2021 07:19:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bljmv40v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S231316AbhBAPQs (ORCPT + 99 others); Mon, 1 Feb 2021 10:16:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231594AbhBAPQb (ORCPT ); Mon, 1 Feb 2021 10:16:31 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF1EC0613D6 for ; Mon, 1 Feb 2021 07:15:50 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id o5so3311673wmq.2 for ; Mon, 01 Feb 2021 07:15:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=iCud/oZ0jp00VRdDLSDWa/VPzMcKe48VJwPVpyKJcE8=; b=bljmv40viwV5v57+TtBOFwGAaz54F5a9tDXB2PSZe5+LMS1pOd9d8QiRNcEEtmVfmT pdNUcTuIXIUH3CaAc+wpyhYC5hKvmCSEj3iNLAZHozaqd/vHgd82MB0cpAg+LE90lF16 4P26uy+BK3EEMlaZGLfJlDisoXkiQ0huHLkrVAmKcmxDHmxRD8LzSGmdL2Cr3wzW5T7M zg97INgmlfCsvWBOEZA+9NcyNVwamwDVUFyds+AxAL8QQh5KBvfc3PUTwvICN//HHTDZ qkNaJJ1NQUcUnxMsjuP69oEL1TAKNDjTmwV8/PCUe7VrMoqb6akq/NuC0JNy5Wkan48Y G81A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iCud/oZ0jp00VRdDLSDWa/VPzMcKe48VJwPVpyKJcE8=; b=QlrEACqfWWrjHGWZopwKXI8pHHdsOPczTlF2L3KJhszmoh+Stp5YyToYp1MtaX0hEt va4wvMfJMCL2DVseTmiL4to9pj9qpKyVt40sLFqTpQvQQzSsReRK/afGEzXj2mAm4YSp bkseLXUdv48wkhxnyhNvZLXocH7ylXf57Jx7tJwcWva8LxH3qt4uZgfkd2VxmRz7gwjA bwKG0bWMdlg+Mwk2NlbnybsBkuLngKG0lm2dLgukhbCHrePuu0+CgDCI3+YApxlDMyLN G7zxGIYhE5V1LLWbIU3OEh9Th33MHtcDXAdI7WCrNRCGXmEa9RBsIJ/owx8Kyb+yXV8/ 5tJg== X-Gm-Message-State: AOAM5320QfWdHSPjRePCoCvqn9peYM0s9l9YHGzfsQPGJF7mPgrqA/XU WiGvuotP2kiRvdDOdk7dpgWI2w== X-Received: by 2002:a7b:c8c3:: with SMTP id f3mr15569794wml.110.1612192549227; Mon, 01 Feb 2021 07:15:49 -0800 (PST) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id y11sm26855292wrh.16.2021.02.01.07.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 07:15:48 -0800 (PST) Date: Mon, 1 Feb 2021 16:15:29 +0100 From: Jean-Philippe Brucker To: Keqian Zhu Cc: Eric Auger , eric.auger.pro@gmail.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, joro@8bytes.org, maz@kernel.org, robin.murphy@arm.com, alex.williamson@redhat.com, jacob.jun.pan@linux.intel.com, nicoleotsuka@gmail.com, vivek.gautam@arm.com, yi.l.liu@intel.com, zhangfei.gao@linaro.org Subject: Re: [PATCH v13 03/15] iommu/arm-smmu-v3: Maintain a SID->device structure Message-ID: References: <20201118112151.25412-1-eric.auger@redhat.com> <20201118112151.25412-4-eric.auger@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 01, 2021 at 08:26:41PM +0800, Keqian Zhu wrote: > > +static int arm_smmu_insert_master(struct arm_smmu_device *smmu, > > + struct arm_smmu_master *master) > > +{ > > + int i; > > + int ret = 0; > > + struct arm_smmu_stream *new_stream, *cur_stream; > > + struct rb_node **new_node, *parent_node = NULL; > > + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(master->dev); > > + > > + master->streams = kcalloc(fwspec->num_ids, > > + sizeof(struct arm_smmu_stream), GFP_KERNEL); > > + if (!master->streams) > > + return -ENOMEM; > > + master->num_streams = fwspec->num_ids; > This is not roll-backed when fail. No need, the caller frees master > > + > > + mutex_lock(&smmu->streams_mutex); > > + for (i = 0; i < fwspec->num_ids && !ret; i++) { > Check ret at here, makes it hard to decide the start index of rollback. > > If we fail at here, then start index is (i-2). > If we fail in the loop, then start index is (i-1). > [...] > > + if (ret) { > > + for (; i > 0; i--) > should be (i >= 0)? > And the start index seems not correct. Indeed, this whole bit is wrong. I'll fix it while resending the IOPF series. Thanks, Jean