From nobody Wed Nov 27 00:22:39 2024 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 172161AF0AE; Tue, 15 Oct 2024 13:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728999444; cv=none; b=J/mI+cb2M9XTw9L6/qVqMoaOBG+0qzuoOEVisOGWtx/+g3tzEja9RiADoAJlO4hxs8xcL8zHF3qHtqVUlqrvZm0JlRmk8z1/8Lqi94gcjXk1st9rTZNS6YKRYHrzQjMOVs/QIxxdKExSIXqK5HtTmak80Xxt9DJazBO7n9Nzuy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728999444; c=relaxed/simple; bh=8SMBbbqWMUC0bk4bj1pzbRGvz1lhMyzwzMh2XDlZFUM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E30gmDACDhMbe+bdq8ZMDND7/qFyhAhbw4/wP5ZUMytUywJaHnQpYCRSiQd8QiuDfhitVFzsFN2tIyGQtPGnYpGEzYpboUqGapmOW9gebDXQfOVzuoEjqPvry+OAL3FW4tFof2BS6K1OYrE2cnGbSZvaVF3qLJ99rrutzxfpX9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.11,205,1725289200"; d="scan'208";a="221998686" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 15 Oct 2024 22:37:15 +0900 Received: from GBR-5CG2373LKG.adwin.renesas.com (unknown [10.226.93.176]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 6B2B8400755A; Tue, 15 Oct 2024 22:37:05 +0900 (JST) From: Paul Barker To: Sergey Shtylyov , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Paul Barker , Geert Uytterhoeven , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Biju Das , Claudiu Beznea , netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v2 04/10] net: ravb: Combine if conditions in RX csum validation Date: Tue, 15 Oct 2024 14:36:28 +0100 Message-Id: <20241015133634.193-5-paul.barker.ct@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241015133634.193-1-paul.barker.ct@bp.renesas.com> References: <20241015133634.193-1-paul.barker.ct@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We can merge the two if conditions on skb_is_nonlinear(). Since skb_frag_size_sub() and skb_trim() do not free memory, it is still safe to access the trimmed bytes at the end of the packet after these calls. Reviewed-by: Sergey Shtylyov Signed-off-by: Paul Barker --- drivers/net/ethernet/renesas/ravb_main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/etherne= t/renesas/ravb_main.c index 4bc2532706c2..2f584c353c78 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -750,7 +750,6 @@ static void ravb_rx_csum_gbeth(struct sk_buff *skb) { struct skb_shared_info *shinfo =3D skb_shinfo(skb); __wsum csum_proto; - skb_frag_t *last_frag; u8 *hw_csum; =20 /* The hardware checksum status is contained in sizeof(__sum16) * 2 =3D 4 @@ -766,21 +765,19 @@ static void ravb_rx_csum_gbeth(struct sk_buff *skb) return; =20 if (skb_is_nonlinear(skb)) { - last_frag =3D &shinfo->frags[shinfo->nr_frags - 1]; + skb_frag_t *last_frag =3D &shinfo->frags[shinfo->nr_frags - 1]; + hw_csum =3D skb_frag_address(last_frag) + skb_frag_size(last_frag); + skb_frag_size_sub(last_frag, 2 * sizeof(__sum16)); } else { hw_csum =3D skb_tail_pointer(skb); + skb_trim(skb, skb->len - 2 * sizeof(__sum16)); } =20 hw_csum -=3D sizeof(__sum16); csum_proto =3D csum_unfold((__force __sum16)get_unaligned_le16(hw_csum)); =20 - if (skb_is_nonlinear(skb)) - skb_frag_size_sub(last_frag, 2 * sizeof(__sum16)); - else - skb_trim(skb, skb->len - 2 * sizeof(__sum16)); - if (!csum_proto) skb->ip_summed =3D CHECKSUM_UNNECESSARY; } --=20 2.43.0