From patchwork Mon Jan 14 08:44:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 10761747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 326FF6C5 for ; Mon, 14 Jan 2019 08:47:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2428228B8D for ; Mon, 14 Jan 2019 08:47:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1682428BA0; Mon, 14 Jan 2019 08:47:44 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,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 C216F28B8D for ; Mon, 14 Jan 2019 08:47:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B4EF06E5F0; Mon, 14 Jan 2019 08:47:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3B40D6E5F0 for ; Mon, 14 Jan 2019 08:47:41 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id f188so7902790wmf.5 for ; Mon, 14 Jan 2019 00:47:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2eE37dROlTulgp8EehVvJi2luqnF0TACq6kEzJmTxMk=; b=Q5Pm+0UP7QaCQkbEUUKvAjIvZVHowUOVRY1E00BVNd2e/4BRU+8DJjzpFU0pDbm27b 7ZHdIugVnIb1eqpH6NFF8FLhTAx458n5QRCvGdFFWZ5mMiuYkjwH/eIPUN3CI62HQKzX tLuQr2hlSS0djE6MQ+G80zRVNG7I2UNpge599qkU26qcLJiAtE+xs8tAh7d4biwRotA/ qw3Mnb5BO0V46rVhD6ASrOy2co5izP8BWt6nOK/aEWo/cNTKwEwzMCljTVhrIXwWJiOc RbFo1pmyWjvSIDao33Ch0qNxeKAWoEAFjh0/OpzFynBIkbamlB0lIHjCGAHiEoeRLxGv W0Ew== X-Gm-Message-State: AJcUukeOAJ3glvntQ0MREp0qiDL3CKi5rdhLRUHM5j/U77nOZm2maPFi I5+okzYGHi2rG92XVvGCEuNyI8tb X-Google-Smtp-Source: ALg8bN5RKon5LG+YhMaJpZ6ZGIcZAYHcE49nctbMpE/RT06R4wcLAO8Vo0eeEWo4EmJSZIN/jX6H7g== X-Received: by 2002:a1c:6489:: with SMTP id y131mr10811529wmb.34.1547455659653; Mon, 14 Jan 2019 00:47:39 -0800 (PST) Received: from localhost.localdomain (cpc91192-cmbg18-2-0-cust374.5-4.cable.virginm.net. [80.6.113.119]) by smtp.gmail.com with ESMTPSA id 60sm100671845wrb.81.2019.01.14.00.47.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 00:47:39 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm: factor out drm_close_helper() function Date: Mon, 14 Jan 2019 08:44:09 +0000 Message-Id: <20190114084410.15266-1-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emil.l.velikov@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Emil Velikov Will be used to plug an existing memory leak. Signed-off-by: Emil Velikov --- drivers/gpu/drm/drm_file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index ffa8dc35515f..149506a20bdc 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -262,6 +262,18 @@ void drm_file_free(struct drm_file *file) kfree(file); } +static void drm_close_helper(struct file *filp) +{ + struct drm_file *file_priv = filp->private_data; + struct drm_device *dev = file_priv->minor->dev; + + mutex_lock(&dev->filelist_mutex); + list_del(&file_priv->lhead); + mutex_unlock(&dev->filelist_mutex); + + drm_file_free(file_priv); +} + static int drm_setup(struct drm_device * dev) { int ret; @@ -473,11 +485,7 @@ int drm_release(struct inode *inode, struct file *filp) DRM_DEBUG("open_count = %d\n", dev->open_count); - mutex_lock(&dev->filelist_mutex); - list_del(&file_priv->lhead); - mutex_unlock(&dev->filelist_mutex); - - drm_file_free(file_priv); + drm_close_helper(filp); if (!--dev->open_count) { drm_lastclose(dev); From patchwork Mon Jan 14 08:44:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 10761749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 985641390 for ; Mon, 14 Jan 2019 08:47:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89E2F28B8D for ; Mon, 14 Jan 2019 08:47:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E53928BA0; Mon, 14 Jan 2019 08:47:46 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,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 4852628B8D for ; Mon, 14 Jan 2019 08:47:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4B86A6E5F1; Mon, 14 Jan 2019 08:47:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by gabe.freedesktop.org (Postfix) with ESMTPS id 27A576E5F0 for ; Mon, 14 Jan 2019 08:47:42 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id g67so7911640wmd.2 for ; Mon, 14 Jan 2019 00:47:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pKIrytTacpK803OH2bbb69nNOo573DfkGqRxeyjdqTo=; b=ZpunYJywkWrsBs9kPGcK0mrpHLJuewpEhealcjrYWFJYpt9kdkfw4M376A3/omuh58 Qi4oc5PTl86YgnuNun84W0qC4h8p0/uqJe9YF0paubGVmSMCRAGFQDP2R9WCd2BwtON2 p6mA1PPI6kUlSbSKnC/Pik+1Pav0Mk/B67LepS2DqSA2axDTlkahZG+AQ4keQlDSw6eu ViGqzOPBCig1r1OH/d3LgFfb9gd3F0R6k9AN8g9VepwMgNWjwkKpXCWJuGIQkCRZLRRE zAHVBkbIM0TTsSYeHi5l0VpeuqyuEJEtYXb1TUz6K6G0gxANYOwxB6ONPrAZo68rMtDf x6OA== X-Gm-Message-State: AJcUukcYTcrRw1uAUkbnf1+M5fdmE+lF4l86T4J3KuZ5/tTBC0PlnPTq sXWob2mGqDZRnQoFJ4+eAB7VcJW4 X-Google-Smtp-Source: ALg8bN53++vL351fzZmMIvypyjzacdxNeCMruOMET/Qj2T2+sC2Ke42bzy5ITOtJLlaCNe9aqh0s+g== X-Received: by 2002:a1c:5dd1:: with SMTP id r200mr11325725wmb.93.1547455660537; Mon, 14 Jan 2019 00:47:40 -0800 (PST) Received: from localhost.localdomain (cpc91192-cmbg18-2-0-cust374.5-4.cable.virginm.net. [80.6.113.119]) by smtp.gmail.com with ESMTPSA id 60sm100671845wrb.81.2019.01.14.00.47.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 00:47:40 -0800 (PST) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm: plug memory leak on drm_setup() failure Date: Mon, 14 Jan 2019 08:44:10 +0000 Message-Id: <20190114084410.15266-2-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190114084410.15266-1-emil.l.velikov@gmail.com> References: <20190114084410.15266-1-emil.l.velikov@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emil.l.velikov@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Emil Velikov Currently we fail to free and detach the drm_file when drm_setup() fails. Use the drm_close_helper to do address that. Signed-off-by: Emil Velikov Reviewed-by: Daniel Vetter Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 149506a20bdc..871dcd8c7545 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -330,8 +330,10 @@ int drm_open(struct inode *inode, struct file *filp) goto err_undo; if (need_setup) { retcode = drm_setup(dev); - if (retcode) + if (retcode) { + drm_close_helper(filp); goto err_undo; + } } return 0;