lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 11 Aug 2016 12:14:30 -0700
From:	Joe Perches <joe@...ches.com>
To:	Andrew Morton <akpm@...ux-foundation.org>,
	Alexander Viro <viro@...iv.linux.org.uk>
Cc:	Alexey Dobriyan <adobriyan@...il.com>,
	Andi Kleen <andi@...stfloor.org>,
	linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [RFC PATCH] seq_puts: Optimize seq_puts for compile-time known constant string lengths

Use a macro to call seq_write for constant strings and seq_puts for
possible variable length char * uses.

Parenthesize seq_puts to avoid recursive macro expansions.

Code size is slightly larger per call, but a runtime calculation
of strlen(string) is avoided.

Signed-off-by: Joe Perches <joe@...ches.com>
---
 fs/seq_file.c            |  2 +-
 include/linux/seq_file.h | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 19f532e..3e50e1f 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -661,7 +661,7 @@ void seq_putc(struct seq_file *m, char c)
 }
 EXPORT_SYMBOL(seq_putc);
 
-void seq_puts(struct seq_file *m, const char *s)
+void (seq_puts)(struct seq_file *m, const char *s)
 {
 	int len = strlen(s);
 
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index f3d45dd..672f4c0 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -116,7 +116,18 @@ void seq_vprintf(struct seq_file *m, const char *fmt, va_list args);
 __printf(2, 3)
 void seq_printf(struct seq_file *m, const char *fmt, ...);
 void seq_putc(struct seq_file *m, char c);
-void seq_puts(struct seq_file *m, const char *s);
+
+void (seq_puts)(struct seq_file *m, const char *s);
+/* Hack to allow constant strings to use compile-time calculated lengths */
+# define seq_puts(seq, string)						\
+do {									\
+	if (__builtin_constant_p(string) &&				\
+	    (sizeof(string) != sizeof(const char *)))			\
+		seq_write(seq, string, sizeof(string) - 1);		\
+	else								\
+		(seq_puts)(seq, string);				\
+} while (0)
+
 void seq_put_decimal_ull(struct seq_file *m, char delimiter,
 			 unsigned long long num);
 void seq_put_decimal_ll(struct seq_file *m, char delimiter, long long num);
-- 
2.8.0.rc4.16.g56331f8

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