Signed-off-by: Matthias Beyer <mail@xxxxxxxxxxxxxxxx> --- drivers/staging/bcm/InterfaceMisc.c | 74 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/drivers/staging/bcm/InterfaceMisc.c b/drivers/staging/bcm/InterfaceMisc.c index fff7d68..51f6e1f 100644 --- a/drivers/staging/bcm/InterfaceMisc.c +++ b/drivers/staging/bcm/InterfaceMisc.c @@ -1,36 +1,49 @@ #include "headers.h" +static int adapter_err_check(const struct bcm_interface_adapter *ad, int *err) +{ + if (ad->psAdapter->device_removed == TRUE) { + BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_PRINTK, 0, 0, + "Device got removed"); + *err = -ENODEV; + return 1; + } + + 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"); + *err = -EACCES; + return 1; + } + + 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.."); + *err = -EACCES; + return 1; + } + + 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; - 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, RDM, - DBG_LVL_ALL, - "Currently Xaction is not allowed on the bus"); - return -EACCES; + if (adapter_err_check(psIntfAdapter, &err)) { + return err; } - if (psIntfAdapter->bSuspended == TRUE || - psIntfAdapter->bPreparingForBusSuspend == TRUE) { - BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, RDM, - DBG_LVL_ALL, - "Bus is in suspended states hence RDM not allowed.."); - return -EACCES; - } psIntfAdapter->psAdapter->DeviceAccess = TRUE; bytes = usb_control_msg(psIntfAdapter->udev, @@ -63,30 +76,13 @@ 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; + if (adapter_err_check(psIntfAdapter, &err)) { + return err; } psIntfAdapter->psAdapter->DeviceAccess = TRUE; -- 2.0.0 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel