diff mbox series

[v2,11/24] selftests/resctrl: Remove start_buf local variable from buffer alloc func

Message ID 20230418114506.46788-12-ilpo.jarvinen@linux.intel.com
State New
Headers show
Series selftests/resctrl: Fixes, cleanups, and rewritten CAT test | expand

Commit Message

Ilpo Järvinen April 18, 2023, 11:44 a.m. UTC
alloc_buffer() has local start_ptr variable which is unnecessary.

Assign the pointer of the allocated buffer directly to startptr that is
a global variable in fill_buf to simplify the code in alloc_buffer().

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 tools/testing/selftests/resctrl/fill_buf.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Reinette Chatre April 22, 2023, 12:16 a.m. UTC | #1
Hi Ilpo,

On 4/18/2023 4:44 AM, Ilpo Järvinen wrote:
> alloc_buffer() has local start_ptr variable which is unnecessary.
> 
> Assign the pointer of the allocated buffer directly to startptr that is
> a global variable in fill_buf to simplify the code in alloc_buffer().

I think the opposite (removing the global variable) would make the
code more manageable. Tests manage their own buffer pointers, there is
no need for a global buffer pointer (that I can see).

Reinette
diff mbox series

Patch

diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c
index 6f0438aa71a6..3a10b554d778 100644
--- a/tools/testing/selftests/resctrl/fill_buf.c
+++ b/tools/testing/selftests/resctrl/fill_buf.c
@@ -145,17 +145,13 @@  static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr,
 
 int alloc_buffer(unsigned long long buf_size, int memflush)
 {
-	unsigned char *start_ptr;
-
-	start_ptr = malloc_and_init_memory(buf_size);
-	if (!start_ptr)
+	startptr = malloc_and_init_memory(buf_size);
+	if (!startptr)
 		return -1;
 
-	startptr = start_ptr;
-
 	/* Flush the memory before using to avoid "cache hot pages" effect */
 	if (memflush)
-		mem_flush(start_ptr, buf_size);
+		mem_flush(startptr, buf_size);
 
 	return 0;
 }