Browse Source

[fc] Hold ULP's peer reference while ULP exists

Allow fc_ulp_decrement() to guarantee to fc_peer_decrement() that the
peer reference remains valid for the duration of the call, by ensuring
that ulp->peer remains valid while ulp is valid.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
41231fda9c
1 changed files with 14 additions and 7 deletions
  1. 14
    7
      src/net/fc.c

+ 14
- 7
src/net/fc.c View File

1476
  ******************************************************************************
1476
  ******************************************************************************
1477
  */
1477
  */
1478
 
1478
 
1479
+/**
1480
+ * Free Fibre Channel upper-layer protocol
1481
+ *
1482
+ * @v refcnt		Reference count
1483
+ */
1484
+static void fc_ulp_free ( struct refcnt *refcnt ) {
1485
+	struct fc_ulp *ulp = container_of ( refcnt, struct fc_ulp, refcnt );
1486
+
1487
+	fc_peer_put ( ulp->peer );
1488
+	free ( ulp );
1489
+}
1490
+
1479
 /**
1491
 /**
1480
  * Close Fibre Channel upper-layer protocol
1492
  * Close Fibre Channel upper-layer protocol
1481
  *
1493
  *
1499
 	/* Remove from list of ULPs */
1511
 	/* Remove from list of ULPs */
1500
 	list_del ( &ulp->list );
1512
 	list_del ( &ulp->list );
1501
 	INIT_LIST_HEAD ( &ulp->list );
1513
 	INIT_LIST_HEAD ( &ulp->list );
1502
-
1503
-	/* Drop peer reference */
1504
-	fc_peer_put ( ulp->peer );
1505
-	ulp->peer = NULL;
1506
 }
1514
 }
1507
 
1515
 
1508
 /**
1516
 /**
1525
  * @v ulp		Fibre Channel ulp
1533
  * @v ulp		Fibre Channel ulp
1526
  */
1534
  */
1527
 void fc_ulp_decrement ( struct fc_ulp *ulp ) {
1535
 void fc_ulp_decrement ( struct fc_ulp *ulp ) {
1528
-	struct fc_peer *peer = ulp->peer;
1529
 
1536
 
1530
 	/* Sanity check */
1537
 	/* Sanity check */
1531
 	assert ( ulp->usage > 0 );
1538
 	assert ( ulp->usage > 0 );
1535
 		fc_ulp_logout ( ulp, 0 );
1542
 		fc_ulp_logout ( ulp, 0 );
1536
 
1543
 
1537
 	/* Decrement our peer's usage count */
1544
 	/* Decrement our peer's usage count */
1538
-	fc_peer_decrement ( peer );
1545
+	fc_peer_decrement ( ulp->peer );
1539
 }
1546
 }
1540
 
1547
 
1541
 /**
1548
 /**
1702
 	ulp = zalloc ( sizeof ( *ulp ) );
1709
 	ulp = zalloc ( sizeof ( *ulp ) );
1703
 	if ( ! ulp )
1710
 	if ( ! ulp )
1704
 		return NULL;
1711
 		return NULL;
1705
-	ref_init ( &ulp->refcnt, NULL );
1712
+	ref_init ( &ulp->refcnt, fc_ulp_free );
1706
 	fc_link_init ( &ulp->link, fc_ulp_examine, &ulp->refcnt );
1713
 	fc_link_init ( &ulp->link, fc_ulp_examine, &ulp->refcnt );
1707
 	intf_init ( &ulp->prli, &fc_ulp_prli_desc, &ulp->refcnt );
1714
 	intf_init ( &ulp->prli, &fc_ulp_prli_desc, &ulp->refcnt );
1708
 	ulp->peer = fc_peer_get ( peer );
1715
 	ulp->peer = fc_peer_get ( peer );

Loading…
Cancel
Save