iommu/tegra-smmu: Unwrap tegra_smmu_group_get
authorNicolin Chen <nicoleotsuka@gmail.com>
Wed, 25 Nov 2020 10:10:09 +0000 (02:10 -0800)
committerWill Deacon <will@kernel.org>
Wed, 25 Nov 2020 11:04:41 +0000 (11:04 +0000)
commitcf910f61aff3c1c7cac4dc0706811389051c0f98
treee2357470c931a4c4a5a21e626ec9c433dd04c853
parentf8394f232b1eab649ce2df5c5f15b0e528c92091
iommu/tegra-smmu: Unwrap tegra_smmu_group_get

The tegra_smmu_group_get was added to group devices in different
SWGROUPs and it'd return a NULL group pointer upon a mismatch at
tegra_smmu_find_group(), so for most of clients/devices, it very
likely would mismatch and need a fallback generic_device_group().

But now tegra_smmu_group_get handles devices in same SWGROUP too,
which means that it would allocate a group for every new SWGROUP
or would directly return an existing one upon matching a SWGROUP,
i.e. any device will go through this function.

So possibility of having a NULL group pointer in device_group()
is upon failure of either devm_kzalloc() or iommu_group_alloc().
In either case, calling generic_device_group() no longer makes a
sense. Especially for devm_kzalloc() failing case, it'd cause a
problem if it fails at devm_kzalloc() yet succeeds at a fallback
generic_device_group(), because it does not create a group->list
for other devices to match.

This patch simply unwraps the function to clean it up.

Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Acked-by: Thierry Reding <treding@nvidia.com>
Link: https://lore.kernel.org/r/20201125101013.14953-2-nicoleotsuka@gmail.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/iommu/tegra-smmu.c