]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/i915: Declare i915_gem_object_create_internal() as taking phys_addr_t size
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 12 Jan 2017 13:04:31 +0000 (13:04 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 12 Jan 2017 16:47:04 +0000 (16:47 +0000)
The internal object is a collection of struct pages and so is
intrinsically linked to the available physical memory on the machine,
and not an arbitrary type from the uabi. Use phys_addr_t so the link
between size and memory consumption is clear, and then double check that
we don't overflow the maximum object size.

v2: Also assert that size is not zero - a mistake I made a few times
while writing selftests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170112130431.1844-1-chris@chris-wilson.co.uk
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem_internal.c

index e9b4ece689d018243023390e3503895ed0df308a..234c5890134ffa13252ad71af781d0f58c50820e 100644 (file)
@@ -3505,7 +3505,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv
 /* i915_gem_internal.c */
 struct drm_i915_gem_object *
 i915_gem_object_create_internal(struct drm_i915_private *dev_priv,
-                               unsigned int size);
+                               phys_addr_t size);
 
 /* i915_gem_shrinker.c */
 unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
index 2222863e505fd67b970e2a70005565ef01673498..9b39472396effae5a2bd8c3ff878fb0712847aca 100644 (file)
@@ -151,10 +151,15 @@ static const struct drm_i915_gem_object_ops i915_gem_object_internal_ops = {
  */
 struct drm_i915_gem_object *
 i915_gem_object_create_internal(struct drm_i915_private *i915,
-                               unsigned int size)
+                               phys_addr_t size)
 {
        struct drm_i915_gem_object *obj;
 
+       GEM_BUG_ON(!size);
+
+       if (overflows_type(size, obj->base.size))
+               return ERR_PTR(-E2BIG);
+
        obj = i915_gem_object_alloc(i915);
        if (!obj)
                return ERR_PTR(-ENOMEM);