msm: kgsl: Don't change the sglen of the memdesc if allocation fails

If the page_alloc loop fails, we changed the length of the scatterlist
for the memdesc to the last good page so we could have an efficient
loop through kgsl_sharedmem_free.  Unfortunately, we were also using
the sglen to decide between using kmem or vmalloc memory for the sg
list in the first place. There is a chance that one could start out
with a large sg list from vmalloc, but if it failed early, then we
could truncate the size and attempt to kfree it.

Zero the stlist at init time and use a length == 0 as an indicator
that the list might be truncated.
CRs-Fixed: 443441

Change-Id: Ib48a08c69a7bbfc69b92f09e83fc80f9bdedffe0
Signed-off-by: Dhivya Subramanian <dthiru@codeaurora.org>
diff --git a/drivers/gpu/msm/kgsl_sharedmem.h b/drivers/gpu/msm/kgsl_sharedmem.h
index fd32b45..ffd80fa 100644
--- a/drivers/gpu/msm/kgsl_sharedmem.h
+++ b/drivers/gpu/msm/kgsl_sharedmem.h
@@ -127,8 +127,13 @@
 {
 	if ((sglen * sizeof(struct scatterlist)) <  PAGE_SIZE)
 		return kzalloc(sglen * sizeof(struct scatterlist), GFP_KERNEL);
-	else
-		return vmalloc(sglen * sizeof(struct scatterlist));
+	else {
+		void *ptr = vmalloc(sglen * sizeof(struct scatterlist));
+		if (ptr)
+			memset(ptr, 0, sglen * sizeof(struct scatterlist));
+
+		return ptr;
+	}
 }
 
 static inline void kgsl_sg_free(void *ptr, unsigned int sglen)