Skip to content

Commit 16cce04

Browse files
icklejnikula
authored andcommitted
drm/i915/selftests: Push the fake iommu device from the stack to data
Since we store a pointer to the fake iommu device that is allocated on the stack, as soon as we leave the function it goes out of scope and any future dereference is undefined behaviour. Just in case we may need to look at the fake iommu device after initialiation, move the allocation from the stack into the data. Fixes: 01b9d4e ("iommu/vt-d: Use dev_iommu_priv_get/set()") Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200916105022.28316-2-chris@chris-wilson.co.uk (cherry picked from commit 9f9f410) Signed-off-by: Jani Nikula <jani.nikula@intel.com>
1 parent e89c832 commit 16cce04

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

drivers/gpu/drm/i915/selftests/mock_gem_device.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ static struct dev_pm_domain pm_domain = {
118118

119119
struct drm_i915_private *mock_gem_device(void)
120120
{
121-
struct drm_i915_private *i915;
122-
struct pci_dev *pdev;
123121
#if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU)
124-
struct dev_iommu iommu;
122+
static struct dev_iommu fake_iommu = { .priv = (void *)-1 };
125123
#endif
124+
struct drm_i915_private *i915;
125+
struct pci_dev *pdev;
126126
int err;
127127

128128
pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
@@ -141,10 +141,8 @@ struct drm_i915_private *mock_gem_device(void)
141141
dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
142142

143143
#if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU)
144-
/* HACK HACK HACK to disable iommu for the fake device; force identity mapping */
145-
memset(&iommu, 0, sizeof(iommu));
146-
iommu.priv = (void *)-1;
147-
pdev->dev.iommu = &iommu;
144+
/* HACK to disable iommu for the fake device; force identity mapping */
145+
pdev->dev.iommu = &fake_iommu;
148146
#endif
149147

150148
pci_set_drvdata(pdev, i915);

0 commit comments

Comments
 (0)