[PATCH 04/11] w35und: simplify hal_init_hardware() error handling

From: Pekka Enberg
Date: Wed Apr 08 2009 - 04:17:15 EST


Impact: cleanup

Use gotos to simplify the deep if-statement nesting in
hal_init_hardware().

Cc: Pavel Machek <pavel@xxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxxxxxx>
---
drivers/staging/winbond/wbusb.c | 66 ++++++++++++++++++++------------------
1 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/winbond/wbusb.c b/drivers/staging/winbond/wbusb.c
index 1943ff0..65d443a 100644
--- a/drivers/staging/winbond/wbusb.c
+++ b/drivers/staging/winbond/wbusb.c
@@ -487,38 +487,42 @@ static int hal_init_hardware(struct ieee80211_hw *hw)
pHwData->FragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD; // Setting default fragment threshold

pHwData->InitialResource = 1;
- if( Wb35Reg_initial(pHwData)) {
- pHwData->InitialResource = 2;
- if (Wb35Tx_initial(pHwData)) {
- pHwData->InitialResource = 3;
- if (Wb35Rx_initial(pHwData)) {
- pHwData->InitialResource = 4;
- init_timer(&pHwData->LEDTimer);
- pHwData->LEDTimer.function = hal_led_control;
- pHwData->LEDTimer.data = (unsigned long) priv;
- pHwData->LEDTimer.expires = jiffies + msecs_to_jiffies(1000);
- add_timer(&pHwData->LEDTimer);
-
- //
- // For restrict to vendor's hardware
- //
- SoftwareSet = hal_software_set( pHwData );
-
- #ifdef Vendor2
- // Try to make sure the EEPROM contain
- SoftwareSet >>= 8;
- if( SoftwareSet != 0x82 )
- return false;
- #endif
-
- Wb35Rx_start(hw);
- Wb35Tx_EP2VM_start(priv);
-
- return 0;
- }
- }
- }
+ if (!Wb35Reg_initial(pHwData))
+ goto error;
+
+ pHwData->InitialResource = 2;
+ if (!Wb35Tx_initial(pHwData))
+ goto error;
+
+ pHwData->InitialResource = 3;
+ if (!Wb35Rx_initial(pHwData))
+ goto error;
+
+ pHwData->InitialResource = 4;
+ init_timer(&pHwData->LEDTimer);
+ pHwData->LEDTimer.function = hal_led_control;
+ pHwData->LEDTimer.data = (unsigned long) priv;
+ pHwData->LEDTimer.expires = jiffies + msecs_to_jiffies(1000);
+ add_timer(&pHwData->LEDTimer);
+
+ //
+ // For restrict to vendor's hardware
+ //
+ SoftwareSet = hal_software_set( pHwData );
+
+ #ifdef Vendor2
+ // Try to make sure the EEPROM contain
+ SoftwareSet >>= 8;
+ if( SoftwareSet != 0x82 )
+ return false;
+ #endif

+ Wb35Rx_start(hw);
+ Wb35Tx_EP2VM_start(priv);
+
+ return 0;
+
+error:
pHwData->SurpriseRemove = 1;
return -EINVAL;
}
--
1.5.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/