Staging: bcm: InterfaceMisc.c: Outsourced doubled error checking
authorMatthias Beyer <mail@beyermatthias.de>
Tue, 1 Jul 2014 07:50:09 +0000 (09:50 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 Jul 2014 23:22:30 +0000 (16:22 -0700)
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/bcm/InterfaceMisc.c

index fff7d68e1fe41440ea55e203304392476c4f9c9a..a0f159e171494c27ff6c548e0fcf314c8ddca328 100644 (file)
@@ -1,36 +1,46 @@
 #include "headers.h"
 
-int InterfaceRDM(struct bcm_interface_adapter *psIntfAdapter,
-               unsigned int addr,
-               void *buff,
-               int len)
+static int adapter_err_occurred(const struct bcm_interface_adapter *ad)
 {
-       int bytes;
-
-       if (!psIntfAdapter)
-               return -EINVAL;
-
-       if (psIntfAdapter->psAdapter->device_removed == TRUE) {
-               BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
+       if (ad->psAdapter->device_removed == TRUE) {
+               BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_PRINTK, 0, 0,
                                "Device got removed");
                return -ENODEV;
        }
 
-       if ((psIntfAdapter->psAdapter->StopAllXaction == TRUE) &&
-           (psIntfAdapter->psAdapter->chip_id >= T3LPB)) {
-               BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, RDM,
+       if ((ad->psAdapter->StopAllXaction == TRUE) &&
+           (ad->psAdapter->chip_id >= T3LPB)) {
+               BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_OTHERS, RDM,
                                DBG_LVL_ALL,
                                "Currently Xaction is not allowed on the bus");
                return -EACCES;
        }
 
-       if (psIntfAdapter->bSuspended == TRUE ||
-           psIntfAdapter->bPreparingForBusSuspend == TRUE) {
-               BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, RDM,
+       if (ad->bSuspended == TRUE || ad->bPreparingForBusSuspend == TRUE) {
+               BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_OTHERS, RDM,
                                DBG_LVL_ALL,
                                "Bus is in suspended states hence RDM not allowed..");
                return -EACCES;
        }
+
+       return 0;
+}
+
+int InterfaceRDM(struct bcm_interface_adapter *psIntfAdapter,
+               unsigned int addr,
+               void *buff,
+               int len)
+{
+       int bytes;
+       int err = 0;
+
+       if (!psIntfAdapter)
+               return -EINVAL;
+
+       err = adapter_err_occurred(psIntfAdapter);
+       if (err)
+               return err;
+
        psIntfAdapter->psAdapter->DeviceAccess = TRUE;
 
        bytes = usb_control_msg(psIntfAdapter->udev,
@@ -63,31 +73,14 @@ int InterfaceWRM(struct bcm_interface_adapter *psIntfAdapter,
                int len)
 {
        int retval = 0;
+       int err = 0;
 
        if (!psIntfAdapter)
                return -EINVAL;
 
-       if (psIntfAdapter->psAdapter->device_removed == TRUE) {
-               BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
-                               "Device got removed");
-               return -ENODEV;
-       }
-
-       if ((psIntfAdapter->psAdapter->StopAllXaction == TRUE) &&
-           (psIntfAdapter->psAdapter->chip_id >= T3LPB)) {
-               BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, WRM,
-                               DBG_LVL_ALL,
-                               "Currently Xaction is not allowed on the bus...");
-               return -EACCES;
-       }
-
-       if (psIntfAdapter->bSuspended == TRUE ||
-           psIntfAdapter->bPreparingForBusSuspend == TRUE) {
-               BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, WRM,
-                               DBG_LVL_ALL,
-                               "Bus is in suspended states hence RDM not allowed..");
-               return -EACCES;
-       }
+       err = adapter_err_occurred(psIntfAdapter);
+       if (err)
+               return err;
 
        psIntfAdapter->psAdapter->DeviceAccess = TRUE;