[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <692b51fa-7a3e-dee7-b628-7cb2d2dc188d@gmail.com>
Date: Tue, 29 Sep 2020 03:17:58 +0300
From: Dmitry Osipenko <digetx@...il.com>
To: Nicolin Chen <nicoleotsuka@...il.com>, thierry.reding@...il.com,
joro@...tes.org
Cc: vdumpa@...dia.com, jonathanh@...dia.com,
linux-tegra@...r.kernel.org, iommu@...ts.linux-foundation.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/2] iommu/tegra-smmu: Expend mutex protection range
...
> static bool tegra_smmu_capable(enum iommu_cap cap)
> @@ -420,17 +413,21 @@ static int tegra_smmu_as_prepare(struct tegra_smmu *smmu,
> struct tegra_smmu_as *as)
> {
> u32 value;
> - int err;
> + int err = 0;
> +
> + mutex_lock(&smmu->lock);
>
> if (as->use_count > 0) {
> as->use_count++;
> - return 0;
> + goto err_unlock;
This looks a bit odd because it's not a error condition. Perhaps should
be better to "goto bump_usecount"?
Or make it similar to tegra_smmu_as_unprepare()?
> }
>
> as->pd_dma = dma_map_page(smmu->dev, as->pd, 0, SMMU_SIZE_PD,
> DMA_TO_DEVICE);
> - if (dma_mapping_error(smmu->dev, as->pd_dma))
> - return -ENOMEM;
> + if (dma_mapping_error(smmu->dev, as->pd_dma)) {
> + err = -ENOMEM;
> + goto err_unlock;
> + }
>
> /* We can't handle 64-bit DMA addresses */
> if (!smmu_dma_addr_valid(smmu, as->pd_dma)) {
> @@ -453,24 +450,35 @@ static int tegra_smmu_as_prepare(struct tegra_smmu *smmu,
> as->smmu = smmu;
bump_usecount:
> as->use_count++;
>
> + mutex_unlock(&smmu->lock);
> +
> return 0;
>
> err_unmap:
> dma_unmap_page(smmu->dev, as->pd_dma, SMMU_SIZE_PD, DMA_TO_DEVICE);
> +err_unlock:
> + mutex_unlock(&smmu->lock);
> +
> return err;
> }
>
> static void tegra_smmu_as_unprepare(struct tegra_smmu *smmu,
> struct tegra_smmu_as *as)
> {
> - if (--as->use_count > 0)
> + mutex_lock(&smmu->lock);
> +
> + if (--as->use_count > 0) {
> + mutex_unlock(&smmu->lock);
> return;
> + }
>
> tegra_smmu_free_asid(smmu, as->id);
>
> dma_unmap_page(smmu->dev, as->pd_dma, SMMU_SIZE_PD, DMA_TO_DEVICE);
>
> as->smmu = NULL;
> +
> + mutex_unlock(&smmu->lock);
> }
>
> static int tegra_smmu_attach_dev(struct iommu_domain *domain,
>
Powered by blists - more mailing lists