Skip to contentSkip to conversation

iommu/arm-smmu: Make use of the iommu_register interface

bug report Dan Carpenter 3 participants 4 messages Feb 15, 2017 – Feb 22, 2017 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hello Joerg Roedel,

This is a semi-automatic email about new static checker warnings.

The patch 9648cbc9625b: "iommu/arm-smmu: Make use of the iommu_register interface" from Feb 1, 2017, leads to the following Smatch complaint:

drivers/iommu/arm-smmu-v3.c:1810 arm_smmu_remove_device()
warn: variable dereferenced before check 'master' (see line 1809)

drivers/iommu/arm-smmu-v3.c
1808 master = fwspec->iommu_priv;

  1809		smmu = master->smmu;
                       ^^^^^^^^^^^^

New dereference.

1810 if (master && master->ste.valid)

                    ^^^^^^

Old code checked for NULL.

  1811			arm_smmu_detach_dev(dev);
  1812		iommu_group_remove_device(dev);

regards,
dan carpenter

#1 lore raw

Hi Dan,

thanks for the report! There are more bogus things going on here.

Quoted 11 lines · Dan Carpenter

The patch 9648cbc9625b: "iommu/arm-smmu: Make use of the iommu_register interface" from Feb 1, 2017, leads to the following Smatch complaint:

drivers/iommu/arm-smmu-v3.c:1810 arm_smmu_remove_device()
warn: variable dereferenced before check 'master' (see line 1809)

drivers/iommu/arm-smmu-v3.c
1808 master = fwspec->iommu_priv;

  1809		smmu = master->smmu;
                       ^^^^^^^^^^^^
Quoted 8 lines

New dereference.

1810 if (master && master->ste.valid)

                    ^^^^^^

Old code checked for NULL.

  1811			arm_smmu_detach_dev(dev);
  1812		iommu_group_remove_device(dev);

So the master pointer comes from fwspec->iommu_priv, and master is freed later in the function. But I can't find where the fwspec->iommu_priv pointer is cleared. To me it looks like this breaks when a device is removed and the added again.

Robin, Will, can you have a look please?

Thanks,

Joerg

#3 lore raw
In reply to a message not in the archive
Quoted 22 lines · Joerg Roedel

Hi Dan,

thanks for the report! There are more bogus things going on here.

Quoted 17 lines · Dan Carpenter

The patch 9648cbc9625b: "iommu/arm-smmu: Make use of the iommu_register interface" from Feb 1, 2017, leads to the following Smatch complaint:

drivers/iommu/arm-smmu-v3.c:1810 arm_smmu_remove_device()
warn: variable dereferenced before check 'master' (see line 1809)

drivers/iommu/arm-smmu-v3.c
1808 master = fwspec->iommu_priv;

  1809		smmu = master->smmu;
                       ^^^^^^^^^^^^

New dereference.

1810 if (master && master->ste.valid)

                    ^^^^^^

Old code checked for NULL.

Quoted 7 lines
Quoted 2 lines
  1811			arm_smmu_detach_dev(dev);
  1812		iommu_group_remove_device(dev);

So the master pointer comes from fwspec->iommu_priv, and master is freed later in the function. But I can't find where the fwspec->iommu_priv pointer is cleared. To me it looks like this breaks when a device is removed and the added again.

The pointer isn't cleared because the whole fwspec is freed on the very next line.

Robin.

Quoted 8 lines

Robin, Will, can you have a look please?

Thanks,

Joerg