From patchwork Mon Jul 1 10:49:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seung-Woo Kim X-Patchwork-Id: 2807031 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0279C9F3EB for ; Mon, 1 Jul 2013 10:49:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0FC6F20168 for ; Mon, 1 Jul 2013 10:49:17 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9EC7520153 for ; Mon, 1 Jul 2013 10:49:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 93981E5E9C for ; Mon, 1 Jul 2013 03:49:15 -0700 (PDT) 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 ESMTP id 5BF51E5D3E for ; Mon, 1 Jul 2013 03:49:03 -0700 (PDT) Received: from epcpsbgr4.samsung.com (u144.gpu120.samsung.co.kr [203.254.230.144]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MP900C6K7DG58C0@mailout2.samsung.com> for dri-devel@lists.freedesktop.org; Mon, 01 Jul 2013 19:49:01 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.116]) by epcpsbgr4.samsung.com (EPCPMTA) with SMTP id 8D.EF.29708.99E51D15; Mon, 01 Jul 2013 19:48:58 +0900 (KST) X-AuditID: cbfee690-b7f6f6d00000740c-d2-51d15e99cadd Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 96.5D.28381.99E51D15; Mon, 01 Jul 2013 19:48:57 +0900 (KST) Received: from localhost.localdomain ([10.90.8.56]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MP900C3X7DJ7300@mmp1.samsung.com>; Mon, 01 Jul 2013 19:48:57 +0900 (KST) From: Seung-Woo Kim To: dri-devel@lists.freedesktop.org, airlied@linux.ie Subject: [PATCH v2 3/3] drm: fix error routines in drm_open_helper Date: Mon, 01 Jul 2013 19:49:10 +0900 Message-id: <1372675750-21312-1-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-reply-to: <20130701101801.GB15843@cantiga.alporthouse.com> References: <20130701101801.GB15843@cantiga.alporthouse.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNLMWRmVeSWpSXmKPExsWyRsSkRHdW3MVAg7tNLBa9504yWdx8eJbV 4srX92wWZ5vesFvMmPySzWLvzsmMDmweKz9oeWz/9oDV4373cSaPvi2rGANYorhsUlJzMstS i/TtErgyts2/wVrwQLji2NZF7A2MbQJdjJwcEgImEr+/fWGBsMUkLtxbz9bFyMUhJLCUUWLN kR/sMEWX1p9khEgsYpTY9e4EC4TTzCTRfGUpM0gVm4COxP4lv1lBbBEBU4mzl6+BxZkF0iUe XbwMNklYwEnizNGVbCA2i4CqxIcpTUBTOTh4BdwkOl5EQCxTkFhw7y1YCaeArcSO1/PAbCEB G4n5PS8YIWr62SWOLmeBGCMg8W3yIRaQMRICshKbDjBDlEhKHFxxg2UCo/ACRoZVjKKpBckF xUnpRSZ6xYm5xaV56XrJ+bmbGIEBffrfswk7GO8dsD7EmAw0biKzlGhyPjAi8kriDY3NjCxM TUyNjcwtzUgTVhLnVW+xDhQSSE8sSc1OTS1ILYovKs1JLT7EyMTBKdXAaJ7rsfLWinuFZR5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000@CPGS X-CFilter-Loop: Reflected Cc: kyungmin.park@samsung.com, sw0312.kim@samsung.com, yj44.cho@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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: YoungJun Cho There are wrong cases to handle error in drm_open_helper(). The priv->minor, assigned by idr_find() which can return NULL, should be checked whether it is NULL or not before referencing it. And if an error occurs after executing dev->driver->open() which allocates driver specific per-file private data, then the private data should be released. Signed-off-by: YoungJun Cho Signed-off-by: Seung-Woo Kim Signed-off-by: Kyungmin Park --- change from v1 - replace error value for failure to find the minor as ENODEV as Chris commented drivers/gpu/drm/drm_fops.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c index 429e07d..0470261 100644 --- a/drivers/gpu/drm/drm_fops.c +++ b/drivers/gpu/drm/drm_fops.c @@ -271,6 +271,11 @@ static int drm_open_helper(struct inode *inode, struct file *filp, priv->uid = current_euid(); priv->pid = get_pid(task_pid(current)); priv->minor = idr_find(&drm_minors_idr, minor_id); + if (!priv->minor) { + ret = -ENODEV; + goto out_free; + } + priv->ioctl_count = 0; /* for compatibility root is always authenticated */ priv->authenticated = capable(CAP_SYS_ADMIN); @@ -304,7 +309,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp, if (!priv->minor->master) { mutex_unlock(&dev->struct_mutex); ret = -ENOMEM; - goto out_free; + goto out_close; } priv->is_master = 1; @@ -322,7 +327,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp, drm_master_put(&priv->minor->master); drm_master_put(&priv->master); mutex_unlock(&dev->struct_mutex); - goto out_free; + goto out_close; } } mutex_lock(&dev->struct_mutex); @@ -333,7 +338,7 @@ static int drm_open_helper(struct inode *inode, struct file *filp, drm_master_put(&priv->minor->master); drm_master_put(&priv->master); mutex_unlock(&dev->struct_mutex); - goto out_free; + goto out_close; } } mutex_unlock(&dev->struct_mutex); @@ -367,7 +372,11 @@ static int drm_open_helper(struct inode *inode, struct file *filp, #endif return 0; - out_free: + +out_close: + if (dev->driver->postclose) + dev->driver->postclose(dev, priv); +out_free: kfree(priv); filp->private_data = NULL; return ret;