iommu/arm-smmu: Adding NULL checks

Added NULL checks to avoid NULL pointer dereference.

Change-Id: Ifa92792c116d752b80fbcc94daf53fd9d0cdab04
Signed-off-by: Sushanth Vadapally <quic_vadapall@quicinc.com>
Signed-off-by: Madhu Ananthula <quic_mananthu@quicinc.com>
This commit is contained in:
Sushanth Vadapally
2023-08-31 16:28:18 +05:30
committed by Madhu Ananthula
parent dabd5f1d90
commit 1b00e8fe32

View File

@@ -458,6 +458,9 @@ static int __arm_smmu_alloc_cb(unsigned long *map, int start, int end,
int i;
int cb = -EINVAL;
if (!fwspec || !cfg)
return cb;
for_each_cfg_sme(cfg, fwspec, i, idx) {
if (smmu->s2crs[idx].pinned)
cb = smmu->s2crs[idx].cbndx;
@@ -1113,7 +1116,7 @@ static bool arm_smmu_master_attached(struct arm_smmu_device *smmu,
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct arm_smmu_master_cfg *cfg = dev_iommu_priv_get(dev);
if (!cfg || !fwspec)
if (!fwspec || !cfg)
return false;
for_each_cfg_sme(cfg, fwspec, i, idx) {
@@ -1959,6 +1962,9 @@ static int arm_smmu_master_alloc_smes(struct device *dev)
bool config_smrs = !dev_defer_smr_configuration(dev);
int i, idx, ret;
if (!fwspec || !cfg)
return -EINVAL;
mutex_lock(&smmu->stream_map_mutex);
/* Figure out a viable stream map entry allocation */
for_each_cfg_sme(cfg, fwspec, i, idx) {
@@ -2771,6 +2777,9 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
struct iommu_group *group = NULL;
int i, idx;
if (!cfg || !fwspec)
return ERR_PTR(-EINVAL);
mutex_lock(&smmu->stream_map_mutex);
group = of_get_device_group(dev);
if (group)