From 05b979146ddb0b957354663a99c181357ad310b2 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 9 Jul 2018 10:35:57 +0100 Subject: [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 Signed-off-by: Michael Brown --- src/net/rndis.c | 102 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/src/net/rndis.c b/src/net/rndis.c index 8a58cb72..a3b562bc 100644 --- a/src/net/rndis.c +++ b/src/net/rndis.c @@ -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 * @@ -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 ) { @@ -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; } -- cgit v1.2.3-55-g7522