staging: ks7010: remove custom return values
authorTobin C. Harding <me@tobin.cc>
Tue, 14 Mar 2017 10:20:12 +0000 (21:20 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 16 Mar 2017 02:41:37 +0000 (11:41 +0900)
Driver code uses custom return values (often positive) to signal error
condition instead of using standard kernel error codes.

Replace custom return values with standard kernel error codes.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ks7010/ks7010_sdio.c
drivers/staging/ks7010/ks_hostif.c
drivers/staging/ks7010/ks_wlan_net.c

index df90c20fcb693f99e4fae5fd8457a381948d7f9f..f3ae9dba36bc626d3bb0a878870b73c1788ec0c9 100644 (file)
@@ -241,21 +241,18 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
                         void *arg1, void *arg2)
 {
        struct tx_device_buffer *sp;
+       int rc;
 
        if (priv->dev_state < DEVICE_STATE_BOOT) {
-               kfree(p);
-               if (complete_handler)
-                       (*complete_handler) (arg1, arg2);
-               return 1;
+               rc = -EPERM;
+               goto err_complete;
        }
 
        if ((TX_DEVICE_BUFF_SIZE - 1) <= cnt_txqbody(priv)) {
                /* in case of buffer overflow */
                DPRINTK(1, "tx buffer overflow\n");
-               kfree(p);
-               if (complete_handler)
-                       (*complete_handler) (arg1, arg2);
-               return 1;
+               rc = -EOVERFLOW;
+               goto err_complete;
        }
 
        sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qtail];
@@ -267,15 +264,22 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
        inc_txqtail(priv);
 
        return 0;
