Skip to contentSkip to conversation

selftests/cgroup: read and write size_t with %zu in test_zswap

PATCH Applied Sasha Levin 2 participants 2 messages Nov 3

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/cgroup: read and write size_t with %zu in test_zswap

On 32-bit architectures size_t is an unsigned int, and reading and writing it with %ld warns:

test_zswap.c:34:29: warning: format '%ld' expects argument of type 'long int *', but argument 3 has type 'size_t *' {aka 'unsigned int *'} [-Wformat=]

Use %zu.

---
Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16 and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without format warnings there now, and the x86_64 builds don't change. The other selftests get the same kind of fix in separate patches.

 tools/testing/selftests/cgroup/test_zswap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/cgroup/test_zswap.c +2 -2
index d50acc1b83ac8..9b5769b417410 100644
@@ -31,7 +31,7 @@ static int read_int(const char *path, size_t *value)
 	file = fopen(path, "r");
 	if (!file)
 		return -1;
-	if (fscanf(file, "%ld", value) != 1)
+	if (fscanf(file, "%zu", value) != 1)
 		ret = -1;
 	fclose(file);
 	return ret;
@@ -45,7 +45,7 @@ static int set_min_free_kb(size_t value)
 	file = fopen("/proc/sys/vm/min_free_kbytes", "w");
 	if (!file)
 		return -1;
-	ret = fprintf(file, "%ld\n", value);
+	ret = fprintf(file, "%zu\n", value);
 	fclose(file);
 	return ret;
 }
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw

Applied to cgroup/for-7.5.

Thanks.

--
tejun