Commit fffe8bec authored by Sergio Paracuellos's avatar Sergio Paracuellos Committed by Greg Kroah-Hartman

staging: ks7010: remove auxiliar zeros buffer in ks_wlan_get_encode

This commit removes the local buffer zeros in ks_wlan_get_encode
function. It also refactors related conditions in order to fill
'extra' output parameter of the function. Originally this zeros
is just memset to zeros and only being used if drw->length is
truncated to zero because of priv->reg.wep_key[index].size is
greater than 16 chars. In those cases the final if statement is
just using zeros but it is using memcpy with a length of zero
bytes which has no sense. Instead of that just handle the good
case copying from the same source the number of bytes of
priv->reg.wep_key[index].size. If it is zero the final 'extra'
parameter won't be copied at all because the number of bytes to
copy will be zero. With this change the code gets simplified.
Signed-off-by: default avatarSergio Paracuellos <sergio.paracuellos@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5dcb7b1e
......@@ -932,7 +932,6 @@ static int ks_wlan_get_encode(struct net_device *dev,
struct iw_point *dwrq, char *extra)
{
struct ks_wlan_private *priv = netdev_priv(dev);
char zeros[16];
int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
if (priv->sleep_mode == SLP_SLEEP)
......@@ -951,8 +950,6 @@ static int ks_wlan_get_encode(struct net_device *dev,
break;
}
memset(zeros, 0, sizeof(zeros));
/* Which key do we want ? -1 -> tx index */
if ((index < 0) || (index >= 4))
index = priv->reg.wep_index;
......@@ -962,16 +959,10 @@ static int ks_wlan_get_encode(struct net_device *dev,
}
dwrq->flags |= index + 1;
/* Copy the key to the user buffer */
if ((index >= 0) && (index < 4))
dwrq->length = priv->reg.wep_key[index].size;
if (dwrq->length > 16)
dwrq->length = 0;
if (dwrq->length) {
if ((index >= 0) && (index < 4))
memcpy(extra, priv->reg.wep_key[index].val,
dwrq->length);
} else {
memcpy(extra, zeros, dwrq->length);
if (index >= 0 && index < 4) {
dwrq->length = (priv->reg.wep_key[index].size <= 16) ?
priv->reg.wep_key[index].size : 0;
memcpy(extra, priv->reg.wep_key[index].val, dwrq->length);
}
return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment