From patchwork Thu Oct 26 19:09:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 830892 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quantonium-net.20150623.gappssmtp.com header.i=@quantonium-net.20150623.gappssmtp.com header.b="r3S7IhBh"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yNGmW5XK6z9t6C for ; Fri, 27 Oct 2017 06:10:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751970AbdJZTKQ (ORCPT ); Thu, 26 Oct 2017 15:10:16 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:51836 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751908AbdJZTKK (ORCPT ); Thu, 26 Oct 2017 15:10:10 -0400 Received: by mail-pg0-f65.google.com with SMTP id p9so3429854pgc.8 for ; Thu, 26 Oct 2017 12:10:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quantonium-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=M3FXeq2nLYeSn0fU0Ho7wThC1D83EIjbYlgwheu0zTM=; b=r3S7IhBhYO6FPLOIm/ia8GHpUsI8C0TAL3THd6vLPQo2f1HsiwDB2PI3yJEk9Hw7eD vNNUagcCagtIIWGnELqLkDDCXPpWus9QIT3cYw0fqD0w0Dz93wSOntadht9TR7CtUF6X j0RY9sC5DOcChJE5Voc7u2SsY2QF6BsNJs4BrV9JLcZg9eOZGfcHWFwJNixMjOoxCcpQ y1OQrfteRqyT02o2cP5nSyceAucyf6nBTLuTzag9LRN5/h4wZHTWdL99ozJPRctxHgzi rl4mBV4TUfTFYyMkYwZOKD7m7RjPgkLXd3WMcctTL3u+xss3VxIXv1zSrnfQdIHf3DXm cqrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=M3FXeq2nLYeSn0fU0Ho7wThC1D83EIjbYlgwheu0zTM=; b=p6+m9LMfcP+d2D1jAPIQq7Ju1rfSNVzRNbG6tgmxY/FjgkqDzdNtsqazWcL9JcvW0l B8acGnhZQq6qQFgNIuqJRHuEuudkaClglCUL6uKtf61CUwfkUmaKdYrmStZCpTZL2NQH /yEZYuKohx3e8wwURhtoeKoN57n4nP7pYijUXtDd7GNMkGCqs6eLzqrJKrqNHkuuiUTb bbruu2R+96M3l8QOZ8yQzn+95g4RyUvEl0vFPOp4hSnoa3ehcd/1o94a2h6xcRj6Fn6c 9wNVIsxthjtPjM7Zn8Q7fFXd0kLZxL35G81a1pXv7J1mKESIw+e02mgh9QdBG+cK5rsx kPww== X-Gm-Message-State: AMCzsaXwGsiz5qZ/eWRww3ovI2dyPr0DOFEw+qfUGRJPV9HuCbqVv/9e 7ntU5SXIS6l+LuRffSpR53Mi1Q== X-Google-Smtp-Source: ABhQp+S17Npypo61IDcLmXFYtId0cewf5Vb6N0p0/b9qNXs/xch7l0qt4bDmAehq/zLND8TO96jqww== X-Received: by 10.99.119.79 with SMTP id s76mr5755824pgc.3.1509045010184; Thu, 26 Oct 2017 12:10:10 -0700 (PDT) Received: from localhost.localdomain (67-207-98-108.static.wiline.com. [67.207.98.108]) by smtp.gmail.com with ESMTPSA id j1sm11071502pfc.169.2017.10.26.12.10.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Oct 2017 12:10:09 -0700 (PDT) From: Tom Herbert To: davem@davemloft.net Cc: pablo@netfilter.org, laforge@gnumonks.org, aschultz@tpip.net, netdev@vger.kernel.org, rohit@quantonium.net, Tom Herbert Subject: [PATCH v6 net-next 06/12] gtp: Use goto for exceptions in gtp_udp_encap_recv funcs Date: Thu, 26 Oct 2017 12:09:23 -0700 Message-Id: <20171026190929.11619-7-tom@quantonium.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171026190929.11619-1-tom@quantonium.net> References: <20171026190929.11619-1-tom@quantonium.net> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Consolidate return logic to make it easier to extend. Signed-off-by: Tom Herbert --- drivers/net/gtp.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index f2aac5d01143..00e5ea5cb935 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -234,23 +234,27 @@ static int gtp0_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) struct pdp_ctx *pctx; if (!pskb_may_pull(skb, hdrlen)) - return -1; + goto drop; gtp0 = (struct gtp0_header *)(skb->data + sizeof(struct udphdr)); if ((gtp0->flags >> 5) != GTP_V0) - return 1; + goto pass; if (gtp0->type != GTP_TPDU) - return 1; + goto pass; pctx = gtp0_pdp_find(gtp, be64_to_cpu(gtp0->tid)); if (!pctx) { netdev_dbg(gtp->dev, "No PDP ctx to decap skb=%p\n", skb); - return 1; + goto pass; } return gtp_rx(pctx, skb, hdrlen, gtp->role); +drop: + return -1; +pass: + return 1; } static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) @@ -261,15 +265,15 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) struct pdp_ctx *pctx; if (!pskb_may_pull(skb, hdrlen)) - return -1; + goto drop; gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr)); if ((gtp1->flags >> 5) != GTP_V1) - return 1; + goto pass; if (gtp1->type != GTP_TPDU) - return 1; + goto pass; /* From 29.060: "This field shall be present if and only if any one or * more of the S, PN and E flags are set.". @@ -282,17 +286,21 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) /* Make sure the header is larger enough, including extensions. */ if (!pskb_may_pull(skb, hdrlen)) - return -1; + goto drop; gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr)); pctx = gtp1_pdp_find(gtp, ntohl(gtp1->tid)); if (!pctx) { netdev_dbg(gtp->dev, "No PDP ctx to decap skb=%p\n", skb); - return 1; + goto drop; } return gtp_rx(pctx, skb, hdrlen, gtp->role); +drop: + return -1; +pass: + return 1; } static void gtp_encap_destroy(struct sock *sk)