diff --git a/drivers/staging/wilc1000/bt.c b/drivers/staging/wilc1000/bt.c index 48a530250151fa..705ea17cb6626e 100644 --- a/drivers/staging/wilc1000/bt.c +++ b/drivers/staging/wilc1000/bt.c @@ -307,7 +307,7 @@ int wilc_bt_power_down(struct wilc *wilc, int source) mutex_lock(&wilc->cs); - pr_info("source: %s, current bus status Wifi: %d, BT: %d\n", + pr_info("POWERING DOWN: source: %s, current bus status Wifi: %d, BT: %d\n", (source == DEV_WIFI ? "Wifi" : "BT"), wilc->power.status[DEV_WIFI], wilc->power.status[DEV_BT]); @@ -327,6 +327,7 @@ int wilc_bt_power_down(struct wilc *wilc, int source) release_bus(wilc, WILC_BUS_RELEASE_ONLY, source); if (ret) { mutex_unlock(&wilc->cs); + pr_err("deinit failed ret: 0x%0x\n", ret); return ret; } } @@ -346,7 +347,7 @@ int wilc_bt_power_up(struct wilc *wilc, int source) mutex_lock(&wilc->cs); - pr_debug("source: %s, current bus status Wifi: %d, BT: %d\n", + pr_info("POWERING UP: source: %s, current bus status Wifi: %d, BT: %d\n", (source == DEV_WIFI ? "Wifi" : "BT"), wilc->power.status[DEV_WIFI], wilc->power.status[DEV_BT]); diff --git a/drivers/staging/wilc1000/hif.c b/drivers/staging/wilc1000/hif.c index 8d9cbc07af52b2..5389430a9ed291 100644 --- a/drivers/staging/wilc1000/hif.c +++ b/drivers/staging/wilc1000/hif.c @@ -1819,12 +1819,18 @@ int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level) { struct wid wid; int result; + struct wilc *wilc = vif->wilc; if (!rssi_level) { PRINT_ER(vif->ndev, "RSS pointer value is null\n"); return -EFAULT; } + if (!wilc->initialized) { + netdev_info(vif->ndev, "Driver not initialized\n"); + return 0; + } + wid.id = WID_RSSI; wid.type = WID_CHAR; wid.size = sizeof(char); diff --git a/drivers/staging/wilc1000/netdev.c b/drivers/staging/wilc1000/netdev.c index 98835b43231804..e27be97224eb5d 100644 --- a/drivers/staging/wilc1000/netdev.c +++ b/drivers/staging/wilc1000/netdev.c @@ -20,10 +20,6 @@ #define WILC_MULTICAST_TABLE_SIZE 8 -#define INIT_TIMEOUT 300 -#define DEINIT_TIMEOUT 10000 - - static int wilc_mac_open(struct net_device *ndev); static int wilc_mac_close(struct net_device *ndev); @@ -754,10 +750,13 @@ static void wilc_wlan_deinitialize(struct net_device *dev) return; } - if (wl->initialized) { PRINT_INFO(vif->ndev, INIT_DBG, "Deinitializing wilc ...\n"); + ret = wilc_wlan_stop(wl, vif); + if (ret != 0) + PRINT_ER(dev, "failed in wlan_stop\n"); + PRINT_D(vif->ndev, INIT_DBG, "destroy aging timer\n"); PRINT_INFO(vif->ndev, INIT_DBG, "Disabling IRQ\n"); @@ -771,30 +770,23 @@ static void wilc_wlan_deinitialize(struct net_device *dev) mutex_unlock(&wl->hif_cs); } } - complete(&wl->txq_event); + deinit_irq(dev); PRINT_INFO(vif->ndev, INIT_DBG, "Deinitializing Threads\n"); wlan_deinitialize_threads(dev); PRINT_INFO(vif->ndev, INIT_DBG, "Deinitializing IRQ\n"); - deinit_irq(dev); - - ret = wilc_wlan_stop(wl, vif); - if (ret != 0) - PRINT_ER(dev, "failed in wlan_stop\n"); PRINT_INFO(vif->ndev, INIT_DBG, "Deinitializing WILC Wlan\n"); wilc_wlan_cleanup(dev); wl->initialized = false; + wl->close = 0; + wl->quit = 0; PRINT_INFO(dev, INIT_DBG, "wilc deinitialization Done\n"); } else { PRINT_INFO(dev, INIT_DBG, "wilc is not initialized\n"); } - - pr_info("%s: Will sleep a bit after deinitialize\n", __func__); - msleep(DEINIT_TIMEOUT); - } static int wlan_initialize_threads(struct net_device *dev) @@ -836,13 +828,8 @@ static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif) int ret = 0; struct wilc *wl = vif->wilc; - pr_info("%s: Will sleep a bit before initialize\n", __func__); - msleep(INIT_TIMEOUT); - if (!wl->initialized) { wl->mac_status = WILC_MAC_STATUS_INIT; - wl->close = 0; - wl->initialized = 0; ret = wilc_wlan_init(dev); if (ret) { @@ -924,6 +911,7 @@ static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif) fail_wilc_wlan: wilc_wlan_cleanup(dev); PRINT_ER(dev, "WLAN initialization FAILED\n"); + wl->initialized = false; } else { PRINT_WRN(vif->ndev, INIT_DBG, "wilc already initialized\n"); } @@ -1189,6 +1177,9 @@ static int wilc_mac_close(struct net_device *ndev) wl->close = 1; wilc_wlan_deinitialize(ndev); + + PRINT_INFO(ndev, GENERIC_DBG, "Powering down wilc\n"); + wilc_bt_power_down(wl, DEV_WIFI); } vif->mac_opened = 0; diff --git a/drivers/staging/wilc1000/sdio.c b/drivers/staging/wilc1000/sdio.c index 3235ac6357688c..7debf403dc35bf 100644 --- a/drivers/staging/wilc1000/sdio.c +++ b/drivers/staging/wilc1000/sdio.c @@ -221,6 +221,7 @@ static int wilc_sdio_probe(struct sdio_func *func, wilc_netdev_cleanup(wilc); free: kfree(sdio_priv); + wilc->bus_data = NULL; return ret; } @@ -235,6 +236,7 @@ static void wilc_sdio_remove(struct sdio_func *func) wilc_netdev_cleanup(wilc); wilc_bt_deinit(); kfree(sdio_priv); + wilc->bus_data = NULL; } static int wilc_sdio_reset(struct wilc *wilc) @@ -259,6 +261,9 @@ static int wilc_sdio_reset(struct wilc *wilc) static bool wilc_sdio_is_init(struct wilc *wilc) { struct wilc_sdio *sdio_priv = wilc->bus_data; + if (!sdio_priv) { + return false; + } return sdio_priv->is_init; } @@ -412,6 +417,11 @@ static int wilc_sdio_write_reg(struct wilc *wilc, u32 addr, u32 data) struct wilc_sdio *sdio_priv = wilc->bus_data; int ret; + if (!sdio_priv) { + dev_err(&func->dev, "%s: 'bus_data' not initialized\n", __func__); + return -1; + } + cpu_to_le32s(&data); if (addr >= 0xf0 && addr <= 0xff) { /* only vendor specific registers */ @@ -461,6 +471,11 @@ static int wilc_sdio_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) { struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct wilc_sdio *sdio_priv = wilc->bus_data; + if (!sdio_priv) { + dev_err(&func->dev, "%s: 'bus_data' not initialized\n", __func__); + return -1; + } + u32 block_size = sdio_priv->block_size; struct sdio_cmd53 cmd; int nblk, nleft, ret; @@ -535,6 +550,11 @@ static int wilc_sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data) struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct wilc_sdio *sdio_priv = wilc->bus_data; int ret; + + if (!sdio_priv) { + dev_err(&func->dev, "%s: 'bus_data' not initialized\n", __func__); + return -1; + } if (addr >= 0xf0 && addr <= 0xff) { /* only vendor specific registers */ struct sdio_cmd52 cmd; @@ -582,9 +602,15 @@ static int wilc_sdio_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size) { struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct wilc_sdio *sdio_priv = wilc->bus_data; - u32 block_size = sdio_priv->block_size; struct sdio_cmd53 cmd; int nblk, nleft, ret; + u32 block_size; + + if (!sdio_priv) { + dev_err(&func->dev, "%s: 'bus_data' not initialized\n", __func__); + return -1; + } + block_size = sdio_priv->block_size; cmd.read_write = 0; if (addr > 0) { @@ -662,7 +688,9 @@ static int wilc_sdio_deinit(struct wilc *wilc) struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct wilc_sdio *sdio_priv = wilc->bus_data; - sdio_priv->is_init = false; + if (sdio_priv) { + sdio_priv->is_init = false; + } pm_runtime_put_sync_autosuspend(mmc_dev(func->card->host)); wilc_wlan_power(wilc, false); @@ -674,6 +702,11 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) { struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct wilc_sdio *sdio_priv = wilc->bus_data; + if (!sdio_priv) { + dev_err(&func->dev, "%s: 'bus_data' not initialized\n", __func__); + return -1; + } + struct sdio_cmd52 cmd; int loop, ret; u32 chipid; @@ -832,6 +865,11 @@ static int wilc_sdio_read_int(struct wilc *wilc, u32 *int_status) { struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct wilc_sdio *sdio_priv = wilc->bus_data; + if (!sdio_priv) { + dev_err(&func->dev, "%s: 'bus_data' not initialized\n", __func__); + return -1; + } + u32 tmp; struct sdio_cmd52 cmd; u32 irq_flags; @@ -883,6 +921,11 @@ static int wilc_sdio_clear_int_ext(struct wilc *wilc, u32 val) struct wilc_sdio *sdio_priv = wilc->bus_data; int ret; u32 reg = 0; + + if (!sdio_priv) { + dev_err(&func->dev, "%s: 'bus_data' not initialized\n", __func__); + return -1; + } if (wilc->chip == WILC_1000) { if (sdio_priv->irq_gpio) @@ -972,6 +1015,11 @@ static int wilc_sdio_sync_ext(struct wilc *wilc, int nint) { struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct wilc_sdio *sdio_priv = wilc->bus_data; + if (!sdio_priv) { + dev_err(&func->dev, "%s: 'bus_data' not initialized\n", __func__); + return -1; + } + u32 reg; int ret, i; diff --git a/drivers/staging/wilc1000/spi.c b/drivers/staging/wilc1000/spi.c index 84e0818a77b211..737fe64a2b282a 100644 --- a/drivers/staging/wilc1000/spi.c +++ b/drivers/staging/wilc1000/spi.c @@ -162,6 +162,7 @@ static int wilc_bus_probe(struct spi_device *spi) wilc_netdev_cleanup(wilc); free: kfree(spi_priv); + wilc->bus_data = NULL; return ret; } @@ -176,6 +177,7 @@ static int wilc_bus_remove(struct spi_device *spi) wilc_netdev_cleanup(wilc); wilc_bt_deinit(); kfree(spi_priv); + wilc->bus_data = NULL; return 0; } diff --git a/drivers/staging/wilc1000/wlan.c b/drivers/staging/wilc1000/wlan.c index f595684e2f5369..5f007d9c04dd2f 100644 --- a/drivers/staging/wilc1000/wlan.c +++ b/drivers/staging/wilc1000/wlan.c @@ -1550,10 +1550,6 @@ int wilc_wlan_start(struct wilc *wilc) ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg); wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®); - if (!ret) - wilc->initialized = 1; - else - wilc->initialized = 0; release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP, DEV_WIFI); return (ret < 0) ? ret : 0; @@ -1889,6 +1885,7 @@ int wilc_wlan_init(struct net_device *dev) wilc = vif->wilc; wilc->quit = 0; + wilc->close = 0; PRINT_INFO(vif->ndev, INIT_DBG, "Initializing WILC_Wlan\n");