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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1410513954-28909-2-git-send-email-linux@rasmusvillemoes.dk>
Date:	Fri, 12 Sep 2014 11:25:49 +0200
From:	Rasmus Villemoes <linux@...musvillemoes.dk>
To:	Julia Lawall <Julia.Lawall@...6.fr>,
	Steven Rostedt <rostedt@...dmis.org>,
	Ingo Molnar <mingo@...hat.com>
Cc:	linux-kernel@...r.kernel.org,
	Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: [PATCH 1/6] Coccinelle: Semantic patch for replacing puts with putc

Using seq_puts to write a one-character string is suboptimal,
since puts has to call strlen(). Replace those instances with
putc. This also tends to give a tiny code size reduction at the
call site.

seq_put[sc] return -1 on error, 0 on success.
trace_seq_put[sc] return how much was written, which is either 0 or 1.

In both cases, _putc is a drop-in replacement for _puts when the
argument is a one-character string.

Signed-off-by: Rasmus Villemoes <linux@...musvillemoes.dk>
---
 scripts/coccinelle/api/seq_putsc.cocci | 61 ++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 scripts/coccinelle/api/seq_putsc.cocci

diff --git a/scripts/coccinelle/api/seq_putsc.cocci b/scripts/coccinelle/api/seq_putsc.cocci
new file mode 100644
index 0000000..bb11097
--- /dev/null
+++ b/scripts/coccinelle/api/seq_putsc.cocci
@@ -0,0 +1,61 @@
+/// Using seq_puts to write a one-character string is suboptimal,
+/// since puts has to call strlen(). Replace those instances with
+/// putc. This also tends to give a tiny code size reduction at the
+/// call site.
+///
+/// seq_put[sc] return -1 on error, 0 on success.
+/// trace_seq_put[sc] return how much was written, which is either 0 or 1.
+///
+/// In both cases, _putc is a drop-in replacement for _puts when the
+/// argument is a one-character string.
+///
+//
+// Confidence: High
+// Options: --no-includes --include-headers
+//
+// Since the changes to any given line should consist of changing an s
+// to a c and two " to ', the generated patches should be easy to
+// proofread.
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@...c1 depends on patch@
+position p;
+expression s;
+constant c;
+@@
+  \(trace_seq_puts@p\|seq_puts@p\)(s, c)
+
+// Use python to check whether the string constant consists of a
+// single character, and if so, create an "identifier" containing that
+// single character as a C literal.
+@...ipt:python putc2@
+s << putc1.s;
+c << putc1.c;
+ch;
+@@
+import re
+import sys
+
+m = re.match("^\"(.|\\\\.)\"$", c)
+if not m:
+    cocci.include_match(False)
+else:
+    coccinelle.ch = "'" + m.group(1) + "'"
+
+@...c3 depends on patch@
+position putc1.p;
+expression putc1.s;
+constant putc1.c;
+identifier putc2.ch;
+@@
+(
+- seq_puts@p(s, c)
++ seq_putc(s, ch)
+|
+- trace_seq_puts@p(s, c)
++ trace_seq_putc(s, ch)
+)
-- 
2.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