Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753388AbdLSThT (ORCPT ); Tue, 19 Dec 2017 14:37:19 -0500 Received: from mga11.intel.com ([192.55.52.93]:27379 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752813AbdLSThM (ORCPT ); Tue, 19 Dec 2017 14:37:12 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,428,1508828400"; d="scan'208";a="4018699" From: Dongwon Kim To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, xen-devel@lists.xenproject.org, mateuszx.potrola@intel.com, dongwon.kim@intel.com, Kai Chen Subject: [RFC PATCH 59/60] hyper_dmabuf: freeing hy_drv_priv when drv init fails (v2) Date: Tue, 19 Dec 2017 11:30:15 -0800 Message-Id: <1513711816-2618-59-git-send-email-dongwon.kim@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513711816-2618-1-git-send-email-dongwon.kim@intel.com> References: <1513711816-2618-1-git-send-email-dongwon.kim@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1368 Lines: 49 From: Kai Chen Make sure hy_drv_priv is freed before exiting in several places in hyper_dmabuf_drv_init. v2: unlocking mutex before freeing hy_drv_priv when bknd_ops->init fails Signed-off-by: Kai Chen Signed-off-by: Dongwon Kim --- drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c b/drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c index bbb3414..eead4c0 100644 --- a/drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c +++ b/drivers/xen/hyper_dmabuf/hyper_dmabuf_drv.c @@ -271,8 +271,10 @@ static int __init hyper_dmabuf_drv_init(void) return -ENOMEM; ret = register_device(); - if (ret < 0) + if (ret < 0) { + kfree(hy_drv_priv); return ret; + } /* currently only supports XEN hypervisor */ #ifdef CONFIG_HYPER_DMABUF_XEN @@ -284,6 +286,7 @@ static int __init hyper_dmabuf_drv_init(void) if (hy_drv_priv->bknd_ops == NULL) { printk(KERN_ERR "Hyper_dmabuf: no backend found\n"); + kfree(hy_drv_priv); return -1; } @@ -336,6 +339,8 @@ static int __init hyper_dmabuf_drv_init(void) if (ret < 0) { dev_dbg(hy_drv_priv->dev, "failed to initialize backend.\n"); + mutex_unlock(&hy_drv_priv->lock); + kfree(hy_drv_priv); return ret; } } -- 2.7.4