Skip to contentSkip to conversation

net: lwip: ensure alignment of packet buffers

PATCH In review Tim Harvey 2 participants 3 messages Sep 29, 2025 – Sep 30, 2025 Networking

lore
Share & tools
lore

Tim Harvey

author
#0 lore raw

PATCH 1/1 net: lwip: ensure alignment of packet buffers

Network packet buffers should be aligned to PKTALIGN. Add a compiler attribute to ensure this.

---
 net/lwip/net-lwip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/lwip/net-lwip.c +1 -1
index 660ceb10cbe..aec05d55de6 100644
@@ -30,7 +30,7 @@ void (*push_packet)(void *, int len) = 0;
 static int net_try_count;
 static int net_restarted;
 int net_restart_wrap;
-static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN];
+static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN] __attribute__((aligned(PKTALIGN)));
 uchar *net_rx_packets[PKTBUFSRX];
 uchar *net_rx_packet;
 const u8 net_bcast_ethaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Signature · 1 line
2.34.1
#1 lore raw

Hi Tim,

Quoted 13 lines · Tim Harvey

Network packet buffers should be aligned to PKTALIGN. Add a compiler attribute to ensure this.

---
 net/lwip/net-lwip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/lwip/net-lwip.c +0 -0
index 660ceb10cbe..aec05d55de6 100644

net/lwip/net-lwip.c void (*push_packet)(void *, int len) = 0; · line 36

Quoted 8 lines
net/lwip/net-lwip.c +1 -1
@@ -30,7 +30,7 @@ void (*push_packet)(void *, int len) = 0;
 static int net_try_count;
 static int net_restarted;
 int net_restart_wrap;
-static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN];
+static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN] __attribute__((aligned(PKTALIGN)));
 uchar *net_rx_packets[PKTBUFSRX];
 uchar *net_rx_packet;
 const u8 net_bcast_ethaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

I'd rather use the __aligned(x) macro from <linux/compiler_attributes.h>. No need to resend, I will update the patch locally before sending my next pull request for the net subsystem.

Thanks,

Signature · 1 line
Jerome
author
#2 lore raw
Quoted 21 lines · Jerome Forissier

Hi Tim,

Quoted 17 lines · Tim Harvey

Network packet buffers should be aligned to PKTALIGN. Add a compiler attribute to ensure this.

---
 net/lwip/net-lwip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/lwip/net-lwip.c +0 -1
index 660ceb10cbe..aec05d55de6 100644
@@ -30,7 +30,7 @@ void (*push_packet)(void *, int len) = 0;
 static int net_try_count;
 static int net_restarted;
 int net_restart_wrap;
-static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN];
Quoted 9 lines

net/lwip/net-lwip.c void (*push_packet)(void *, int len) = 0; · line 36

Quoted 4 lines
net/lwip/net-lwip.c +1 -0
+static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN] __attribute__((aligned(PKTALIGN)));
 uchar *net_rx_packets[PKTBUFSRX];
 uchar *net_rx_packet;
 const u8 net_bcast_ethaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

I'd rather use the __aligned(x) macro from <linux/compiler_attributes.h>. No need to resend, I will update the patch locally before sending my next pull request for the net subsystem.

Hi Jerome,

I'll make note of that - thanks for taking care of it.

Best Regards,

Tim