As drm now exports a method to create an anonymous struct file around a
drm_device for internal use, make use of it to avoid our horrible hacks.
Danial suggested that the mock_file_put() wrapper was suitable for
drm-core, along with the mock_drm_getfile() [and that the vestigal
mock_drm_file() in this patch should perhaps be the drm interface
itself]. However, the eventual goal is to remove the mock_drm_file() and
use the struct file and fput() directly, in this patch we take a simple
transition in that direction.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20191107180601.30815-3-chris@chris-wilson.co.uk
select X86_MSR # used by igt/pm_rpm
select DRM_VGEM # used by igt/prime_vgem (dmabuf interop checks)
select DRM_DEBUG_MM if DRM=y
+ select DRM_EXPORT_FOR_TESTS if m
select DRM_DEBUG_SELFTEST
select DMABUF_SELFTESTS
select SW_SYNC # signaling validation framework (igt/syncobj*)
bool "Enable selftests upon driver load"
depends on DRM_I915
default n
+ select DRM_EXPORT_FOR_TESTS if m
select FAULT_INJECTION
select PRIME_NUMBERS
help
err = i915_subtests(tests, ctx);
out_file:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
}
out_file:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
}
kfree(data);
out_file:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
if (igt_live_test_end(&t))
err = -EIO;
- mock_file_free(i915, file);
+ mock_file_put(file);
if (err)
return err;
if (igt_live_test_end(&t))
err = -EIO;
out_file:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
if (igt_live_test_end(&t))
err = -EIO;
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
out_file:
if (igt_live_test_end(&t))
err = -EIO;
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
intel_context_put(ce);
out_file:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
intel_context_put(ce);
out_file:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
}
out_file:
- mock_file_free(gt->i915, file);
+ mock_file_put(file);
return err;
}
}
out_file:
- mock_file_free(gt->i915, file);
+ mock_file_put(file);
return err;
}
err = igt_flush_test(gt->i915);
out:
- mock_file_free(gt->i915, file);
+ mock_file_put(file);
if (intel_gt_is_wedged(gt))
err = -EIO;
return err;
err = igt_flush_test(gt->i915);
out:
- mock_file_free(gt->i915, file);
+ mock_file_put(file);
if (intel_gt_is_wedged(gt))
err = -EIO;
return err;
}
err_file:
- mock_file_free(engine->i915, file);
+ mock_file_put(file);
return err;
}
i915_vm_put(vm);
out:
- mock_file_free(gt->i915, file);
+ mock_file_put(file);
return err;
}
}
out_file:
- mock_file_free(gt->i915, file);
+ mock_file_put(file);
return err;
}
err = switch_to_context(ctx);
out:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
err = switch_to_context(ctx);
out:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
pr_info("Submitted %lu contexts/requests on %s\n",
count, engine->name);
- mock_file_free(i915, file);
+ mock_file_put(file);
if (err)
break;
}
i915_vm_put(&ppgtt->vm);
out_free:
- mock_file_free(dev_priv, file);
+ mock_file_put(file);
return err;
}
out_vm:
i915_vm_put(vm);
out_unlock:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
out_smoke:
kfree(smoke);
out_file:
- mock_file_free(i915, file);
+ mock_file_put(file);
out_rpm:
intel_runtime_pm_put(&i915->runtime_pm, wakeref);
out_put:
i915_gem_object_put(obj);
out_file:
- mock_file_free(i915, file);
+ mock_file_put(file);
return err;
}
*
*/
+#include <drm/drm_file.h>
+
#include "mock_drm.h"
struct drm_file *mock_file(struct drm_i915_private *i915)
{
- struct file *filp;
- struct inode *inode;
- struct drm_file *file;
- int err;
-
- inode = kzalloc(sizeof(*inode), GFP_KERNEL);
- if (!inode) {
- err = -ENOMEM;
- goto err;
- }
-
- inode->i_rdev = i915->drm.primary->index;
-
- filp = kzalloc(sizeof(*filp), GFP_KERNEL);
- if (!filp) {
- err = -ENOMEM;
- goto err_inode;
- }
-
- err = drm_open(inode, filp);
- if (err)
- goto err_filp;
+ struct file *file;
- file = filp->private_data;
- memset(&file->filp, POISON_INUSE, sizeof(file->filp));
- file->authenticated = true;
-
- kfree(filp);
- kfree(inode);
- return file;
-
-err_filp:
- kfree(filp);
-err_inode:
- kfree(inode);
-err:
- return ERR_PTR(err);
-}
-
-void mock_file_free(struct drm_i915_private *i915, struct drm_file *file)
-{
- struct file filp = { .private_data = file };
+ file = mock_drm_getfile(i915->drm.primary, O_RDWR);
+ if (IS_ERR(file))
+ return ERR_CAST(file);
- drm_release(NULL, &filp);
+ return file->private_data;
}
#ifndef __MOCK_DRM_H
#define __MOCK_DRM_H
+struct drm_file;
+struct drm_i915_private;
+
struct drm_file *mock_file(struct drm_i915_private *i915);
-void mock_file_free(struct drm_i915_private *i915, struct drm_file *file);
+static inline void mock_file_put(struct drm_file *file)
+{
+ fput(file->filp);
+}
#endif /* !__MOCK_DRM_H */