mirror of
https://xff.cz/git/u-boot/
synced 2025-09-03 17:52:07 +02:00
net: avoid address-of-packed-member error
sandbox_defconfig does not compile using GCC 9.2.1: net/net.c: In function ‘net_process_received_packet’: net/net.c:1288:23: error: taking address of packed member of ‘struct ip_udp_hdr’ may result in an unaligned pointer value [-Werror=address-of-packed-member] 1288 | sumptr = (ushort *)&(ip->udp_src); | ^~~~~~~~~~~~~~ Avoid the error by using a u8 pointer instead of an u16 pointer and in-lining ntohs(). Simplify the checksumming of the last message byte. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
committed by
Joe Hershberger
parent
1f60789602
commit
8524423da9
20
net/net.c
20
net/net.c
@@ -1271,7 +1271,7 @@ void net_process_received_packet(uchar *in_packet, int len)
|
|||||||
#ifdef CONFIG_UDP_CHECKSUM
|
#ifdef CONFIG_UDP_CHECKSUM
|
||||||
if (ip->udp_xsum != 0) {
|
if (ip->udp_xsum != 0) {
|
||||||
ulong xsum;
|
ulong xsum;
|
||||||
ushort *sumptr;
|
u8 *sumptr;
|
||||||
ushort sumlen;
|
ushort sumlen;
|
||||||
|
|
||||||
xsum = ip->ip_p;
|
xsum = ip->ip_p;
|
||||||
@@ -1282,22 +1282,16 @@ void net_process_received_packet(uchar *in_packet, int len)
|
|||||||
xsum += (ntohl(ip->ip_dst.s_addr) >> 0) & 0x0000ffff;
|
xsum += (ntohl(ip->ip_dst.s_addr) >> 0) & 0x0000ffff;
|
||||||
|
|
||||||
sumlen = ntohs(ip->udp_len);
|
sumlen = ntohs(ip->udp_len);
|
||||||
sumptr = (ushort *)&(ip->udp_src);
|
sumptr = (u8 *)&ip->udp_src;
|
||||||
|
|
||||||
while (sumlen > 1) {
|
while (sumlen > 1) {
|
||||||
ushort sumdata;
|
/* inlined ntohs() to avoid alignment errors */
|
||||||
|
xsum += (sumptr[0] << 8) + sumptr[1];
|
||||||
sumdata = *sumptr++;
|
sumptr += 2;
|
||||||
xsum += ntohs(sumdata);
|
|
||||||
sumlen -= 2;
|
sumlen -= 2;
|
||||||
}
|
}
|
||||||
if (sumlen > 0) {
|
if (sumlen > 0)
|
||||||
ushort sumdata;
|
xsum += (sumptr[0] << 8) + sumptr[0];
|
||||||
|
|
||||||
sumdata = *(unsigned char *)sumptr;
|
|
||||||
sumdata = (sumdata << 8) & 0xff00;
|
|
||||||
xsum += sumdata;
|
|
||||||
}
|
|
||||||
while ((xsum >> 16) != 0) {
|
while ((xsum >> 16) != 0) {
|
||||||
xsum = (xsum & 0x0000ffff) +
|
xsum = (xsum & 0x0000ffff) +
|
||||||
((xsum >> 16) & 0x0000ffff);
|
((xsum >> 16) & 0x0000ffff);
|
||||||
|
Reference in New Issue
Block a user