Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3521203pxf; Mon, 15 Mar 2021 11:24:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz9bZkXsYJ08I+6n++YALNt1Y9a+StjiPwzUQ2jLfEQVoi6uogKqqOPU2xIKbj5/27ZCSn X-Received: by 2002:a17:907:2bd7:: with SMTP id gv23mr25426565ejc.351.1615832648164; Mon, 15 Mar 2021 11:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832648; cv=none; d=google.com; s=arc-20160816; b=yq72EqzPa1fcp2VRKAn2i9Ja1UO4ZBEBVrVRP2eiqUMHVnUwHk93T/p6zqlCcB/dPA KJSp6hXw1il2+tmjWGOxOFWvpEZWLy75eH08KHbLwIlSpcpO68AQfo7NvQTlB4MpxDRi ls6uHhxhebgBjncQ9dfC08uRAozUfcaH/NanqZsA2bV1djwkfnHDNj96t79wtVsJicje hG5958BCdDsfHkmtjXeVAowHoGqFCG+ao3sTuEKcrILAnXCvk+SwLsrdvude4gcOtt1a v9h78E2EFQduhKbkl7ObhkZclWsF4LmB5u9wubZJzUsdqXmByOf6QI2FDrZRi4jFXBo2 CR6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wHac4CWiK2gQjLmYXrmZVSHnEqLBIdy7ltnx45AOomI=; b=ZzIBErfxW8ie4tmix55ppWiDGMOZ6eRjlEgV3ZPLhbHKyEZfBPGuj1BhCTvzzEulHw LEeixn9op/SG4D1xdavvxsDJTr5drBr2G4hCGisJ/ssz8JhHLve/j2gtuf6oP6WHhzhS w4jW0rlQ6xw5USzGVDc24qDU+fPqmvVFRQYmxmxAbeC+mmWegAv7GRkX6T2Bcol5m9QP zKOfX456T0HCDr0WTRmm5UD+DObTGAVBpuSVOrGmPrcgCAV+wfnwhj9wBLaJZ3IMJYzx YX4AFlVz6N2qdaMLsKcRxWDhBaB+rgIG9A2Y9ohrINwhVYxLt5NG9sc8fDmuMUIi0LU/ OlVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="0de/qqLB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si12464339eju.321.2021.03.15.11.23.40; Mon, 15 Mar 2021 11:24:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="0de/qqLB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238561AbhCOOX2 (ORCPT + 99 others); Mon, 15 Mar 2021 10:23:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:37836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232879AbhCOOAE (ORCPT ); Mon, 15 Mar 2021 10:00:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 696FE64F3E; Mon, 15 Mar 2021 13:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816786; bh=hH5nnsUVrEKtD1IqMe8o0CVhKYO92yLCreFclILE9lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0de/qqLBvnc9YvMkM+wSBQTe2rJvh+QpAJ5h+0PAuHj9jMcOMYUdjOe167oM7WjAh 0bZXrAXim/P/1hnai+x5D9/xZcE3m00/r000YiH3xA/gUOAtRz2uvI05yFW7gSeJpB IUaDVHL4pBDfCQYcWRysxLm1grIy6SRGQuaGhXoU= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Eggers , Vladimir Oltean , Florian Fainelli , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 114/290] net: dsa: tag_ksz: dont allocate additional memory for padding/tagging Date: Mon, 15 Mar 2021 14:53:27 +0100 Message-Id: <20210315135545.768141148@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Christian Eggers [ Upstream commit 88fda8eefd9a7a7175bf4dad1d02cc0840581111 ] The caller (dsa_slave_xmit) guarantees that the frame length is at least ETH_ZLEN and that enough memory for tail tagging is available. Signed-off-by: Christian Eggers Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_ksz.c | 73 ++++++----------------------------------------- 1 file changed, 9 insertions(+), 64 deletions(-) diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index 0a5aa982c60d..4820dbcedfa2 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -14,46 +14,6 @@ #define KSZ_EGRESS_TAG_LEN 1 #define KSZ_INGRESS_TAG_LEN 1 -static struct sk_buff *ksz_common_xmit(struct sk_buff *skb, - struct net_device *dev, int len) -{ - struct sk_buff *nskb; - int padlen; - - padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len; - - if (skb_tailroom(skb) >= padlen + len) { - /* Let dsa_slave_xmit() free skb */ - if (__skb_put_padto(skb, skb->len + padlen, false)) - return NULL; - - nskb = skb; - } else { - nskb = alloc_skb(NET_IP_ALIGN + skb->len + - padlen + len, GFP_ATOMIC); - if (!nskb) - return NULL; - skb_reserve(nskb, NET_IP_ALIGN); - - skb_reset_mac_header(nskb); - skb_set_network_header(nskb, - skb_network_header(skb) - skb->head); - skb_set_transport_header(nskb, - skb_transport_header(skb) - skb->head); - skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len)); - - /* Let skb_put_padto() free nskb, and let dsa_slave_xmit() free - * skb - */ - if (skb_put_padto(nskb, nskb->len + padlen)) - return NULL; - - consume_skb(skb); - } - - return nskb; -} - static struct sk_buff *ksz_common_rcv(struct sk_buff *skb, struct net_device *dev, unsigned int port, unsigned int len) @@ -90,23 +50,18 @@ static struct sk_buff *ksz_common_rcv(struct sk_buff *skb, static struct sk_buff *ksz8795_xmit(struct sk_buff *skb, struct net_device *dev) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct sk_buff *nskb; u8 *tag; u8 *addr; - nskb = ksz_common_xmit(skb, dev, KSZ_INGRESS_TAG_LEN); - if (!nskb) - return NULL; - /* Tag encoding */ - tag = skb_put(nskb, KSZ_INGRESS_TAG_LEN); - addr = skb_mac_header(nskb); + tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); + addr = skb_mac_header(skb); *tag = 1 << dp->index; if (is_link_local_ether_addr(addr)) *tag |= KSZ8795_TAIL_TAG_OVERRIDE; - return nskb; + return skb; } static struct sk_buff *ksz8795_rcv(struct sk_buff *skb, struct net_device *dev, @@ -156,18 +111,13 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, struct net_device *dev) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct sk_buff *nskb; __be16 *tag; u8 *addr; u16 val; - nskb = ksz_common_xmit(skb, dev, KSZ9477_INGRESS_TAG_LEN); - if (!nskb) - return NULL; - /* Tag encoding */ - tag = skb_put(nskb, KSZ9477_INGRESS_TAG_LEN); - addr = skb_mac_header(nskb); + tag = skb_put(skb, KSZ9477_INGRESS_TAG_LEN); + addr = skb_mac_header(skb); val = BIT(dp->index); @@ -176,7 +126,7 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, *tag = cpu_to_be16(val); - return nskb; + return skb; } static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev, @@ -213,24 +163,19 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb, struct net_device *dev) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct sk_buff *nskb; u8 *addr; u8 *tag; - nskb = ksz_common_xmit(skb, dev, KSZ_INGRESS_TAG_LEN); - if (!nskb) - return NULL; - /* Tag encoding */ - tag = skb_put(nskb, KSZ_INGRESS_TAG_LEN); - addr = skb_mac_header(nskb); + tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); + addr = skb_mac_header(skb); *tag = BIT(dp->index); if (is_link_local_ether_addr(addr)) *tag |= KSZ9893_TAIL_TAG_OVERRIDE; - return nskb; + return skb; } static const struct dsa_device_ops ksz9893_netdev_ops = { -- 2.30.1