Skip to content

Commit 4d63763

Browse files
vittyvkgregkh
authored andcommitted
Drivers: hv: get rid of redundant messagecount in create_gpadl_header()
We use messagecount only once in vmbus_establish_gpadl() to check if it is safe to iterate through the submsglist. We can just initialize the list header in all cases in create_gpadl_header() instead. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a9f61ca commit 4d63763

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

drivers/hv/channel.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ EXPORT_SYMBOL_GPL(vmbus_send_tl_connect_request);
238238
* create_gpadl_header - Creates a gpadl for the specified buffer
239239
*/
240240
static int create_gpadl_header(void *kbuffer, u32 size,
241-
struct vmbus_channel_msginfo **msginfo,
242-
u32 *messagecount)
241+
struct vmbus_channel_msginfo **msginfo)
243242
{
244243
int i;
245244
int pagecount;
@@ -283,7 +282,6 @@ static int create_gpadl_header(void *kbuffer, u32 size,
283282
gpadl_header->range[0].pfn_array[i] = slow_virt_to_phys(
284283
kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT;
285284
*msginfo = msgheader;
286-
*messagecount = 1;
287285

288286
pfnsum = pfncount;
289287
pfnleft = pagecount - pfncount;
@@ -323,7 +321,6 @@ static int create_gpadl_header(void *kbuffer, u32 size,
323321
}
324322

325323
msgbody->msgsize = msgsize;
326-
(*messagecount)++;
327324
gpadl_body =
328325
(struct vmbus_channel_gpadl_body *)msgbody->msg;
329326

@@ -352,6 +349,8 @@ static int create_gpadl_header(void *kbuffer, u32 size,
352349
msgheader = kzalloc(msgsize, GFP_KERNEL);
353350
if (msgheader == NULL)
354351
goto nomem;
352+
353+
INIT_LIST_HEAD(&msgheader->submsglist);
355354
msgheader->msgsize = msgsize;
356355

357356
gpadl_header = (struct vmbus_channel_gpadl_header *)
@@ -366,7 +365,6 @@ static int create_gpadl_header(void *kbuffer, u32 size,
366365
kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT;
367366

368367
*msginfo = msgheader;
369-
*messagecount = 1;
370368
}
371369

372370
return 0;
@@ -391,7 +389,6 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
391389
struct vmbus_channel_gpadl_body *gpadl_body;
392390
struct vmbus_channel_msginfo *msginfo = NULL;
393391
struct vmbus_channel_msginfo *submsginfo;
394-
u32 msgcount;
395392
struct list_head *curr;
396393
u32 next_gpadl_handle;
397394
unsigned long flags;
@@ -400,7 +397,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
400397
next_gpadl_handle =
401398
(atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1);
402399

403-
ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
400+
ret = create_gpadl_header(kbuffer, size, &msginfo);
404401
if (ret)
405402
return ret;
406403

@@ -423,24 +420,21 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
423420
if (ret != 0)
424421
goto cleanup;
425422

426-
if (msgcount > 1) {
427-
list_for_each(curr, &msginfo->submsglist) {
423+
list_for_each(curr, &msginfo->submsglist) {
424+
submsginfo = (struct vmbus_channel_msginfo *)curr;
425+
gpadl_body =
426+
(struct vmbus_channel_gpadl_body *)submsginfo->msg;
428427

429-
submsginfo = (struct vmbus_channel_msginfo *)curr;
430-
gpadl_body =
431-
(struct vmbus_channel_gpadl_body *)submsginfo->msg;
428+
gpadl_body->header.msgtype =
429+
CHANNELMSG_GPADL_BODY;
430+
gpadl_body->gpadl = next_gpadl_handle;
432431

433-
gpadl_body->header.msgtype =
434-
CHANNELMSG_GPADL_BODY;
435-
gpadl_body->gpadl = next_gpadl_handle;
432+
ret = vmbus_post_msg(gpadl_body,
433+
submsginfo->msgsize -
434+
sizeof(*submsginfo));
435+
if (ret != 0)
436+
goto cleanup;
436437

437-
ret = vmbus_post_msg(gpadl_body,
438-
submsginfo->msgsize -
439-
sizeof(*submsginfo));
440-
if (ret != 0)
441-
goto cleanup;
442-
443-
}
444438
}
445439
wait_for_completion(&msginfo->waitevent);
446440

0 commit comments

Comments
 (0)