[RFC v4 05/12] drm/nouveau/kms/nv50-: Unroll error cleanup in nv50_head_create()

From: Lyude Paul
Date: Fri May 08 2020 - 16:48:52 EST


We'll be rolling back more things in this function, and the way it's
structured is a bit confusing. So, let's clean this up a bit and just
unroll in the event of failure.

Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
---
drivers/gpu/drm/nouveau/dispnv50/head.c | 33 +++++++++++++++++--------
1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv50/head.c b/drivers/gpu/drm/nouveau/dispnv50/head.c
index 8f6455697ba7..e29ea40e7c33 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/head.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/head.c
@@ -507,20 +507,28 @@ nv50_head_create(struct drm_device *dev, int index)

if (disp->disp->object.oclass < GV100_DISP) {
ret = nv50_base_new(drm, head->base.index, &base);
+ if (ret)
+ goto fail_free;
+
ret = nv50_ovly_new(drm, head->base.index, &ovly);
+ if (ret)
+ goto fail_free;
} else {
ret = nv50_wndw_new(drm, DRM_PLANE_TYPE_PRIMARY,
head->base.index * 2 + 0, &base);
+ if (ret)
+ goto fail_free;
+
ret = nv50_wndw_new(drm, DRM_PLANE_TYPE_OVERLAY,
head->base.index * 2 + 1, &ovly);
- }
- if (ret == 0)
- ret = nv50_curs_new(drm, head->base.index, &curs);
- if (ret) {
- kfree(head);
- return ERR_PTR(ret);
+ if (ret)
+ goto fail_free;
}

+ ret = nv50_curs_new(drm, head->base.index, &curs);
+ if (ret)
+ goto fail_free;
+
crtc = &head->base.base;
drm_crtc_init_with_planes(dev, crtc, &base->plane, &curs->plane,
&nv50_head_func, "head-%d", head->base.index);
@@ -533,11 +541,16 @@ nv50_head_create(struct drm_device *dev, int index)

if (head->func->olut_set) {
ret = nv50_lut_init(disp, &drm->client.mmu, &head->olut);
- if (ret) {
- nv50_head_destroy(crtc);
- return ERR_PTR(ret);
- }
+ if (ret)
+ goto fail_crtc_cleanup;
}

return head;
+
+fail_crtc_cleanup:
+ drm_crtc_cleanup(crtc);
+fail_free:
+ kfree(head);
+
+ return ERR_PTR(ret);
}
--
2.25.4