From 04b1523728dfcc3003172a7624e9151de7eeb1bd Mon Sep 17 00:00:00 2001
From: Ankur Bansal <ankban@codeaurora.org>
Date: Tue, 15 Aug 2017 16:39:22 +0530
Subject: [PATCH] lrdp_v2 : correct total ion memory calculation in memstat.py

Use correct API to calculate the total ion memory allocation.
On 64bit platforms, the amount of memory allocated by ion can
exceed 32 bits.

Change-Id: I3a99392a921a288e3581bb842bb9989bd7c0d696
---
 linux-ramdump-parser-v2/parsers/memstat.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/linux-ramdump-parser-v2/parsers/memstat.py b/linux-ramdump-parser-v2/parsers/memstat.py
index 322a050..ae23e88 100644
--- a/linux-ramdump-parser-v2/parsers/memstat.py
+++ b/linux-ramdump-parser-v2/parsers/memstat.py
@@ -90,6 +90,8 @@ class MemStats(RamParser):
         offset_total_allocated = \
             self.ramdump.field_offset(
                 'struct ion_heap', 'total_allocated')
+        size = self.ramdump.sizeof(
+                '((struct ion_heap *)0x0)->total_allocated')
         if self.ramdump.arm64:
             addressspace = 8
         else:
@@ -99,9 +101,12 @@ class MemStats(RamParser):
         for i in range(0, number_of_ion_heaps):
             heap_addr_array.append(heap_addr + i * addressspace)
             temp = self.ramdump.read_word(heap_addr_array[i])
-            total_allocated = self.ramdump.read_int(
-                                temp +
-                                offset_total_allocated)
+            if size == 4:
+                total_allocated = self.ramdump.read_int(
+                                    temp + offset_total_allocated)
+            if size == 8:
+                total_allocated = self.ramdump.read_u64(
+                                    temp + offset_total_allocated)
             if total_allocated is None:
                 total_allocated = 0
                 break
-- 
GitLab