Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: wwan: mhi_wwan_mbim: Avoid -Wflex-array-member-not-at-end warning

Use DEFINE_RAW_FLEX() to avoid a -Wflex-array-member-not-at-end warning.

Remove fixed-size array struct usb_cdc_ncm_dpe16 dpe16[2]; from struct
mbim_tx_hdr, so that flex-array member struct mbim_tx_hdr::ndp16.dpe16[]
ends last in this structure.

Compensate for this by using the DEFINE_RAW_FLEX() helper to declare the
on-stack struct instance that contains struct usb_cdc_ncm_ndp16 as a
member. Adjust the rest of the code, accordingly.

So, with these changes fix the following warning:

drivers/net/wwan/mhi_wwan_mbim.c:81:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Reviewed-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Gustavo A. R. Silva and committed by
Jakub Kicinski
eeecf5d3 858b1d07

+9 -8
+9 -8
drivers/net/wwan/mhi_wwan_mbim.c
··· 78 78 79 79 struct mbim_tx_hdr { 80 80 struct usb_cdc_ncm_nth16 nth16; 81 + 82 + /* Must be last as it ends in a flexible-array member. */ 81 83 struct usb_cdc_ncm_ndp16 ndp16; 82 - struct usb_cdc_ncm_dpe16 dpe16[2]; 83 84 } __packed; 84 85 85 86 static struct mhi_mbim_link *mhi_mbim_get_link_rcu(struct mhi_mbim_context *mbim, ··· 108 107 static struct sk_buff *mbim_tx_fixup(struct sk_buff *skb, unsigned int session, 109 108 u16 tx_seq) 110 109 { 110 + DEFINE_RAW_FLEX(struct mbim_tx_hdr, mbim_hdr, ndp16.dpe16, 2); 111 111 unsigned int dgram_size = skb->len; 112 112 struct usb_cdc_ncm_nth16 *nth16; 113 113 struct usb_cdc_ncm_ndp16 *ndp16; 114 - struct mbim_tx_hdr *mbim_hdr; 115 114 116 115 /* Only one NDP is sent, containing the IP packet (no aggregation) */ 117 116 118 117 /* Ensure we have enough headroom for crafting MBIM header */ 119 - if (skb_cow_head(skb, sizeof(struct mbim_tx_hdr))) { 118 + if (skb_cow_head(skb, __struct_size(mbim_hdr))) { 120 119 dev_kfree_skb_any(skb); 121 120 return NULL; 122 121 } 123 122 124 - mbim_hdr = skb_push(skb, sizeof(struct mbim_tx_hdr)); 123 + mbim_hdr = skb_push(skb, __struct_size(mbim_hdr)); 125 124 126 125 /* Fill NTB header */ 127 126 nth16 = &mbim_hdr->nth16; ··· 134 133 /* Fill the unique NDP */ 135 134 ndp16 = &mbim_hdr->ndp16; 136 135 ndp16->dwSignature = cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN | (session << 24)); 137 - ndp16->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp16) 138 - + sizeof(struct usb_cdc_ncm_dpe16) * 2); 136 + ndp16->wLength = cpu_to_le16(struct_size(ndp16, dpe16, 2)); 139 137 ndp16->wNextNdpIndex = 0; 140 138 141 139 /* Datagram follows the mbim header */ 142 - ndp16->dpe16[0].wDatagramIndex = cpu_to_le16(sizeof(struct mbim_tx_hdr)); 140 + ndp16->dpe16[0].wDatagramIndex = cpu_to_le16(__struct_size(mbim_hdr)); 143 141 ndp16->dpe16[0].wDatagramLength = cpu_to_le16(dgram_size); 144 142 145 143 /* null termination */ ··· 584 584 { 585 585 ndev->header_ops = NULL; /* No header */ 586 586 ndev->type = ARPHRD_RAWIP; 587 - ndev->needed_headroom = sizeof(struct mbim_tx_hdr); 587 + ndev->needed_headroom = 588 + struct_size_t(struct mbim_tx_hdr, ndp16.dpe16, 2); 588 589 ndev->hard_header_len = 0; 589 590 ndev->addr_len = 0; 590 591 ndev->flags = IFF_POINTOPOINT | IFF_NOARP;