staging: ks7010: remove auxiliar zeros buffer in ks_wlan_get_encode
authorSergio Paracuellos <sergio.paracuellos@gmail.com>
Thu, 19 Apr 2018 05:07:57 +0000 (07:07 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 23 Apr 2018 12:32:04 +0000 (14:32 +0200)
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: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ks7010/ks_wlan_net.c

index eaee49d..d0350a2 100644 (file)
@@ -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;