automated: linux: modules: move memory measurement outside iteration loop

Restructure the testing loop to implement cumulative memory leak detection:

- Record memory usage once at the start of all iterations for a module
- Remove per-iteration memory recording and leak checking
- Move leak detection to after all iterations complete
- Record final memory usage after all load/unload cycles

This changes the approach from checking for leaks after each individual
load/unload cycle to checking for cumulative leaks after all cycles
complete. This provides cleaner test results with one pass/fail per
module instead of multiple results per module.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
diff --git a/automated/linux/modules/modules.sh b/automated/linux/modules/modules.sh
index 8b6cd56..0f926c0 100755
--- a/automated/linux/modules/modules.sh
+++ b/automated/linux/modules/modules.sh
@@ -144,9 +144,11 @@
 	for module in ${MODULES_LIST}; do
 		# don't insert/remove modules that is already inserted.
 		if ! lsmod | grep "^${module}"; then
+			# Record memory at start of all iterations
+			mem_start=$(get_mem_usage_kb)
+
 			for num in $(seq "${MODULE_MODPROBE_NUMBER}"); do
 				dmesg -C
-				mem_before=$(get_mem_usage_kb)
 				report "" "${module}" "insert" "${num}"
 				echo
 				echo "modinfo ${module}"
@@ -157,9 +159,11 @@
 				scan_dmesg_for_errors
 
 				check_module_unloaded "${module}"
-				mem_after=$(get_mem_usage_kb)
-				check_module_memory_leaks_cumulative "$mem_before" "$mem_after" "$module"
 			done
+
+			# Check for cumulative leaks after all iterations
+			mem_end=$(get_mem_usage_kb)
+			check_module_memory_leaks_cumulative "$module" "$mem_start" "$mem_end"
 		fi
 	done
 }