+
+err_complete:
+       kfree(p);
+       if (complete_handler)
+               (*complete_handler) (arg1, arg2);
+
+       return rc;
 }
 
 /* write data */
 static int write_to_device(struct ks_wlan_private *priv, unsigned char *buffer,
                           unsigned long size)
 {
-       int retval;
        unsigned char rw_data;
        struct hostif_hdr *hdr;
+       int rc;
 
        hdr = (struct hostif_hdr *)buffer;
 
@@ -285,18 +289,17 @@ static int write_to_device(struct ks_wlan_private *priv, unsigned char *buffer,
                return 0;
        }
 
-       retval = ks7010_sdio_write(priv, DATA_WINDOW, buffer, size);
-       if (retval) {
-               DPRINTK(1, " write error : retval=%d\n", retval);
-               return -4;
+       rc = ks7010_sdio_write(priv, DATA_WINDOW, buffer, size);
+       if (rc) {
+               DPRINTK(1, " write error : retval=%d\n", rc);
+               return rc;
        }
 
        rw_data = WRITE_STATUS_BUSY;
-       retval =
-           ks7010_sdio_write(priv, WRITE_STATUS, &rw_data, sizeof(rw_data));
-       if (retval) {
+       rc = ks7010_sdio_write(priv, WRITE_STATUS, &rw_data, sizeof(rw_data));
+       if (rc) {
                DPRINTK(1, " error : WRITE_STATUS=%02X\n", rw_data);
-               return -3;
+               return rc;
        }
 
        return 0;
@@ -675,30 +678,27 @@ static void trx_device_exit(struct ks_wlan_private *priv)
 
 static int ks7010_sdio_update_index(struct ks_wlan_private *priv, u32 index)
 {
-       int rc = 0;
-       int retval;
+       int rc;
        unsigned char *data_buf;
 
        data_buf = kmalloc(sizeof(u32), GFP_KERNEL);
-       if (!data_buf) {
-               rc = 1;
-               goto error_out;
-       }
+       if (!data_buf)
+               return -ENOMEM;
 
        memcpy(data_buf, &index, sizeof(index));
-       retval = ks7010_sdio_write(priv, WRITE_INDEX, data_buf, sizeof(index));
-       if (retval) {
-               rc = 2;
+       rc = ks7010_sdio_write(priv, WRITE_INDEX, data_buf, sizeof(index));
+       if (rc)
                goto error_out;
-       }
 
-       retval = ks7010_sdio_write(priv, READ_INDEX, data_buf, sizeof(index));
-       if (retval) {
-               rc = 3;
+       rc = ks7010_sdio_write(priv, READ_INDEX, data_buf, sizeof(index));
+       if (rc)
                goto error_out;
-       }
+
+       return 0;
+
  error_out:
        kfree(data_buf);
+
        return rc;
 }
 
@@ -706,29 +706,28 @@ static int ks7010_sdio_update_index(struct ks_wlan_private *priv, u32 index)
 static int ks7010_sdio_data_compare(struct ks_wlan_private *priv, u32 address,
                                    unsigned char *data, unsigned int size)
 {
-       int rc = 0;
-       int retval;
+       int rc;
        unsigned char *read_buf;
 
        read_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL);
-       if (!read_buf) {
-               rc = 1;
-               goto error_out;
-       }
-       retval = ks7010_sdio_read(priv, address, read_buf, size);
-       if (retval) {
-               rc = 2;
+       if (!read_buf)
+               return -ENOMEM;
+
+       rc = ks7010_sdio_read(priv, address, read_buf, size);
+       if (rc)
                goto error_out;
-       }
-       retval = memcmp(data, read_buf, size);
 
-       if (retval) {
-               DPRINTK(0, "data compare error (%d)\n", retval);
-               rc = 3;
+       rc = memcmp(data, read_buf, size);
+       if (rc) {
+               DPRINTK(0, "data compare error (%d)\n", rc);
                goto error_out;
        }
+
+       return 0;
+
  error_out:
        kfree(read_buf);
+
        return rc;
 }
 
@@ -738,28 +737,27 @@ static int ks7010_upload_firmware(struct ks_wlan_private *priv,
        unsigned int size, offset, n = 0;
        unsigned char *rom_buf;
        unsigned char rw_data = 0;
-       int retval, rc = 0;
+       int rc;
        int length;
        const struct firmware *fw_entry = NULL;
 
        /* buffer allocate */
        rom_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL);
        if (!rom_buf)
-               return 3;
+               return -ENOMEM;
 
        sdio_claim_host(card->func);
 
        /* Firmware running ? */
-       retval = ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
+       rc = ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
        if (rw_data == GCR_A_RUN) {
                DPRINTK(0, "MAC firmware running ...\n");
-               rc = 0;
-               goto error_out0;
+               goto release_host_and_free;
        }
 
-       retval = request_firmware(&fw_entry, ROM_FILE, &priv->ks_wlan_hw.sdio_card->func->dev);
-       if (retval)
-               goto error_out0;
+       rc = request_firmware(&fw_entry, ROM_FILE, &priv->ks_wlan_hw.sdio_card->func->dev);
+       if (rc)
+               goto release_host_and_free;
 
        length = fw_entry->size;
 
@@ -779,67 +777,58 @@ static int ks7010_upload_firmware(struct ks_wlan_private *priv,
                memcpy(rom_buf, fw_entry->data + n, size);
                /* Update write index */
                offset = n;
-               retval =
-                   ks7010_sdio_update_index(priv,
-                                            KS7010_IRAM_ADDRESS + offset);
-               if (retval) {
-                       rc = 6;
-                       goto error_out1;
-               }
+               rc = ks7010_sdio_update_index(priv,
+                                             KS7010_IRAM_ADDRESS + offset);
+               if (rc)
+                       goto release_firmware;
 
                /* Write data */
-               retval = ks7010_sdio_write(priv, DATA_WINDOW, rom_buf, size);
-               if (retval) {
-                       rc = 8;
-                       goto error_out1;
-               }
+               rc = ks7010_sdio_write(priv, DATA_WINDOW, rom_buf, size);
+               if (rc)
+                       goto release_firmware;
 
                /* compare */
-               retval =
-                   ks7010_sdio_data_compare(priv, DATA_WINDOW, rom_buf, size);
-               if (retval) {
-                       rc = 9;
-                       goto error_out1;
-               }
+               rc = ks7010_sdio_data_compare(priv, DATA_WINDOW, rom_buf, size);
+               if (rc)
+                       goto release_firmware;
+
                n += size;
 
        } while (size);
 
        /* Remap request */
        rw_data = GCR_A_REMAP;
-       retval = ks7010_sdio_write(priv, GCR_A, &rw_data, sizeof(rw_data));
-       if (retval) {
-               rc = 11;
-               goto error_out1;
-       }
+       rc = ks7010_sdio_write(priv, GCR_A, &rw_data, sizeof(rw_data));
+       if (rc)
+               goto release_firmware;
+
        DPRINTK(4, " REMAP Request : GCR_A=%02X\n", rw_data);
 
        /* Firmware running check */
        for (n = 0; n < 50; ++n) {
                mdelay(10);     /* wait_ms(10); */
-               retval =
-                   ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
-               if (retval) {
-                       rc = 11;
-                       goto error_out1;
-               }
+               rc = ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
+               if (rc)
+                       goto release_firmware;
+
                if (rw_data == GCR_A_RUN)
                        break;
        }
        DPRINTK(4, "firmware wakeup (%d)!!!!\n", n);
        if ((50) <= n) {
                DPRINTK(1, "firmware can't start\n");
-               rc = 12;
-               goto error_out1;
+               rc = -EIO;
+               goto release_firmware;
        }
 
        rc = 0;
 
error_out1:
release_firmware:
        release_firmware(fw_entry);
error_out0:
release_host_and_free:
        sdio_release_host(card->func);
        kfree(rom_buf);
+
        return rc;
 }
 
index 1e497171f316d5f1df4d0b909ddf712d47e32897..db10e168ab3e5113f3c15b624c4dafa227f51f4e 100644 (file)
@@ -110,14 +110,13 @@ int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info_t *ap_info)
        struct local_ap_t *ap;
        union iwreq_data wrqu;
        struct net_device *netdev = priv->net_dev;
-       int rc = 0;
 
        DPRINTK(3, "\n");
        ap = &priv->current_ap;
 
        if ((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS) {
                memset(ap, 0, sizeof(struct local_ap_t));
-               return 1;
+               return -EPERM;
        }
 
        /* bssid */
@@ -198,7 +197,7 @@ int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info_t *ap_info)
        DPRINTK(4, "\n    ext_rate_set_size=%d\n    rate_set_size=%d\n",
                ap_info->ext_rate_set.size, ap_info->rate_set.size);
 
-       return rc;
+       return 0;
 }
 
 static
