Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915/selftests: align more to real device lifetimes

To avoid having to create all the device and driver scaffolding we
just manually create and destroy a devres_group.

v2: Rebased

v3: use devres_open/release_group so we can use devm without real
hacks in the driver core or having to create an entire fake bus for
testing drivers. Might want to extract this into helpers eventually,
maybe as a mock_drm_dev_alloc or test_drm_dev_alloc.

v4:
- Fix IS_ERR handling (Matt)
- Delete surplus put_device() in mock_device_release (intel-gfx-ci)

v5:
- do not switch to device_add - it breaks runtime pm in the tests and
with the devres_group_add/release no longer needed for automatic
cleanup (CI). Update commit message to match.
- print correct error in pr_err (Matt)

v6: Remove now unused err variable (CI).

v7: More warning fixes ...

Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Matthew Auld <matthew.william.auld@gmail.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> (v3)
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.william.auld@gmail.com> (v4)
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200919134032.2488403-1-daniel.vetter@ffwll.ch

+19 -20
+19 -20
drivers/gpu/drm/i915/selftests/mock_gem_device.c
··· 79 79 80 80 out: 81 81 i915_params_free(&i915->params); 82 - put_device(&i915->drm.pdev->dev); 83 - i915->drm.pdev = NULL; 84 82 } 85 83 86 84 static struct drm_driver mock_driver = { ··· 121 123 #if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU) 122 124 struct dev_iommu iommu; 123 125 #endif 124 - int err; 125 126 126 127 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); 127 128 if (!pdev) 128 129 return NULL; 129 - i915 = kzalloc(sizeof(*i915), GFP_KERNEL); 130 - if (!i915) { 131 - kfree(pdev); 132 - return NULL; 133 - } 134 - 135 130 device_initialize(&pdev->dev); 136 131 pdev->class = PCI_BASE_CLASS_DISPLAY << 16; 137 132 pdev->dev.release = release_dev; ··· 137 146 iommu.priv = (void *)-1; 138 147 pdev->dev.iommu = &iommu; 139 148 #endif 149 + if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) { 150 + put_device(&pdev->dev); 151 + return NULL; 152 + } 153 + 154 + i915 = devm_drm_dev_alloc(&pdev->dev, &mock_driver, 155 + struct drm_i915_private, drm); 156 + if (IS_ERR(i915)) { 157 + pr_err("Failed to allocate mock GEM device: err=%ld\n", PTR_ERR(i915)); 158 + devres_release_group(&pdev->dev, NULL); 159 + put_device(&pdev->dev); 160 + 161 + return NULL; 162 + } 140 163 141 164 pci_set_drvdata(pdev, i915); 165 + i915->drm.pdev = pdev; 142 166 143 167 dev_pm_domain_set(&pdev->dev, &pm_domain); 144 168 pm_runtime_enable(&pdev->dev); ··· 161 155 if (pm_runtime_enabled(&pdev->dev)) 162 156 WARN_ON(pm_runtime_get_sync(&pdev->dev)); 163 157 164 - err = drm_dev_init(&i915->drm, &mock_driver, &pdev->dev); 165 - if (err) { 166 - pr_err("Failed to initialise mock GEM device: err=%d\n", err); 167 - put_device(&pdev->dev); 168 - kfree(i915); 169 - 170 - return NULL; 171 - } 172 - i915->drm.pdev = pdev; 173 - drmm_add_final_kfree(&i915->drm, i915); 174 158 175 159 i915_params_copy(&i915->params, &i915_modparams); 176 160 ··· 227 231 228 232 void mock_destroy_device(struct drm_i915_private *i915) 229 233 { 230 - drm_dev_put(&i915->drm); 234 + struct device *dev = i915->drm.dev; 235 + 236 + devres_release_group(dev, NULL); 237 + put_device(dev); 231 238 }