@@ -22,9 +22,6 @@ struct hv_input_dev_info {
22
22
unsigned short reserved [11 ];
23
23
};
24
24
25
- /* The maximum size of a synthetic input message. */
26
- #define SYNTHHID_MAX_INPUT_REPORT_SIZE 16
27
-
28
25
/*
29
26
* Current version
30
27
*
@@ -59,11 +56,6 @@ struct synthhid_msg_hdr {
59
56
u32 size ;
60
57
};
61
58
62
- struct synthhid_msg {
63
- struct synthhid_msg_hdr header ;
64
- char data [1 ]; /* Enclosed message */
65
- };
66
-
67
59
union synthhid_version {
68
60
struct {
69
61
u16 minor_version ;
@@ -99,7 +91,7 @@ struct synthhid_device_info_ack {
99
91
100
92
struct synthhid_input_report {
101
93
struct synthhid_msg_hdr header ;
102
- char buffer [1 ];
94
+ char buffer [];
103
95
};
104
96
105
97
#pragma pack(pop)
@@ -118,7 +110,7 @@ enum pipe_prot_msg_type {
118
110
struct pipe_prt_msg {
119
111
enum pipe_prot_msg_type type ;
120
112
u32 size ;
121
- char data [1 ];
113
+ char data [];
122
114
};
123
115
124
116
struct mousevsc_prt_msg {
@@ -232,7 +224,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
232
224
233
225
ret = vmbus_sendpacket (input_device -> device -> channel ,
234
226
& ack ,
235
- sizeof (struct pipe_prt_msg ) - sizeof ( unsigned char ) +
227
+ sizeof (struct pipe_prt_msg ) +
236
228
sizeof (struct synthhid_device_info_ack ),
237
229
(unsigned long )& ack ,
238
230
VM_PKT_DATA_INBAND ,
@@ -251,7 +243,7 @@ static void mousevsc_on_receive(struct hv_device *device,
251
243
struct vmpacket_descriptor * packet )
252
244
{
253
245
struct pipe_prt_msg * pipe_msg ;
254
- struct synthhid_msg * hid_msg ;
246
+ struct synthhid_msg_hdr * hid_msg_hdr ;
255
247
struct mousevsc_dev * input_dev = hv_get_drvdata (device );
256
248
struct synthhid_input_report * input_report ;
257
249
size_t len ;
@@ -262,25 +254,23 @@ static void mousevsc_on_receive(struct hv_device *device,
262
254
if (pipe_msg -> type != PIPE_MESSAGE_DATA )
263
255
return ;
264
256
265
- hid_msg = (struct synthhid_msg * )pipe_msg -> data ;
257
+ hid_msg_hdr = (struct synthhid_msg_hdr * )pipe_msg -> data ;
266
258
267
- switch (hid_msg -> header . type ) {
259
+ switch (hid_msg_hdr -> type ) {
268
260
case SYNTH_HID_PROTOCOL_RESPONSE :
269
261
/*
270
262
* While it will be impossible for us to protect against
271
263
* malicious/buggy hypervisor/host, add a check here to
272
264
* ensure we don't corrupt memory.
273
265
*/
274
- if ((pipe_msg -> size + sizeof (struct pipe_prt_msg )
275
- - sizeof (unsigned char ))
266
+ if (struct_size (pipe_msg , data , pipe_msg -> size )
276
267
> sizeof (struct mousevsc_prt_msg )) {
277
268
WARN_ON (1 );
278
269
break ;
279
270
}
280
271
281
272
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 ));
284
274
complete (& input_dev -> wait_event );
285
275
break ;
286
276
@@ -311,7 +301,7 @@ static void mousevsc_on_receive(struct hv_device *device,
311
301
break ;
312
302
default :
313
303
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 );
315
305
break ;
316
306
}
317
307
@@ -359,8 +349,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
359
349
request -> request .version_requested .version = SYNTHHID_INPUT_VERSION ;
360
350
361
351
ret = vmbus_sendpacket (device -> channel , request ,
362
- sizeof (struct pipe_prt_msg ) -
363
- sizeof (unsigned char ) +
352
+ sizeof (struct pipe_prt_msg ) +
364
353
sizeof (struct synthhid_protocol_request ),
365
354
(unsigned long )request ,
366
355
VM_PKT_DATA_INBAND ,
0 commit comments