Re: [PATCH 02/10] fs: tftp: use net_eth_to_udp() for packet parsing

Ahmad Fatoum
2026-04-17T10:06:17Z

On 4/2/26 8:36 AM, Sascha Hauer wrote:
> Replace the separate net_eth_to_udp_payload(), net_eth_to_udphdr() and
> net_eth_to_udplen() calls with the new consolidated net_eth_to_udp()
> helper. This validates the packet length before accessing any headers
> and removes the need to cast away the unused len parameter.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
> fs/tftp.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/fs/tftp.c b/fs/tftp.c
> index a454306b4b..fe6f42b073 100644
> --- a/fs/tftp.c
> +++ b/fs/tftp.c
> @@ -628,11 +628,12 @@ static void tftp_recv(struct file_priv *priv,
> static void tftp_handler(void *ctx, char *packet, unsigned len)
> {
> struct file_priv *priv = ctx;
> - char *pkt = net_eth_to_udp_payload(packet);
> - struct udphdr *udp = net_eth_to_udphdr(packet);
> + struct net_udp_pkt udp;
>
> - (void)len;
> - tftp_recv(priv, pkt, net_eth_to_udplen(packet), udp->uh_sport);
> + if (net_eth_to_udp(packet, len, &udp))
> + return;
> +
> + tftp_recv(priv, udp.payload, udp.len, udp.udp->uh_sport);
> }
>
> static int tftp_start_transfer(struct file_priv *priv)
>

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |