1 From 96cfc336eb33c0152c4aff462bd6a21cd75cc731 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Mon, 25 Jan 2016 14:13:12 -0800
4 Subject: [PATCH] drm/vc4: Return an ERR_PTR from BO creation instead of NULL.
6 Fixes igt vc4_create_bo/create-bo-0 by returning -EINVAL from the
7 ioctl instead of -ENOMEM.
9 Signed-off-by: Eric Anholt <eric@anholt.net>
11 drivers/gpu/drm/vc4/vc4_bo.c | 23 +++++++++++++----------
12 drivers/gpu/drm/vc4/vc4_gem.c | 4 ++--
13 drivers/gpu/drm/vc4/vc4_irq.c | 2 +-
14 drivers/gpu/drm/vc4/vc4_render_cl.c | 4 ++--
15 drivers/gpu/drm/vc4/vc4_validate.c | 4 ++--
16 5 files changed, 20 insertions(+), 17 deletions(-)
18 --- a/drivers/gpu/drm/vc4/vc4_bo.c
19 +++ b/drivers/gpu/drm/vc4/vc4_bo.c
20 @@ -213,10 +213,10 @@ struct vc4_bo *vc4_bo_create(struct drm_
21 size_t size = roundup(unaligned_size, PAGE_SIZE);
22 struct vc4_dev *vc4 = to_vc4_dev(dev);
23 struct drm_gem_cma_object *cma_obj;
29 + return ERR_PTR(-EINVAL);
31 /* First, try to get a vc4_bo from the kernel BO cache. */
33 @@ -247,14 +247,17 @@ struct vc4_bo *vc4_bo_create(struct drm_
34 * unreferenced BOs to the cache, and then
37 - vc4_wait_for_seqno(dev, vc4->emit_seqno, ~0ull, true);
38 + ret = vc4_wait_for_seqno(dev, vc4->emit_seqno, ~0ull,
41 + return ERR_PTR(ret);
42 vc4_job_handle_completed(vc4);
43 vc4_bo_cache_purge(dev);
46 DRM_ERROR("Failed to allocate from CMA:\n");
47 vc4_bo_stats_dump(vc4);
49 + return ERR_PTR(-ENOMEM);
53 @@ -276,8 +279,8 @@ int vc4_dumb_create(struct drm_file *fil
54 args->size = args->pitch * args->height;
56 bo = vc4_bo_create(dev, args->size, false);
62 ret = drm_gem_handle_create(file_priv, &bo->base.base, &args->handle);
63 drm_gem_object_unreference_unlocked(&bo->base.base);
64 @@ -460,8 +463,8 @@ int vc4_create_bo_ioctl(struct drm_devic
65 * get zeroed, and that might leak data between users.
67 bo = vc4_bo_create(dev, args->size, false);
73 ret = drm_gem_handle_create(file_priv, &bo->base.base, &args->handle);
74 drm_gem_object_unreference_unlocked(&bo->base.base);
75 @@ -513,8 +516,8 @@ vc4_create_shader_bo_ioctl(struct drm_de
78 bo = vc4_bo_create(dev, args->size, true);
84 ret = copy_from_user(bo->base.vaddr,
85 (void __user *)(uintptr_t)args->data,
86 --- a/drivers/gpu/drm/vc4/vc4_gem.c
87 +++ b/drivers/gpu/drm/vc4/vc4_gem.c
88 @@ -593,9 +593,9 @@ vc4_get_bcl(struct drm_device *dev, stru
91 bo = vc4_bo_create(dev, exec_size, true);
94 DRM_ERROR("Couldn't allocate BO for binning\n");
95 - ret = PTR_ERR(exec->exec_bo);
99 exec->exec_bo = &bo->base;
100 --- a/drivers/gpu/drm/vc4/vc4_irq.c
101 +++ b/drivers/gpu/drm/vc4/vc4_irq.c
102 @@ -57,7 +57,7 @@ vc4_overflow_mem_work(struct work_struct
105 bo = vc4_bo_create(dev, 256 * 1024, true);
108 DRM_ERROR("Couldn't allocate binner overflow mem\n");
111 --- a/drivers/gpu/drm/vc4/vc4_render_cl.c
112 +++ b/drivers/gpu/drm/vc4/vc4_render_cl.c
113 @@ -316,8 +316,8 @@ static int vc4_create_rcl_bo(struct drm_
114 size += xtiles * ytiles * loop_body_size;
116 setup->rcl = &vc4_bo_create(dev, size, true)->base;
119 + if (IS_ERR(setup->rcl))
120 + return PTR_ERR(setup->rcl);
121 list_add_tail(&to_vc4_bo(&setup->rcl->base)->unref_head,
124 --- a/drivers/gpu/drm/vc4/vc4_validate.c
125 +++ b/drivers/gpu/drm/vc4/vc4_validate.c
126 @@ -401,8 +401,8 @@ validate_tile_binning_config(VALIDATE_AR
127 tile_bo = vc4_bo_create(dev, exec->tile_alloc_offset + tile_alloc_size,
129 exec->tile_bo = &tile_bo->base;
130 - if (!exec->tile_bo)
132 + if (IS_ERR(exec->tile_bo))
133 + return PTR_ERR(exec->tile_bo);
134 list_add_tail(&tile_bo->unref_head, &exec->unref_list);
136 /* tile alloc address. */