From patchwork Tue Feb 12 12:36:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 2128231 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 73A9F3FCA4 for ; Tue, 12 Feb 2013 12:36:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 551B2E638B for ; Tue, 12 Feb 2013 04:36:50 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 34056E5C13 for ; Tue, 12 Feb 2013 04:36:37 -0800 (PST) Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MI300D3AXOWVF30@mailout1.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 12 Feb 2013 21:36:35 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [203.254.230.45]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 09.01.03918.3573A115; Tue, 12 Feb 2013 21:36:35 +0900 (KST) X-AuditID: cbfee61a-b7f7d6d000000f4e-52-511a3753e8d7 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id B8.01.03918.3573A115; Tue, 12 Feb 2013 21:36:35 +0900 (KST) Received: from daeinki-desktop.10.32.193.11 ([10.90.8.53]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MI300BP3XOZ2O40@mmp1.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 12 Feb 2013 21:36:35 +0900 (KST) From: Inki Dae To: airlied@linux.ie, dri-devel@lists.freedesktop.org Subject: [PATCH] drm/exynos: release resources properly when fb creation is failed. Date: Tue, 12 Feb 2013 21:36:35 +0900 Message-id: <1360672595-27365-1-git-send-email-inki.dae@samsung.com> X-Mailer: git-send-email 1.7.4.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDLMWRmVeSWpSXmKPExsVy+t8zXd1gc6lAg6+LdS2ufH3P5sDocb/7 OFMAYxSXTUpqTmZZapG+XQJXxuOWrawFz6Uqlh54yd7A2CbWxcjJISFgItG7eR4rhC0mceHe erYuRi4OIYFljBLfnjxmgyna+W0bC0RiEaPE8xX/GSGcdUwSaz62g7WzCahKTFxxH6xDRMBU omPSUrAOZoFuoI4Hf8GKhAVCJW50zgErYgFqODZnI1ARBwevgIvEoc2FENsUJBbcewt2hoTA DjaJo9PeMELUC0h8m3wIrF5CQFZi0wFmiHpJiYMrbrBMYBRcwMiwilE0tSC5oDgpPddQrzgx t7g0L10vOT93EyMkrKR2MK5ssDjEKMDBqMTDe0NcMlCINbGsuDL3EKMEB7OSCO8hE6lAId6U xMqq1KL8+KLSnNTiQ4zJQMsnMkuJJucDQz6vJN7Q2MDY0NDS0MzU0tSANGElcV7GU08ChATS E0tSs1NTC1KLYLYwcXBKNTCu2/0lNDVuv/ME7lt/JON0KpXq/Ou9U/r2cD79tlBOdfNM6VUP Dvz/zsrIyrrkSa9N0g6v/0VPf9p6rLZXfmbLLOSlZeu0uEldJuC2RFlYY9C+9maB7l1pwUfE ZvxuMZp+tzM9tb6RP5j3YtuFvy3/tsWflZockVD5RPT9xfQeESWGiFkrHimxFGckGmoxFxUn AgDJKuZIbwIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmkeLIzCtJLcpLzFFi42I5/e+xgG6wuVSgQc9TFYsrX9+zOTB63O8+ zhTAGNXAaJORmpiSWqSQmpecn5KZl26r5B0c7xxvamZgqGtoaWGupJCXmJtqq+TiE6DrlpkD NFZJoSwxpxQoFJBYXKykb4dpQmiIm64FTGOErm9IEFyPkQEaSFjHmPG4ZStrwXOpiqUHXrI3 MLaJdTFyckgImEjs/LaNBcIWk7hwbz1bFyMXh5DAIkaJ5yv+M0I465gk1nxsZwWpYhNQlZi4 4j4biC0iYCrRMWkpC0gRs0A3UMeDv2BFwgKhEjc654AVsQA1HJuzEaiIg4NXwEXi0OZCiG0K EgvuvWWbwMi9gJFhFaNoakFyQXFSeq6hXnFibnFpXrpecn7uJkZw0D6T2sG4ssHiEKMAB6MS D+8NcclAIdbEsuLK3EOMEhzMSiK8h0ykAoV4UxIrq1KL8uOLSnNSiw8xJgMtn8gsJZqcD4yo vJJ4Q2MTMyNLIzNjE3NjY9KElcR5GU89CRASSE8sSc1OTS1ILYLZwsTBKdXAmMbD6hu9/v+R xCNq8/Svlp+5tn8R58R7F7guzdV1PHJfSDq/KPX2Zt/Cn+EvxGfrV+Yeb/fceub5LO+KJRzC fBedDyqFTloSsnnb1d1Cqnlpq1KV8yt5d4Xw3DnCdjYq4Ovblf2uV5y0a+X0grPmZeas0sie bZSxZ/2L+ZJMK+bGGNsHse5yVWIpzkg01GIuKk4EAEtS2IGeAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Cc: kyungmin.park@samsung.com, sw0312.kim@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org From: YoungJun Cho This patch releases allocated resources properly when exynos_user_fb_create() is failed. Signed-off-by: YoungJun Cho Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/gpu/drm/exynos/exynos_drm_fb.c | 51 +++++++++++++++++--------------- 1 files changed, 27 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_fb.c b/drivers/gpu/drm/exynos/exynos_drm_fb.c index 31d4cb1..0e04f4e 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_fb.c +++ b/drivers/gpu/drm/exynos/exynos_drm_fb.c @@ -221,23 +221,25 @@ exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, struct drm_mode_fb_cmd2 *mode_cmd) { struct drm_gem_object *obj; + struct exynos_drm_gem_obj *exynos_gem_obj; struct exynos_drm_fb *exynos_fb; int i, ret; DRM_DEBUG_KMS("%s\n", __FILE__); - obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); - if (!obj) { - DRM_ERROR("failed to lookup gem object\n"); - return ERR_PTR(-ENOENT); - } - exynos_fb = kzalloc(sizeof(*exynos_fb), GFP_KERNEL); if (!exynos_fb) { DRM_ERROR("failed to allocate exynos drm framebuffer\n"); return ERR_PTR(-ENOMEM); } + obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); + if (!obj) { + DRM_ERROR("failed to lookup gem object\n"); + ret = -ENOENT; + goto err_free; + } + drm_helper_mode_fill_fb_struct(&exynos_fb->fb, mode_cmd); exynos_fb->exynos_gem_obj[0] = to_exynos_gem_obj(obj); exynos_fb->buf_cnt = exynos_drm_format_num_buffers(mode_cmd); @@ -245,43 +247,44 @@ exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, DRM_DEBUG_KMS("buf_cnt = %d\n", exynos_fb->buf_cnt); for (i = 1; i < exynos_fb->buf_cnt; i++) { - struct exynos_drm_gem_obj *exynos_gem_obj; - int ret; - obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[i]); if (!obj) { DRM_ERROR("failed to lookup gem object\n"); - kfree(exynos_fb); - return ERR_PTR(-ENOENT); + ret = -ENOENT; + exynos_fb->buf_cnt = i; + goto err_unreference; } exynos_gem_obj = to_exynos_gem_obj(obj); + exynos_fb->exynos_gem_obj[i] = exynos_gem_obj; ret = check_fb_gem_memory_type(dev, exynos_gem_obj); if (ret < 0) { DRM_ERROR("cannot use this gem memory type for fb.\n"); - kfree(exynos_fb); - return ERR_PTR(ret); + goto err_unreference; } - - exynos_fb->exynos_gem_obj[i] = to_exynos_gem_obj(obj); } ret = drm_framebuffer_init(dev, &exynos_fb->fb, &exynos_drm_fb_funcs); if (ret) { - for (i = 0; i < exynos_fb->buf_cnt; i++) { - struct exynos_drm_gem_obj *gem_obj; - - gem_obj = exynos_fb->exynos_gem_obj[i]; - drm_gem_object_unreference_unlocked(&gem_obj->base); - } - - kfree(exynos_fb); - return ERR_PTR(ret); + DRM_ERROR("failed to init framebuffer.\n"); + goto err_unreference; } return &exynos_fb->fb; + +err_unreference: + for (i = 0; i < exynos_fb->buf_cnt; i++) { + struct drm_gem_object *obj; + + obj = &exynos_fb->exynos_gem_obj[i]->base; + if (obj) + drm_gem_object_unreference_unlocked(obj); + } +err_free: + kfree(exynos_fb); + return ERR_PTR(ret); } struct exynos_drm_gem_buf *exynos_drm_fb_buffer(struct drm_framebuffer *fb,