@@ -22,9 +22,6 @@ struct hv_input_dev_info {
2222 unsigned short reserved [11 ];
2323};
2424
25- /* The maximum size of a synthetic input message. */
26- #define SYNTHHID_MAX_INPUT_REPORT_SIZE 16
27-
2825/*
2926 * Current version
3027 *
@@ -59,11 +56,6 @@ struct synthhid_msg_hdr {
5956 u32 size ;
6057};
6158
62- struct synthhid_msg {
63- struct synthhid_msg_hdr header ;
64- char data [1 ]; /* Enclosed message */
65- };
66-
6759union synthhid_version {
6860 struct {
6961 u16 minor_version ;
@@ -99,7 +91,7 @@ struct synthhid_device_info_ack {
9991
10092struct synthhid_input_report {
10193 struct synthhid_msg_hdr header ;
102- char buffer [1 ];
94+ char buffer [];
10395};
10496
10597#pragma pack(pop)
@@ -118,7 +110,7 @@ enum pipe_prot_msg_type {
118110struct pipe_prt_msg {
119111 enum pipe_prot_msg_type type ;
120112 u32 size ;
121- char data [1 ];
113+ char data [];
122114};
123115
124116struct mousevsc_prt_msg {
@@ -232,7 +224,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
232224
233225 ret = vmbus_sendpacket (input_device -> device -> channel ,
234226 & ack ,
235- sizeof (struct pipe_prt_msg ) - sizeof ( unsigned char ) +
227+ sizeof (struct pipe_prt_msg ) +
236228 sizeof (struct synthhid_device_info_ack ),
237229 (unsigned long )& ack ,
238230 VM_PKT_DATA_INBAND ,
@@ -251,7 +243,7 @@ static void mousevsc_on_receive(struct hv_device *device,
251243 struct vmpacket_descriptor * packet )
252244{
253245 struct pipe_prt_msg * pipe_msg ;
254- struct synthhid_msg * hid_msg ;
246+ struct synthhid_msg_hdr * hid_msg_hdr ;
255247 struct mousevsc_dev * input_dev = hv_get_drvdata (device );
256248 struct synthhid_input_report * input_report ;
257249 size_t len ;
@@ -262,25 +254,23 @@ static void mousevsc_on_receive(struct hv_device *device,
262254 if (pipe_msg -> type != PIPE_MESSAGE_DATA )
263255 return ;
264256
265- hid_msg = (struct synthhid_msg * )pipe_msg -> data ;
257+ hid_msg_hdr = (struct synthhid_msg_hdr * )pipe_msg -> data ;
266258
267- switch (hid_msg -> header . type ) {
259+ switch (hid_msg_hdr -> type ) {
268260 case SYNTH_HID_PROTOCOL_RESPONSE :
269261 /*
270262 * While it will be impossible for us to protect against
271263 * malicious/buggy hypervisor/host, add a check here to
272264 * ensure we don't corrupt memory.
273265 */
274- if ((pipe_msg -> size + sizeof (struct pipe_prt_msg )
275- - sizeof (unsigned char ))
266+ if (struct_size (pipe_msg , data , pipe_msg -> size )
276267 > sizeof (struct mousevsc_prt_msg )) {
277268 WARN_ON (1 );
278269 break ;
279270 }
280271
281272 memcpy (& input_dev -> protocol_resp , pipe_msg ,
282- pipe_msg -> size + sizeof (struct pipe_prt_msg ) -
283- sizeof (unsigned char ));
273+ struct_size (pipe_msg , data , pipe_msg -> size ));
284274 complete (& input_dev -> wait_event );
285275 break ;
286276
@@ -311,7 +301,7 @@ static void mousevsc_on_receive(struct hv_device *device,
311301 break ;
312302 default :
313303 pr_err ("unsupported hid msg type - type %d len %d\n" ,
314- hid_msg -> header . type , hid_msg -> header . size );
304+ hid_msg_hdr -> type , hid_msg_hdr -> size );
315305 break ;
316306 }
317307
@@ -359,8 +349,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
359349 request -> request .version_requested .version = SYNTHHID_INPUT_VERSION ;
360350
361351 ret = vmbus_sendpacket (device -> channel , request ,
362- sizeof (struct pipe_prt_msg ) -
363- sizeof (unsigned char ) +
352+ sizeof (struct pipe_prt_msg ) +
364353 sizeof (struct synthhid_protocol_request ),
365354 (unsigned long )request ,
366355 VM_PKT_DATA_INBAND ,
0 commit comments