From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2 v2 9/9] tunnel: Return constant string without copying it Date: Thu, 18 Jan 2018 16:04:36 +0200 Message-ID: <1516284276-10942-10-git-send-email-serhe.popovych@gmail.com> References: <1516284276-10942-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f66.google.com ([209.85.215.66]:34332 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932337AbeAROFs (ORCPT ); Thu, 18 Jan 2018 09:05:48 -0500 Received: by mail-lf0-f66.google.com with SMTP id k19so6565172lfj.1 for ; Thu, 18 Jan 2018 06:05:47 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id r21sm1344748lja.8.2018.01.18.06.05.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 06:05:46 -0800 (PST) In-Reply-To: <1516284276-10942-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 --- 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