From 9b8bb37dbd9431da5899a221d583e578ba800d68 Mon Sep 17 00:00:00 2001
From: Naveen Ramaraj <nramaraj@codeaurora.org>
Date: Mon, 9 Feb 2015 17:43:31 -0800
Subject: [PATCH] msm: smd_pkt: Avoid prematurely stashing driver info

smd_pkt_release() relies on checks that would pass by default
(reference count == 0) to proceed with the release even if the
open was unsuccessful in the first place

Bug: b/18759663
Signed-off-by: Naveen Ramaraj <nramaraj@codeaurora.org>
---
 arch/arm/mach-msm/smd_pkt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-msm/smd_pkt.c b/arch/arm/mach-msm/smd_pkt.c
index d175b39b2dcd..9da145aec375 100644
--- a/arch/arm/mach-msm/smd_pkt.c
+++ b/arch/arm/mach-msm/smd_pkt.c
@@ -826,8 +826,6 @@ int smd_pkt_open(struct inode *inode, struct file *file)
 	}
 	D_STATUS("Begin %s on smd_pkt_dev id:%d\n", __func__, smd_pkt_devp->i);
 
-	file->private_data = smd_pkt_devp;
-
 	mutex_lock(&smd_pkt_devp->ch_lock);
 	if (smd_pkt_devp->ch == 0) {
 		wake_lock_init(&smd_pkt_devp->pa_wake_lock, WAKE_LOCK_SUSPEND,
@@ -942,6 +940,8 @@ release_pd:
 		platform_driver_unregister(&smd_pkt_devp->driver);
 		smd_pkt_devp->driver.probe = NULL;
 	}
+	else if (r == 0)
+		file->private_data = smd_pkt_devp;
 out:
 	if (!smd_pkt_devp->ch)
 		wake_lock_destroy(&smd_pkt_devp->pa_wake_lock);
-- 
GitLab