From patchwork Fri Jul 13 18:34:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Obermayr X-Patchwork-Id: 1196601 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 1C8F6DFFFD for ; Fri, 13 Jul 2012 18:38:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1FD719E7B6 for ; Fri, 13 Jul 2012 11:38:28 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23]) by gabe.freedesktop.org (Postfix) with SMTP id 16AEC9E85A for ; Fri, 13 Jul 2012 11:36:38 -0700 (PDT) Received: (qmail invoked by alias); 13 Jul 2012 18:36:38 -0000 Received: from p57915C2C.dip.t-dialin.net (EHLO jobermayr.MSHEIMNETZ) [87.145.92.44] by mail.gmx.net (mp041) with SMTP; 13 Jul 2012 20:36:38 +0200 X-Authenticated: #1405430 X-Provags-ID: V01U2FsdGVkX1+LlF13jUKLoIa+0YDUsxXtYe82ufOamgk2x2IxtX 3kZ6sViffky4Qp From: Johannes Obermayr To: dri-devel@lists.freedesktop.org, marcin.slusarz@gmail.com Subject: [PATCH 2/6] libkms/nouveau.c: Fix a memory leak and make some code easier to read. Date: Fri, 13 Jul 2012 20:34:22 +0200 Message-Id: <1342204466-15460-3-git-send-email-johannesobermayr@gmx.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1342204466-15460-1-git-send-email-johannesobermayr@gmx.de> References: <20120713164750.GA31630@joi.lan> <1342204466-15460-1-git-send-email-johannesobermayr@gmx.de> X-Y-GMX-Trusted: 0 Cc: Johannes Obermayr 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 --- libkms/nouveau.c | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libkms/nouveau.c b/libkms/nouveau.c index 0e24a15..fbca6fe 100644 --- a/libkms/nouveau.c +++ b/libkms/nouveau.c @@ -90,21 +90,24 @@ nouveau_bo_create(struct kms_driver *kms, } } - bo = calloc(1, sizeof(*bo)); - if (!bo) - return -ENOMEM; - - if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) { + switch (type) { + case KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8: pitch = 64 * 4; size = 64 * 64 * 4; - } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) { + break; + case KMS_BO_TYPE_SCANOUT_X8R8G8B8: pitch = width * 4; pitch = (pitch + 512 - 1) & ~(512 - 1); size = pitch * height; - } else { + break; + default: return -EINVAL; } + bo = calloc(1, sizeof(*bo)); + if (!bo) + return -ENOMEM; + memset(&arg, 0, sizeof(arg)); arg.info.size = size; arg.info.domain = NOUVEAU_GEM_DOMAIN_MAPPABLE | NOUVEAU_GEM_DOMAIN_VRAM; @@ -114,8 +117,10 @@ nouveau_bo_create(struct kms_driver *kms, arg.channel_hint = 0; ret = drmCommandWriteRead(kms->fd, DRM_NOUVEAU_GEM_NEW, &arg, sizeof(arg)); - if (ret) - goto err_free; + if (ret) { + free(bo); + return ret; + } bo->base.kms = kms; bo->base.handle = arg.info.handle; @@ -126,10 +131,6 @@ nouveau_bo_create(struct kms_driver *kms, *out = &bo->base; return 0; - -err_free: - free(bo); - return ret; } static int