@@ -1125,12 +1124,13 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
        struct ieee802_1x_hdr *aa1x_hdr;
        struct wpa_eapol_key *eap_key;
        struct ethhdr *eth;
+       int rc;
 
        packet_len = packet->len;
        if (packet_len > ETH_FRAME_LEN) {
                DPRINTK(1, "bad length packet_len=%d\n", packet_len);
-               dev_kfree_skb(packet);
-               return -1;
+               rc = -EOVERFLOW;
+               goto err_kfree_skb;
        }
 
        if (((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS)
@@ -1157,8 +1157,8 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
 
        if (!pp) {
                DPRINTK(3, "allocate memory failed..\n");
-               dev_kfree_skb(packet);
-               return -2;
+               rc = -ENOMEM;
+               goto err_kfree_skb;
        }
 
        p = (unsigned char *)pp->data;
@@ -1171,9 +1171,8 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
        if (memcmp(&priv->eth_addr[0], eth->h_source, ETH_ALEN)) {
                DPRINTK(1, "invalid mac address !!\n");
                DPRINTK(1, "ethernet->h_source=%pM\n", eth->h_source);
-               dev_kfree_skb(packet);
-               kfree(pp);
-               return -3;
+               rc = -ENXIO;
+               goto err_kfree;
        }
 
        /* MAC address copy */
@@ -1276,6 +1275,13 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
        }
 
        return result;
+
+err_kfree:
+       kfree(pp);
+err_kfree_skb:
+       dev_kfree_skb(packet);
+
+       return rc;
 }
 
 #define ps_confirm_wait_inc(priv) do { \
index 651d4799733baee0e40e66e65eb0e948467b779b..76079dc296606c8ffac7aadf199a6f53582d31bf 100644 (file)
@@ -89,10 +89,10 @@ int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
        DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
 
        if (priv->dev_state < DEVICE_STATE_READY)
-               return -1;      /* not finished initialize */
+               return -EBUSY;  /* not finished initialize */
 
        if (atomic_read(&update_phyinfo))
-               return 1;
+               return -EPERM;
 
        /* The status */
        wstats->status = priv->reg.operation_mode;      /* Operation mode */