From patchwork Mon Mar 20 00:52:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seung-Woo Kim X-Patchwork-Id: 9632967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CF79601E9 for ; Mon, 20 Mar 2017 00:52:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67B9728068 for ; Mon, 20 Mar 2017 00:52:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58E5C2807B; Mon, 20 Mar 2017 00:52:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8317B27F60 for ; Mon, 20 Mar 2017 00:52:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E91DA6E2B6; Mon, 20 Mar 2017 00:52:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2CB316E3FB for ; Mon, 20 Mar 2017 00:52:38 +0000 (UTC) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ON30286493OEWA0@mailout2.samsung.com> for dri-devel@lists.freedesktop.org; Mon, 20 Mar 2017 09:52:36 +0900 (KST) Received: from epsmges5p4.samsung.com (unknown [182.195.40.68]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20170320005235epcas1p1db5bd6f6ac6401b3131e1bf0a0e78220~tcN800g4R3000230002epcas1p1K; Mon, 20 Mar 2017 00:52:35 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p4.samsung.com (EPCPMTA) with SMTP id 2B.F4.04908.3D72FC85; Mon, 20 Mar 2017 09:52:35 +0900 (KST) Received: from epcpsbgm2new.samsung.com (u27.gpu120.samsung.co.kr [203.254.230.27]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20170320005235epcas5p3a5671536d1bc4a01be83567d060d6653~tcN8VzK3q0808808088epcas5p3q; Mon, 20 Mar 2017 00:52:35 +0000 (GMT) X-AuditID: b6c32a58-f79f16d00000132c-fc-58cf27d37075 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 6E.E7.06422.3D72FC85; Mon, 20 Mar 2017 09:52:35 +0900 (KST) Received: from localhost.localdomain ([10.113.62.209]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ON3009UO93LK8B0@mmp1.samsung.com>; Mon, 20 Mar 2017 09:52:35 +0900 (KST) From: Seung-Woo Kim To: dri-devel@lists.freedesktop.org, robclark@freedesktop.org, inki.dae@samsung.com Subject: [PATCH] tests/exynos: fix invalid code of error path in g2d test Date: Mon, 20 Mar 2017 09:52:49 +0900 Message-id: <1489971169-12821-1-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-reply-to: <1489629604-10811-1-git-send-email-sw0312.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEKsWRmVeSWpSXmKPExsWy7bCmhu5l9fMRBus+q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mTX7I5sHmsmrOB1WPnrLvsHve7jzN59G1ZxRjAEuVmk5GamJJa pJCal5yfkpmXbqsUGuKma6GkkJeYm2qrFKHrGxKkpFCWmFMK5BkZoAEH5wD3YCV9uwS3jJnN OxkLDihUPJ3fxtbAeF6yi5GTQ0LARGLhpCksELaYxIV769m6GLk4hASWMkpM6jvIDOH8YJRo 6b8PVsUmoCOxf8lvVhBbRCBUYtvST0wgNrOAr8Tz+xOYQWxhAU+JrvaNYHEWAVWJTUvfsoHY vAJuEqtnbmeC2KYgseAeRJxTwF3iw+NP7F2MHEDL3CSu/IqcwMi7gJFhFaNEakFyQXFSeq5R Xmq5XnFibnFpXrpecn7uJkZw+D6T3sF4eJf7IUYBDkYlHt4bl85FCLEmlhVX5h5ilOBgVhLh FeI5HyHEm5JYWZValB9fVJqTWnyI0RToronMUqLJ+cDYyiuJNzQxNzE3NrAwt7Q0MVIS522c /SxcSCA9sSQ1OzW1ILUIpo+Jg1OqgTF0zk+LtzuY/yzJCn7K/ZI5z9AkcZfQQ+EbyYdTTP8I Vezdcqvud6zmQZlpa+2FTWYFTFsX//Y2V334zoqPDvnKZxdE6HWLyMdI7zF6y6oWPEMi18TI T2EOj6bDhY81vsk1l/NUTC1PWM/2Wxzks1FX58eWnUlxi/4mMHw8r50b+cHE7ZSTqhJLcUai oRZzUXEiAB8daNZ1AgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170320005235epcas5p3a5671536d1bc4a01be83567d060d6653 X-Msg-Generator: CA X-Sender-IP: 203.254.230.27 X-Local-Sender: =?UTF-8?B?6rmA7Iq57JqwG1RpemVuIFBsYXRmb3JtIExhYihTL1fshLw=?= =?UTF-8?B?7YSwKRvsgrzshLHsoITsnpAbU2VuaW9yIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?U2V1bmctV29vIEtpbRtUaXplbiBQbGF0Zm9ybSBMYWIuG1Nh?= =?UTF-8?B?bXN1bmcgRWxlY3Ryb25pY3MbU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG1NUQUYbQzEwVjgxMTE=?= CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-HopCount: 7 X-CMS-RootMailID: 20170320005235epcas5p3a5671536d1bc4a01be83567d060d6653 X-RootMTR: 20170320005235epcas5p3a5671536d1bc4a01be83567d060d6653 References: <1489629604-10811-1-git-send-email-sw0312.kim@samsung.com> Cc: sw0312.kim@samsung.com, emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes invalid code of error path including NULL deference and leak in g2d test. Signed-off-by: Seung-Woo Kim --- tests/exynos/exynos_fimg2d_test.c | 39 +++++++++++++++++++----------------- 1 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/exynos/exynos_fimg2d_test.c b/tests/exynos/exynos_fimg2d_test.c index 797fb6e..e4e960c 100644 --- a/tests/exynos/exynos_fimg2d_test.c +++ b/tests/exynos/exynos_fimg2d_test.c @@ -59,7 +59,6 @@ static void connector_find_mode(int fd, struct connector *c, if (!connector) { fprintf(stderr, "could not get connector %i: %s\n", resources->connectors[i], strerror(errno)); - drmModeFreeConnector(connector); continue; } @@ -98,7 +97,6 @@ static void connector_find_mode(int fd, struct connector *c, if (!c->encoder) { fprintf(stderr, "could not get encoder %i: %s\n", resources->encoders[i], strerror(errno)); - drmModeFreeEncoder(c->encoder); continue; } @@ -264,7 +262,8 @@ static int g2d_copy_test(struct exynos_device *dev, struct exynos_bo *src, userptr = (unsigned long)malloc(size); if (!userptr) { fprintf(stderr, "failed to allocate userptr.\n"); - return -EFAULT; + ret = -EFAULT; + goto fail; } src_img.user_ptr[0].userptr = userptr; @@ -469,7 +468,8 @@ static int g2d_copy_with_scale_test(struct exynos_device *dev, userptr = (unsigned long)malloc(size); if (!userptr) { fprintf(stderr, "failed to allocate userptr.\n"); - return -EFAULT; + ret = -EFAULT; + goto fail; } src_img.user_ptr[0].userptr = userptr; @@ -520,7 +520,7 @@ err_free_userptr: fail: g2d_fini(ctx); - return 0; + return ret;; } static int g2d_blend_test(struct exynos_device *dev, @@ -557,7 +557,8 @@ static int g2d_blend_test(struct exynos_device *dev, userptr = (unsigned long)malloc(size); if (!userptr) { fprintf(stderr, "failed to allocate userptr.\n"); - return -EFAULT; + ret = -EFAULT; + goto fail; } src_img.user_ptr[0].userptr = userptr; @@ -619,7 +620,7 @@ err_free_userptr: fail: g2d_fini(ctx); - return 0; + return ret; } static int g2d_checkerboard_test(struct exynos_device *dev, @@ -645,8 +646,8 @@ static int g2d_checkerboard_test(struct exynos_device *dev, dst_y = 0; checkerboard = create_checkerboard_pattern(screen_width / 32, screen_height / 32, 32); - if (checkerboard == NULL) { - ret = -1; + if (!checkerboard) { + ret = -EFAULT; goto fail; } @@ -755,8 +756,8 @@ int main(int argc, char **argv) dev = exynos_device_create(fd); if (!dev) { - drmClose(dev->fd); - return -EFAULT; + ret = -EFAULT; + goto err_drm_close; } resources = drmModeGetResources(dev->fd); @@ -764,7 +765,7 @@ int main(int argc, char **argv) fprintf(stderr, "drmModeGetResources failed: %s\n", strerror(errno)); ret = -EFAULT; - goto err_drm_close; + goto err_dev_destory; } connector_find_mode(dev->fd, &con, resources); @@ -773,7 +774,7 @@ int main(int argc, char **argv) if (!con.mode) { fprintf(stderr, "failed to find usable connector\n"); ret = -EFAULT; - goto err_drm_close; + goto err_dev_destory; } screen_width = con.mode->hdisplay; @@ -782,7 +783,7 @@ int main(int argc, char **argv) if (screen_width == 0 || screen_height == 0) { fprintf(stderr, "failed to find sane resolution on connector\n"); ret = -EFAULT; - goto err_drm_close; + goto err_dev_destory; } printf("screen width = %d, screen height = %d\n", screen_width, @@ -791,7 +792,7 @@ int main(int argc, char **argv) bo = exynos_create_buffer(dev, screen_width * screen_height * 4, 0); if (!bo) { ret = -EFAULT; - goto err_drm_close; + goto err_dev_destory; } handles[0] = bo->handle; @@ -882,9 +883,11 @@ err_rm_fb: err_destroy_buffer: exynos_destroy_buffer(bo); -err_drm_close: - drmClose(dev->fd); +err_dev_destory: exynos_device_destroy(dev); - return 0; +err_drm_close: + drmClose(fd); + + return ret; }