Skip to contentSkip to conversation

selftests/mount: Explicitly define buffer size

PATCH In review [email protected] 2 participants 3 messages Feb 22, 2025 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/mount: Explicitly define buffer size

From: Ritvik Gupta <[email protected]>

Define macro ('MAX_BUF_SIZE') for buffer size
instead of hardcoded value '4096', to improve
readability.

---
 tools/testing/selftests/mount/unprivileged-remount-test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/mount/unprivileged-remount-test.c +3 -1
index d2917054fe3a..67a550b7c69b 100644
@@ -45,6 +45,8 @@
 # define MS_STRICTATIME (1 << 24)
 #endif
 
+#define MAX_BUF_SIZE 4096
+
 static void die(char *fmt, ...)
 {
 	va_list ap;
@@ -56,7 +58,7 @@ static void die(char *fmt, ...)
 
 static void vmaybe_write_file(bool enoent_ok, char *filename, char *fmt, va_list ap)
 {
-	char buf[4096];
+	char buf[MAX_BUF_SIZE];
 	int fd;
 	ssize_t written;
 	int buf_len;
Signature · 1 line
2.48.1
#1 lore raw
Quoted 25 lines · On Sat, Feb 22, 2025 at 01:47:11PM +0530, [email protected] wrote:

From: Ritvik Gupta <[email protected]>

Define macro ('MAX_BUF_SIZE') for buffer size
instead of hardcoded value '4096', to improve
readability.

---
 tools/testing/selftests/mount/unprivileged-remount-test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/mount/unprivileged-remount-test.c +2 -0
index d2917054fe3a..67a550b7c69b 100644
@@ -45,6 +45,8 @@
 # define MS_STRICTATIME (1 << 24)
 #endif
 
+#define MAX_BUF_SIZE 4096
+
 static void die(char *fmt, ...)
 {
 	va_list ap;

tools/testing/selftests/mount/unprivileged-remount-test.c static void die(char *fmt, ...) · line 61

Quoted 5 lines
tools/testing/selftests/mount/unprivileged-remount-test.c +1 -1
@@ -56,7 +58,7 @@ static void die(char *fmt, ...)
 
 static void vmaybe_write_file(bool enoent_ok, char *filename, char *fmt, va_list ap)
 {
-	char buf[4096];
+	char buf[MAX_BUF_SIZE];

As this is only used once, why is a #define really needed at all? Only do that if it makes sense (i.e. is checked in different places.)

thanks,

greg k-h