staging: vt6655: refactor iwctl_giwaplist() to avoid -Wframe-larger-than warn.
authorKonrad Zapalowicz <bergo.torino@gmail.com>
Tue, 27 May 2014 15:42:25 +0000 (17:42 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 May 2014 21:10:46 +0000 (14:10 -0700)
This commit refactors the iwctl_giwaplist() function so that the sparse
warning "the frame size of 1292 bytes is larger than 1024 bytes
[-Wframe-larger-than=]" is no more.

The root cause of this warning were two arrays allocated on the stack
and this commit changes this - these arrays are now kmalloc'ed. As a
result the function is refactored and hopefully stil working the same.

I were not able to test these changes so at least the carefull review
is more than welcomed.

Note that my changes has broadened the set of error codes that this
function can return. The new error code is ENOMEM. Luckily, this is
no issue.

Signed-off-by: Konrad Zapalowicz <bergo.torino@gmail.com>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vt6655/iwctl.c

index eb03e68..ae2b87f 100644 (file)
@@ -714,42 +714,66 @@ int iwctl_giwaplist(struct net_device *dev,
                    char *extra)
 {
        int ii, jj, rc = 0;
-       struct sockaddr sock[IW_MAX_AP];
-       struct iw_quality qual[IW_MAX_AP];
+       struct sockaddr *sock   = NULL;
+       struct sockaddr *s      = NULL;
+       struct iw_quality *qual = NULL;
+       struct iw_quality *q    = NULL;
+       PKnownBSS pBSS          = NULL;
+
        PSDevice pDevice = (PSDevice)netdev_priv(dev);
        PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
 
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
-       // Only super-user can see AP list
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST\n");
 
        if (!capable(CAP_NET_ADMIN)) {
                rc = -EPERM;
-               return rc;
+               goto exit;
        }
 
-       if (wrq->pointer) {
-               PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
+       if (!wrq->pointer)
+               goto exit;
 
-               for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
-                       pBSS = &(pMgmt->sBSSList[ii]);
-                       if (!pBSS->bActive)
-                               continue;
-                       if (jj >= IW_MAX_AP)
-                               break;
-                       memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
-                       sock[jj].sa_family = ARPHRD_ETHER;
-                       qual[jj].level = pBSS->uRSSI;
-                       qual[jj].qual = qual[jj].noise = 0;
-                       qual[jj].updated = 2;
-                       jj++;
-               }
+       sock = kmalloc_array(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
+       if (!sock) {
+               rc = -ENOMEM;
+               goto exit;
+       }
+
+       qual = kmalloc_array(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
+       if (!qual) {
+               rc = -ENOMEM;
+               goto exit;
+       }
+
+       for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
+               pBSS = &(pMgmt->sBSSList[ii]);
+
+               if (!pBSS->bActive)
+                       continue;
+               if (jj >= IW_MAX_AP)
+                       break;
+
+               s = &sock[jj];
+               q = &qual[jj];
 
-               wrq->flags = 1; // Should be define'd
-               wrq->length = jj;
-               memcpy(extra, sock, sizeof(struct sockaddr)*jj);
-               memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
+               memcpy(s->sa_data, pBSS->abyBSSID, 6);
+               s->sa_family    = ARPHRD_ETHER;
+               q->level        = pBSS->uRSSI;
+               q->qual         = 0;
+               q->noise        = 0;
+               q->updated      = 2;
+               jj++;
        }
 
+       wrq->flags = 1; /* Should be define'd */
+       wrq->length = jj;
+       memcpy(extra, sock, sizeof(struct sockaddr) * jj);
+       memcpy(extra + sizeof(struct sockaddr) * jj,
+               qual,
+               sizeof(struct iw_quality) * jj);
+exit:
+       kfree(sock);
+       kfree(qual);
        return rc;
 }