Thread (11 messages) flat view 11 messages, 2 authors, 2018-01-19
STALE3140d

Revision v2 of 2 in this series.

Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH iproute2 v2 9/9] tunnel: Return constant string without copying it

From: Serhey Popovych <hidden>
Date: 2018-01-18 14:05:48
Subsystem: the rest · Maintainer: Linus Torvalds

We return constant string from tnl_strproto(), no need
to copy it to temporary buffer and then return such
buffer as const: return constant string instead.

Signed-off-by: Serhey Popovych <redacted>
---
 ip/tunnel.c |   25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/ip/tunnel.c b/ip/tunnel.c
index 42ae70e..0414804 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -40,33 +40,22 @@
 
 const char *tnl_strproto(__u8 proto)
 {
-	static char buf[16];
-
 	switch (proto) {
 	case IPPROTO_IPIP:
-		strcpy(buf, "ip");
-		break;
+		return "ip";
 	case IPPROTO_GRE:
-		strcpy(buf, "gre");
-		break;
+		return "gre";
 	case IPPROTO_IPV6:
-		strcpy(buf, "ipv6");
-		break;
+		return "ipv6";
 	case IPPROTO_ESP:
-		strcpy(buf, "esp");
-		break;
+		return "esp";
 	case IPPROTO_MPLS:
-		strcpy(buf, "mpls");
-		break;
+		return "mpls";
 	case 0:
-		strcpy(buf, "any");
-		break;
+		return "any";
 	default:
-		strcpy(buf, "unknown");
-		break;
+		return "unknown";
 	}
-
-	return buf;
 }
 
 int tnl_get_ioctl(const char *basedev, void *p)
-- 
1.7.10.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help