Skip to content

Commit dd1af0c

Browse files
mhklinuxliuw
authored andcommitted
PCI: hv: Remove unnecessary flex array in struct pci_packet
struct pci_packet contains a "message" field that is a flex array of struct pci_message. struct pci_packet is usually followed by a second struct in a containing struct that is defined locally in individual functions in pci-hyperv.c. As such, the compiler flag -Wflex-array-member-not-at-end (introduced in gcc-14) generates multiple warnings such as: drivers/pci/controller/pci-hyperv.c:3809:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] The Linux kernel intends to introduce this compiler flag in standard builds, so the current code is problematic in generating these warnings. The "message" field is used only to locate the start of the second struct, and not as an array. Because the second struct can be addressed directly, the "message" field is not really necessary. Rather than try to fix its usage to meet the requirements of -Wflex-array-member-not-at-end, just eliminate the field and either directly reference the second struct, or use "pkt + 1" when "pkt" is dynamically allocated. Reported-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Michael Kelley <mhklinux@outlook.com> Link: https://lore.kernel.org/r/20250514044440.48924-1-mhklinux@outlook.com Signed-off-by: Wei Liu <wei.liu@kernel.org> Message-ID: <20250514044440.48924-1-mhklinux@outlook.com>
1 parent cd1769e commit dd1af0c

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

drivers/pci/controller/pci-hyperv.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ struct pci_packet {
310310
void (*completion_func)(void *context, struct pci_response *resp,
311311
int resp_packet_size);
312312
void *compl_ctxt;
313-
314-
struct pci_message message[];
315313
};
316314

