Browse Source

[rndis] Clean up error handling path in register_rndis()

Avoid calling rndis_halt() and rndis->op->close() twice if the call to
register_netdev() fails.

Reported-by: Roman Kagan <rkagan@virtuozzo.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 6 years ago
parent
commit
05b979146d
1 changed files with 61 additions and 41 deletions
  1. 61
    41
      src/net/rndis.c

+ 61
- 41
src/net/rndis.c View File

@@ -650,6 +650,63 @@ static int rndis_oid ( struct rndis_device *rndis, unsigned int oid,
650 650
 	return 0;
651 651
 }
652 652
 
653
+/**
654
+ * Describe RNDIS device
655
+ *
656
+ * @v rndis		RNDIS device
657
+ * @ret rc		Return status code
658
+ */
659
+static int rndis_describe ( struct rndis_device *rndis ) {
660
+	struct net_device *netdev = rndis->netdev;
661
+	int rc;
662
+
663
+	/* Assign device name (for debugging) */
664
+	rndis->name = netdev->dev->name;
665
+
666
+	/* Open RNDIS device to read MAC addresses */
667
+	if ( ( rc = rndis->op->open ( rndis ) ) != 0 ) {
668
+		DBGC ( rndis, "RNDIS %s could not open: %s\n",
669
+		       rndis->name, strerror ( rc ) );
670
+		goto err_open;
671
+	}
672
+
673
+	/* Initialise RNDIS */
674
+	if ( ( rc = rndis_initialise ( rndis ) ) != 0 )
675
+		goto err_initialise;
676
+
677
+	/* Query permanent MAC address */
678
+	if ( ( rc = rndis_oid ( rndis, RNDIS_OID_802_3_PERMANENT_ADDRESS,
679
+				NULL, 0 ) ) != 0 )
680
+		goto err_query_permanent;
681
+
682
+	/* Query current MAC address */
683
+	if ( ( rc = rndis_oid ( rndis, RNDIS_OID_802_3_CURRENT_ADDRESS,
684
+				NULL, 0 ) ) != 0 )
685
+		goto err_query_current;
686
+
687
+	/* Get link status */
688
+	if ( ( rc = rndis_oid ( rndis, RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
689
+				NULL, 0 ) ) != 0 )
690
+		goto err_query_link;
691
+
692
+	/* Halt RNDIS device */
693
+	rndis_halt ( rndis );
694
+
695
+	/* Close RNDIS device */
696
+	rndis->op->close ( rndis );
697
+
698
+	return 0;
699
+
700
+ err_query_link:
701
+ err_query_current:
702
+ err_query_permanent:
703
+	rndis_halt ( rndis );
704
+ err_initialise:
705
+	rndis->op->close ( rndis );
706
+ err_open:
707
+	return rc;
708
+}
709
+
653 710
 /**
654 711
  * Receive indicate status message
655 712
  *
@@ -970,40 +1027,9 @@ int register_rndis ( struct rndis_device *rndis ) {
970 1027
 	struct net_device *netdev = rndis->netdev;
971 1028
 	int rc;
972 1029
 
973
-	/* Assign device name (for debugging) */
974
-	rndis->name = netdev->dev->name;
975
-
976
-	/* Open RNDIS device to read MAC addresses */
977
-	if ( ( rc = rndis->op->open ( rndis ) ) != 0 ) {
978
-		DBGC ( rndis, "RNDIS %s could not open: %s\n",
979
-		       rndis->name, strerror ( rc ) );
980
-		goto err_open;
981
-	}
982
-
983
-	/* Initialise RNDIS */
984
-	if ( ( rc = rndis_initialise ( rndis ) ) != 0 )
985
-		goto err_initialise;
986
-
987
-	/* Query permanent MAC address */
988
-	if ( ( rc = rndis_oid ( rndis, RNDIS_OID_802_3_PERMANENT_ADDRESS,
989
-				NULL, 0 ) ) != 0 )
990
-		goto err_query_permanent;
991
-
992
-	/* Query current MAC address */
993
-	if ( ( rc = rndis_oid ( rndis, RNDIS_OID_802_3_CURRENT_ADDRESS,
994
-				NULL, 0 ) ) != 0 )
995
-		goto err_query_current;
996
-
997
-	/* Get link status */
998
-	if ( ( rc = rndis_oid ( rndis, RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
999
-				NULL, 0 ) ) != 0 )
1000
-		goto err_query_link;
1001
-
1002
-	/* Halt RNDIS device */
1003
-	rndis_halt ( rndis );
1004
-
1005
-	/* Close RNDIS device */
1006
-	rndis->op->close ( rndis );
1030
+	/* Describe RNDIS device */
1031
+	if ( ( rc = rndis_describe ( rndis ) ) != 0 )
1032
+		goto err_describe;
1007 1033
 
1008 1034
 	/* Register network device */
1009 1035
 	if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
@@ -1016,13 +1042,7 @@ int register_rndis ( struct rndis_device *rndis ) {
1016 1042
 
1017 1043
 	unregister_netdev ( netdev );
1018 1044
  err_register:
1019
- err_query_link:
1020
- err_query_current:
1021
- err_query_permanent:
1022
-	rndis_halt ( rndis );
1023
- err_initialise:
1024
-	rndis->op->close ( rndis );
1025
- err_open:
1045
+ err_describe:
1026 1046
 	return rc;
1027 1047
 }
1028 1048
 

Loading…
Cancel
Save