Skip to content

Commit 542f25a

Browse files
PauloMigAlmeidaJiri Kosina
authored andcommitted
HID: hyperv: Replace one-element array with flexible-array member
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in structs synthhid_msg, synthhid_input_report, pipe_prt_msg and refactor the rest of the code accordingly. This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1]. Link: KSPP#79 Link: KSPP#210 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1] Signed-off-by: Paulo Miguel Almeida <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 79d11de commit 542f25a

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

drivers/hid/hid-hyperv.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct synthhid_msg_hdr {
6161

6262
struct synthhid_msg {
6363
struct synthhid_msg_hdr header;
64-
char data[1]; /* Enclosed message */
64+
char data[]; /* Enclosed message */
6565
};
6666

6767
union synthhid_version {
@@ -99,7 +99,7 @@ struct synthhid_device_info_ack {
9999

100100
struct synthhid_input_report {
101101
struct synthhid_msg_hdr header;
102-
char buffer[1];
102+
char buffer[];
103103
};
104104

105105
#pragma pack(pop)
@@ -118,7 +118,7 @@ enum pipe_prot_msg_type {
118118
struct pipe_prt_msg {
119119
enum pipe_prot_msg_type type;
120120
u32 size;
121-
char data[1];
121+
char data[];
122122
};
123123

124124
struct mousevsc_prt_msg {
@@ -232,7 +232,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
232232

233233
ret = vmbus_sendpacket(input_device->device->channel,
234234
&ack,
235-
sizeof(struct pipe_prt_msg) - sizeof(unsigned char) +
235+
sizeof(struct pipe_prt_msg) +
236236
sizeof(struct synthhid_device_info_ack),
237237
(unsigned long)&ack,
238238
VM_PKT_DATA_INBAND,
@@ -271,16 +271,14 @@ static void mousevsc_on_receive(struct hv_device *device,
271271
* malicious/buggy hypervisor/host, add a check here to
272272
* ensure we don't corrupt memory.
273273
*/
274-
if ((pipe_msg->size + sizeof(struct pipe_prt_msg)
275-
- sizeof(unsigned char))
274+
if (struct_size(pipe_msg, data, pipe_msg->size)
276275
> sizeof(struct mousevsc_prt_msg)) {
277276
WARN_ON(1);
278277
break;
279278
}
280279

281280
memcpy(&input_dev->protocol_resp, pipe_msg,
282-
pipe_msg->size + sizeof(struct pipe_prt_msg) -
283-
sizeof(unsigned char));
281+
struct_size(pipe_msg, data, pipe_msg->size));
284282
complete(&input_dev->wait_event);
285283
break;
286284

@@ -359,8 +357,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
359357
request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
360358

361359
ret = vmbus_sendpacket(device->channel, request,
362-
sizeof(struct pipe_prt_msg) -
363-
sizeof(unsigned char) +
360+
sizeof(struct pipe_prt_msg) +
364361
sizeof(struct synthhid_protocol_request),
365362
(unsigned long)request,
366363
VM_PKT_DATA_INBAND,

0 commit comments

Comments
 (0)