Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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>
  • Loading branch information
mcb30 committed Jul 9, 2018
1 parent 1c47eb1 commit 05b9791
Showing 1 changed file with 61 additions and 41 deletions.
102 changes: 61 additions & 41 deletions src/net/rndis.c
Expand Up @@ -650,6 +650,63 @@ static int rndis_oid ( struct rndis_device *rndis, unsigned int oid,
return 0;
}

/**
* Describe RNDIS device
*
* @v rndis RNDIS device
* @ret rc Return status code
*/
static int rndis_describe ( struct rndis_device *rndis ) {
struct net_device *netdev = rndis->netdev;
int rc;

/* Assign device name (for debugging) */
rndis->name = netdev->dev->name;

/* Open RNDIS device to read MAC addresses */
if ( ( rc = rndis->op->open ( rndis ) ) != 0 ) {
DBGC ( rndis, "RNDIS %s could not open: %s\n",
rndis->name, strerror ( rc ) );
goto err_open;
}

/* Initialise RNDIS */
if ( ( rc = rndis_initialise ( rndis ) ) != 0 )
goto err_initialise;

/* Query permanent MAC address */
if ( ( rc = rndis_oid ( rndis, RNDIS_OID_802_3_PERMANENT_ADDRESS,
NULL, 0 ) ) != 0 )
goto err_query_permanent;

/* Query current MAC address */
if ( ( rc = rndis_oid ( rndis, RNDIS_OID_802_3_CURRENT_ADDRESS,
NULL, 0 ) ) != 0 )
goto err_query_current;

/* Get link status */
if ( ( rc = rndis_oid ( rndis, RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
NULL, 0 ) ) != 0 )
goto err_query_link;

/* Halt RNDIS device */
rndis_halt ( rndis );

/* Close RNDIS device */
rndis->op->close ( rndis );

return 0;

err_query_link:
err_query_current:
err_query_permanent:
rndis_halt ( rndis );
err_initialise:
rndis->op->close ( rndis );
err_open:
return rc;
}

/**
* Receive indicate status message
*
Expand Down Expand Up @@ -970,40 +1027,9 @@ int register_rndis ( struct rndis_device *rndis ) {
struct net_device *netdev = rndis->netdev;
int rc;

/* Assign device name (for debugging) */
rndis->name = netdev->dev->name;

/* Open RNDIS device to read MAC addresses */
if ( ( rc = rndis->op->open ( rndis ) ) != 0 ) {
DBGC ( rndis, "RNDIS %s could not open: %s\n",
rndis->name, strerror ( rc ) );
goto err_open;
}

/* Initialise RNDIS */
if ( ( rc = rndis_initialise ( rndis ) ) != 0 )
goto err_initialise;

/* Query permanent MAC address */
if ( ( rc = rndis_oid ( rndis, RNDIS_OID_802_3_PERMANENT_ADDRESS,
NULL, 0 ) ) != 0 )
goto err_query_permanent;

/* Query current MAC address */
if ( ( rc = rndis_oid ( rndis, RNDIS_OID_802_3_CURRENT_ADDRESS,
NULL, 0 ) ) != 0 )
goto err_query_current;

/* Get link status */
if ( ( rc = rndis_oid ( rndis, RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
NULL, 0 ) ) != 0 )
goto err_query_link;

/* Halt RNDIS device */
rndis_halt ( rndis );

/* Close RNDIS device */
rndis->op->close ( rndis );
/* Describe RNDIS device */
if ( ( rc = rndis_describe ( rndis ) ) != 0 )
goto err_describe;

/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
Expand All @@ -1016,13 +1042,7 @@ int register_rndis ( struct rndis_device *rndis ) {

unregister_netdev ( netdev );
err_register:
err_query_link:
err_query_current:
err_query_permanent:
rndis_halt ( rndis );
err_initialise:
rndis->op->close ( rndis );
err_open:
err_describe:
return rc;
}

Expand Down

0 comments on commit 05b9791

Please sign in to comment.