1
0
Fork 0

staging: vt6655: refactor iwctl_giwaplist() to avoid -Wframe-larger-than warn.

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>
hifive-unleashed-5.1
Konrad Zapalowicz 2014-05-27 17:42:25 +02:00 committed by Greg Kroah-Hartman
parent 5dda2528ef
commit 0c4df9c969
1 changed files with 49 additions and 25 deletions

View 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++;
}
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);
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];
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;
}