Skip to content

Commit 2a62644

Browse files
dmantipovkuba-moo
authored andcommitted
net: asix: fix fortify warning
When compiling with gcc version 14.0.0 20231129 (experimental) and CONFIG_FORTIFY_SOURCE=y, I've noticed the following warning: ... In function 'fortify_memcpy_chk', inlined from 'ax88796c_tx_fixup' at drivers/net/ethernet/asix/ax88796c_main.c:287:2: ./include/linux/fortify-string.h:588:25: warning: call to '__read_overflow2_field' declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning] 588 | __read_overflow2_field(q_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... This call to 'memcpy()' is interpreted as an attempt to copy TX_OVERHEAD (which is 8) bytes from 4-byte 'sop' field of 'struct tx_pkt_info' and thus overread warning is issued. Since we actually want to copy both 'sop' and 'seg' fields at once, use the convenient 'struct_group()' here. Signed-off-by: Dmitry Antipov <[email protected]> Acked-by: Łukasz Stelmach <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 609c767 commit 2a62644

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

drivers/net/ethernet/asix/ax88796c_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ ax88796c_tx_fixup(struct net_device *ndev, struct sk_buff_head *q)
284284
ax88796c_proc_tx_hdr(&info, skb->ip_summed);
285285

286286
/* SOP and SEG header */
287-
memcpy(skb_push(skb, TX_OVERHEAD), &info.sop, TX_OVERHEAD);
287+
memcpy(skb_push(skb, TX_OVERHEAD), &info.tx_overhead, TX_OVERHEAD);
288288

289289
/* Write SPI TXQ header */
290290
memcpy(skb_push(skb, spi_len), ax88796c_tx_cmd_buf, spi_len);

drivers/net/ethernet/asix/ax88796c_main.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define AX88796C_PHY_REGDUMP_LEN 14
2626
#define AX88796C_PHY_ID 0x10
2727

28-
#define TX_OVERHEAD 8
28+
#define TX_OVERHEAD sizeof_field(struct tx_pkt_info, tx_overhead)
2929
#define TX_EOP_SIZE 4
3030

3131
#define AX_MCAST_FILTER_SIZE 8
@@ -549,8 +549,10 @@ struct tx_eop_header {
549549
};
550550

551551
struct tx_pkt_info {
552-
struct tx_sop_header sop;
553-
struct tx_segment_header seg;
552+
struct_group(tx_overhead,
553+
struct tx_sop_header sop;
554+
struct tx_segment_header seg;
555+
);
554556
struct tx_eop_header eop;
555557
u16 pkt_len;
556558
u16 seq_num;

0 commit comments

Comments
 (0)