317315
/*
@@ -1496,7 +1494,7 @@ static int hv_read_config_block(struct pci_dev *pdev, void *buf,
14961494
memset(&pkt, 0, sizeof(pkt));
14971495
pkt.pkt.completion_func = hv_pci_read_config_compl;
14981496
pkt.pkt.compl_ctxt = &comp_pkt;
1499-
read_blk = (struct pci_read_block *)&pkt.pkt.message;
1497+
read_blk = (struct pci_read_block *)pkt.buf;
15001498
read_blk->message_type.type = PCI_READ_BLOCK;
15011499
read_blk->wslot.slot = devfn_to_wslot(pdev->devfn);
15021500
read_blk->block_id = block_id;
@@ -1576,7 +1574,7 @@ static int hv_write_config_block(struct pci_dev *pdev, void *buf,
15761574
memset(&pkt, 0, sizeof(pkt));
15771575
pkt.pkt.completion_func = hv_pci_write_config_compl;
15781576
pkt.pkt.compl_ctxt = &comp_pkt;
1579-
write_blk = (struct pci_write_block *)&pkt.pkt.message;
1577+
write_blk = (struct pci_write_block *)pkt.buf;
15801578
write_blk->message_type.type = PCI_WRITE_BLOCK;
15811579
write_blk->wslot.slot = devfn_to_wslot(pdev->devfn);
15821580
write_blk->block_id = block_id;
@@ -1657,7 +1655,7 @@ static void hv_int_desc_free(struct hv_pci_dev *hpdev,
16571655
return;
16581656
}
16591657
memset(&ctxt, 0, sizeof(ctxt));
1660-
int_pkt = (struct pci_delete_interrupt *)&ctxt.pkt.message;
1658+
int_pkt = (struct pci_delete_interrupt *)ctxt.buffer;
16611659
int_pkt->message_type.type =
16621660
PCI_DELETE_INTERRUPT_MESSAGE;
16631661
int_pkt->wslot.slot = hpdev->desc.win_slot.slot;
@@ -2540,7 +2538,7 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus,
25402538
comp_pkt.hpdev = hpdev;
25412539
pkt.init_packet.compl_ctxt = &comp_pkt;
25422540
pkt.init_packet.completion_func = q_resource_requirements;
2543-
res_req = (struct pci_child_message *)&pkt.init_packet.message;
2541+
res_req = (struct pci_child_message *)pkt.buffer;
25442542
res_req->message_type.type = PCI_QUERY_RESOURCE_REQUIREMENTS;
25452543
res_req->wslot.slot = desc->win_slot.slot;
25462544

@@ -2918,7 +2916,7 @@ static void hv_eject_device_work(struct work_struct *work)
29182916
pci_destroy_slot(hpdev->pci_slot);
29192917

29202918
memset(&ctxt, 0, sizeof(ctxt));
2921-
ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message;
2919+
ejct_pkt = (struct pci_eject_response *)ctxt.buffer;
29222920
ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE;
29232921
ejct_pkt->wslot.slot = hpdev->desc.win_slot.slot;
29242922
vmbus_sendpacket(hbus->hdev->channel, ejct_pkt,
@@ -3176,7 +3174,7 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev,
31763174
init_completion(&comp_pkt.host_event);
31773175
pkt->completion_func = hv_pci_generic_compl;
31783176
pkt->compl_ctxt = &comp_pkt;
3179-
version_req = (struct pci_version_request *)&pkt->message;
3177+
version_req = (struct pci_version_request *)(pkt + 1);
31803178
version_req->message_type.type = PCI_QUERY_PROTOCOL_VERSION;
31813179

31823180
for (i = 0; i < num_version; i++) {
@@ -3398,7 +3396,7 @@ static int hv_pci_enter_d0(struct hv_device *hdev)
33983396
init_completion(&comp_pkt.host_event);
33993397
pkt->completion_func = hv_pci_generic_compl;
34003398
pkt->compl_ctxt = &comp_pkt;
3401-
d0_entry = (struct pci_bus_d0_entry *)&pkt->message;
3399+
d0_entry = (struct pci_bus_d0_entry *)(pkt + 1);
34023400
d0_entry->message_type.type = PCI_BUS_D0ENTRY;
34033401
d0_entry->mmio_base = hbus->mem_config->start;
34043402

@@ -3556,20 +3554,20 @@ static int hv_send_resources_allocated(struct hv_device *hdev)
35563554

35573555
if (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) {
35583556
res_assigned =
3559-
(struct pci_resources_assigned *)&pkt->message;
3557+
(struct pci_resources_assigned *)(pkt + 1);
35603558
res_assigned->message_type.type =
35613559
PCI_RESOURCES_ASSIGNED;
35623560
res_assigned->wslot.slot = hpdev->desc.win_slot.slot;
35633561
} else {
35643562
res_assigned2 =
3565-
(struct pci_resources_assigned2 *)&pkt->message;
3563+
(struct pci_resources_assigned2 *)(pkt + 1);
35663564
res_assigned2->message_type.type =
35673565
PCI_RESOURCES_ASSIGNED2;
35683566
res_assigned2->wslot.slot = hpdev->desc.win_slot.slot;
35693567
}
35703568
put_pcichild(hpdev);
35713569

3572-
ret = vmbus_sendpacket(hdev->channel, &pkt->message,
3570+
ret = vmbus_sendpacket(hdev->channel, pkt + 1,
35733571
size_res, (unsigned long)pkt,
35743572
VM_PKT_DATA_INBAND,
35753573
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -3867,6 +3865,7 @@ static int hv_pci_bus_exit(struct hv_device *hdev, bool keep_devs)
38673865
struct pci_packet teardown_packet;
38683866
u8 buffer[sizeof(struct pci_message)];
38693867
} pkt;
3868+
struct pci_message *msg;
38703869
struct hv_pci_compl comp_pkt;
38713870
struct hv_pci_dev *hpdev, *tmp;
38723871
unsigned long flags;
@@ -3912,10 +3911,10 @@ static int hv_pci_bus_exit(struct hv_device *hdev, bool keep_devs)
39123911
init_completion(&comp_pkt.host_event);
39133912
pkt.teardown_packet.completion_func = hv_pci_generic_compl;
39143913
pkt.teardown_packet.compl_ctxt = &comp_pkt;
3915-
pkt.teardown_packet.message[0].type = PCI_BUS_D0EXIT;
3914+
msg = (struct pci_message *)pkt.buffer;
3915+
msg->type = PCI_BUS_D0EXIT;
39163916

3917-
ret = vmbus_sendpacket_getid(chan, &pkt.teardown_packet.message,
3918-
sizeof(struct pci_message),
3917+
ret = vmbus_sendpacket_getid(chan, msg, sizeof(*msg),
39193918
(unsigned long)&pkt.teardown_packet,
39203919
&trans_id, VM_PKT_DATA_INBAND,
39213920
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);

0 commit comments

Comments
 (0)