Browse Source

[hyperv] Fix resource leaks on error path

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 years ago
parent
commit
8963193cda
1 changed files with 11 additions and 5 deletions
  1. 11
    5
      src/interface/hyperv/vmbus.c

+ 11
- 5
src/interface/hyperv/vmbus.c View File

448
 	/* Post message */
448
 	/* Post message */
449
 	if ( ( rc = vmbus_post_message ( hv, &open.header,
449
 	if ( ( rc = vmbus_post_message ( hv, &open.header,
450
 					 sizeof ( open ) ) ) != 0 )
450
 					 sizeof ( open ) ) ) != 0 )
451
-		return rc;
451
+		goto err_post_message;
452
 
452
 
453
 	/* Wait for response */
453
 	/* Wait for response */
454
 	if ( ( rc = vmbus_wait_for_message ( hv,
454
 	if ( ( rc = vmbus_wait_for_message ( hv,
455
 					     VMBUS_OPEN_CHANNEL_RESULT ) ) != 0)
455
 					     VMBUS_OPEN_CHANNEL_RESULT ) ) != 0)
456
-		return rc;
456
+		goto err_wait_for_message;
457
 
457
 
458
 	/* Check response */
458
 	/* Check response */
459
 	if ( opened->channel != cpu_to_le32 ( vmdev->channel ) ) {
459
 	if ( opened->channel != cpu_to_le32 ( vmdev->channel ) ) {
460
 		DBGC ( vmdev, "VMBUS %s unexpected opened channel %#08x\n",
460
 		DBGC ( vmdev, "VMBUS %s unexpected opened channel %#08x\n",
461
 		       vmdev->dev.name, le32_to_cpu ( opened->channel ) );
461
 		       vmdev->dev.name, le32_to_cpu ( opened->channel ) );
462
-		return -EPROTO;
462
+		rc = -EPROTO;
463
+		goto err_check_response;
463
 	}
464
 	}
464
 	if ( opened->id != open_id /* Non-endian */ ) {
465
 	if ( opened->id != open_id /* Non-endian */ ) {
465
 		DBGC ( vmdev, "VMBUS %s unexpected open ID %#08x\n",
466
 		DBGC ( vmdev, "VMBUS %s unexpected open ID %#08x\n",
466
 		       vmdev->dev.name, le32_to_cpu ( opened->id ) );
467
 		       vmdev->dev.name, le32_to_cpu ( opened->id ) );
467
-		return -EPROTO;
468
+		rc = -EPROTO;
469
+		goto err_check_response;
468
 	}
470
 	}
469
 	if ( opened->status != 0 ) {
471
 	if ( opened->status != 0 ) {
470
 		DBGC ( vmdev, "VMBUS %s open failed: %#08x\n",
472
 		DBGC ( vmdev, "VMBUS %s open failed: %#08x\n",
471
 		       vmdev->dev.name, le32_to_cpu ( opened->status ) );
473
 		       vmdev->dev.name, le32_to_cpu ( opened->status ) );
472
-		return -EPROTO;
474
+		rc = -EPROTO;
475
+		goto err_check_response;
473
 	}
476
 	}
474
 
477
 
475
 	/* Store channel parameters */
478
 	/* Store channel parameters */
488
 		( virt_to_phys ( vmdev->out ) + len ) );
491
 		( virt_to_phys ( vmdev->out ) + len ) );
489
 	return 0;
492
 	return 0;
490
 
493
 
494
+ err_check_response:
495
+ err_wait_for_message:
496
+ err_post_message:
491
 	vmbus_gpadl_teardown ( vmdev, vmdev->gpadl );
497
 	vmbus_gpadl_teardown ( vmdev, vmdev->gpadl );
492
  err_establish:
498
  err_establish:
493
 	free_dma ( ring, len );
499
 	free_dma ( ring, len );

Loading…
Cancel
Save