From: Simon Horman <horms@kernel.org>
To: Moon Yeounsu <yyyynoom@gmail.com>
Cc: cooldavid@cooldavid.org, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: ethernet: use ip_hdrlen() instead of bit shift
Date: Fri, 2 Aug 2024 15:15:34 +0100 [thread overview]
Message-ID: <20240802141534.GA2504122@kernel.org> (raw)
In-Reply-To: <20240802054421.5428-1-yyyynoom@gmail.com>
On Fri, Aug 02, 2024 at 02:44:21PM +0900, Moon Yeounsu wrote:
> `ip_hdr(skb)->ihl << 2` are the same as `ip_hdrlen(skb)`
> Therefore, we should use a well-defined function not a bit shift
> to find the header length.
>
> It also compress two lines at a single line.
>
> Signed-off-by: Moon Yeounsu <yyyynoom@gmail.com>
Firstly, I think this clean-up is both correct and safe. Safe because
ip_hdrlen() only relies on ip_hdr(), which is already used in the same code
path. And correct because ip_hdrlen multiplies ihl by 4, which is clearly
equivalent to a left shift of 2 bits.
However, I do wonder about the value of clean-ups for what appears to be a
very old driver, which hasn't received a new feature for quite sometime
And further, I wonder if we should update this driver from "Maintained" to
"Odd Fixes" as the maintainer, "Guo-Fu Tseng" <cooldavid@cooldavid.org>,
doesn't seem to have been seen by lore since early 2020.
https://lore.kernel.org/netdev/20200219034801.M31679@cooldavid.org/
> ---
> drivers/net/ethernet/jme.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/jme.c b/drivers/net/ethernet/jme.c
> index b06e24562973..83b185c995df 100644
> --- a/drivers/net/ethernet/jme.c
> +++ b/drivers/net/ethernet/jme.c
> @@ -946,15 +946,13 @@ jme_udpsum(struct sk_buff *skb)
> if (skb->protocol != htons(ETH_P_IP))
> return csum;
> skb_set_network_header(skb, ETH_HLEN);
> +
> if ((ip_hdr(skb)->protocol != IPPROTO_UDP) ||
> - (skb->len < (ETH_HLEN +
> - (ip_hdr(skb)->ihl << 2) +
> - sizeof(struct udphdr)))) {
> + (skb->len < (ETH_HLEN + (ip_hdrlen(skb)) + sizeof(struct udphdr)))) {
The parentheses around the call to ip_hdrlen are unnecessary.
And this line is now too long: networking codes till prefers
code to be 80 columns wide or less.
> skb_reset_network_header(skb);
> return csum;
> }
> - skb_set_transport_header(skb,
> - ETH_HLEN + (ip_hdr(skb)->ihl << 2));
> + skb_set_transport_header(skb, ETH_HLEN + (ip_hdrlen(skb)));
Unnecessary parentheses here too.
> csum = udp_hdr(skb)->check;
> skb_reset_transport_header(skb);
> skb_reset_network_header(skb);
--
pw-bot: cr
next prev parent reply other threads:[~2024-08-02 14:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 5:44 [PATCH] net: ethernet: use ip_hdrlen() instead of bit shift Moon Yeounsu
2024-08-02 13:35 ` Christophe JAILLET
2024-08-03 1:21 ` Moon Yeounsu
2024-08-02 14:15 ` Simon Horman [this message]
2024-08-02 14:40 ` Simon Horman
2024-08-03 1:47 ` Moon Yeounsu
2024-08-04 10:18 ` Simon Horman
2024-08-05 0:32 ` Guo-Fu Tseng
2024-08-03 2:29 ` [PATCH v2] net: ethernet: remove unnecessary parentheses Moon Yeounsu
2024-08-03 10:22 ` Christophe JAILLET
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240802141534.GA2504122@kernel.org \
--to=horms@kernel.org \
--cc=cooldavid@cooldavid.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=yyyynoom@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.