wil6210: fix array out of bounds access in pmc
authorDedy Lansky <qca_dlansky@qca.qualcomm.com>
Wed, 5 Apr 2017 11:58:13 +0000 (14:58 +0300)
committerKalle Valo <kvalo@qca.qualcomm.com>
Thu, 13 Apr 2017 12:46:21 +0000 (15:46 +0300)
Array index 'i' is used before limits check.
Fix this by doing limits check first.

Signed-off-by: Dedy Lansky <qca_dlansky@qca.qualcomm.com>
Signed-off-by: Maya Erez <qca_merez@qca.qualcomm.com>
Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
drivers/net/wireless/ath/wil6210/pmc.c

index b067fdf086d41cd44c3e3482b37f7d2b2f21c310..2e301b6b32a9ce2a81a97e77affb2f8590cfe390 100644 (file)
@@ -200,7 +200,7 @@ void wil_pmc_alloc(struct wil6210_priv *wil,
 
 release_pmc_skbs:
        wil_err(wil, "exit on error: Releasing skbs...\n");
-       for (i = 0; pmc->descriptors[i].va && i < num_descriptors; i++) {
+       for (i = 0; i < num_descriptors && pmc->descriptors[i].va; i++) {
                dma_free_coherent(dev,
                                  descriptor_size,
                                  pmc->descriptors[i].va,
@@ -283,7 +283,7 @@ void wil_pmc_free(struct wil6210_priv *wil, int send_pmc_cmd)
                int i;
 
                for (i = 0;
-                    pmc->descriptors[i].va && i < pmc->num_descriptors; i++) {
+                    i < pmc->num_descriptors && pmc->descriptors[i].va; i++) {
                        dma_free_coherent(dev,
                                          pmc->descriptor_size,
                                          pmc->descriptors[i].va,