Re: [PATCH v2 68/75] staging: ks7010: Replace manual array copy with ether_addr_copy().

2018-03-31 Thread Dan Carpenter
I'm in a hurry because I'm leaving for a long weekend so I've reviewed
the first easy 67 patches but this one is tricky and I'm not able to
review it properly before I leave.

On Fri, Mar 30, 2018 at 11:08:48PM -0700, Quytelda Kahja wrote:
> Copying the dummy HW address into the struct net_device doesn't need
> to be done byte by byte; use ether_addr_copy() instead.

Fine.

> Additionally, dev->dev_addr is not eight bytes long.
> ether_setup() sets the dev->addr_len to ETH_ALEN (defined as 6)
> in the net core code.

So it's a buffer overflow?  The subject should have mentioned that this
is a bug fix.  But I'm not sure it is.  dev->dev_addr is MAX_ADDR_LEN (32)
bytes long I believe.  See dev_addr_init() for details.

The commit message didn't make it clear that you were getting rid of
priv->eth_addr.  It's a good change, but it confused me and I am in a
hurry.

> 
> Signed-off-by: Quytelda Kahja 
> ---
>  drivers/staging/ks7010/ks_hostif.c   | 29 +++--
>  drivers/staging/ks7010/ks_wlan.h |  2 --
>  drivers/staging/ks7010/ks_wlan_net.c | 13 ++---
>  3 files changed, 13 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/staging/ks7010/ks_hostif.c 
> b/drivers/staging/ks7010/ks_hostif.c
> index 1eff78540683..23c637ef147d 100644
> --- a/drivers/staging/ks7010/ks_hostif.c
> +++ b/drivers/staging/ks7010/ks_hostif.c
> @@ -388,6 +388,7 @@ int hostif_data_indication_wpa(struct ks_wlan_private 
> *priv,
>  static
>  void hostif_data_indication(struct ks_wlan_private *priv)
>  {
> + struct net_device *dev = priv->net_dev;
>   unsigned int rx_ind_size;   /* indicate data size */
>   struct sk_buff *skb;
>   unsigned short auth_type;
> @@ -411,9 +412,9 @@ void hostif_data_indication(struct ks_wlan_private *priv)
>   eth_proto = ntohs(eth_hdr->h_proto);
>  
>   /* source address check */
> - if (memcmp(>eth_addr[0], eth_hdr->h_source, ETH_ALEN) == 0) {
> - netdev_err(priv->net_dev, "invalid : source is own mac address 
> !!\n");
> - netdev_err(priv->net_dev,
> + if (memcmp(dev->dev_addr, eth_hdr->h_source, ETH_ALEN) == 0) {
> + netdev_err(dev, "invalid : source is own mac address !!\n");
> + netdev_err(dev,
>  
> "eth_hdrernet->h_dest=%02X:%02X:%02X:%02X:%02X:%02X\n",
>  eth_hdr->h_source[0], eth_hdr->h_source[1],
>  eth_hdr->h_source[2], eth_hdr->h_source[3],
> @@ -443,7 +444,7 @@ void hostif_data_indication(struct ks_wlan_private *priv)
>   priv->nstats.rx_dropped++;
>   return;
>   }
> - netdev_dbg(priv->net_dev, "SNAP, rx_ind_size = %d\n",
> + netdev_dbg(dev, "SNAP, rx_ind_size = %d\n",
>  rx_ind_size);

I don't like the printk cleanups.  They belong in a separate patch and
they make it harder for reviewers in a hurry to see what the patch is
doing.

Sorry, gotta run...

regards,
dan carpenter

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 68/75] staging: ks7010: Replace manual array copy with ether_addr_copy().

2018-03-31 Thread Quytelda Kahja
Copying the dummy HW address into the struct net_device doesn't need
to be done byte by byte; use ether_addr_copy() instead.
Additionally, dev->dev_addr is not eight bytes long.
ether_setup() sets the dev->addr_len to ETH_ALEN (defined as 6)
in the net core code.

Signed-off-by: Quytelda Kahja 
---
 drivers/staging/ks7010/ks_hostif.c   | 29 +++--
 drivers/staging/ks7010/ks_wlan.h |  2 --
 drivers/staging/ks7010/ks_wlan_net.c | 13 ++---
 3 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 1eff78540683..23c637ef147d 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -388,6 +388,7 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv,
 static
 void hostif_data_indication(struct ks_wlan_private *priv)
 {
+   struct net_device *dev = priv->net_dev;
unsigned int rx_ind_size;   /* indicate data size */
struct sk_buff *skb;
unsigned short auth_type;
@@ -411,9 +412,9 @@ void hostif_data_indication(struct ks_wlan_private *priv)
eth_proto = ntohs(eth_hdr->h_proto);
 
/* source address check */
-   if (memcmp(>eth_addr[0], eth_hdr->h_source, ETH_ALEN) == 0) {
-   netdev_err(priv->net_dev, "invalid : source is own mac address 
!!\n");
-   netdev_err(priv->net_dev,
+   if (memcmp(dev->dev_addr, eth_hdr->h_source, ETH_ALEN) == 0) {
+   netdev_err(dev, "invalid : source is own mac address !!\n");
+   netdev_err(dev,
   
"eth_hdrernet->h_dest=%02X:%02X:%02X:%02X:%02X:%02X\n",
   eth_hdr->h_source[0], eth_hdr->h_source[1],
   eth_hdr->h_source[2], eth_hdr->h_source[3],
@@ -443,7 +444,7 @@ void hostif_data_indication(struct ks_wlan_private *priv)
priv->nstats.rx_dropped++;
return;
}
-   netdev_dbg(priv->net_dev, "SNAP, rx_ind_size = %d\n",
+   netdev_dbg(dev, "SNAP, rx_ind_size = %d\n",
   rx_ind_size);
 
size = ETH_ALEN * 2;
@@ -463,7 +464,7 @@ void hostif_data_indication(struct ks_wlan_private *priv)
priv->nstats.rx_dropped++;
return;
}
-   netdev_dbg(priv->net_dev, "NETBEUI/NetBIOS rx_ind_size=%d\n",
+   netdev_dbg(dev, "NETBEUI/NetBIOS rx_ind_size=%d\n",
   rx_ind_size);
 
/* 8802/FDDI MAC copy */
@@ -480,7 +481,7 @@ void hostif_data_indication(struct ks_wlan_private *priv)
aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 14);
break;
default:/* other rx data */
-   netdev_err(priv->net_dev, "invalid data format\n");
+   netdev_err(dev, "invalid data format\n");
priv->nstats.rx_errors++;
return;
}
@@ -522,17 +523,9 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
case DOT11_MAC_ADDRESS:
/* MAC address */
hostif_sme_enqueue(priv, SME_GET_MAC_ADDRESS);
-   memcpy(priv->eth_addr, priv->rxp, ETH_ALEN);
+   memcpy(dev->dev_addr, priv->rxp, ETH_ALEN);
priv->mac_address_valid = true;
-   dev->dev_addr[0] = priv->eth_addr[0];
-   dev->dev_addr[1] = priv->eth_addr[1];
-   dev->dev_addr[2] = priv->eth_addr[2];
-   dev->dev_addr[3] = priv->eth_addr[3];
-   dev->dev_addr[4] = priv->eth_addr[4];
-   dev->dev_addr[5] = priv->eth_addr[5];
-   dev->dev_addr[6] = 0x00;
-   dev->dev_addr[7] = 0x00;
-   netdev_info(dev, "MAC ADDRESS = %pM\n", priv->eth_addr);
+   netdev_info(dev, "MAC ADDRESS = %pM\n", dev->dev_addr);
break;
case DOT11_PRODUCT_VERSION:
/* firmware version */
@@ -,7 +1104,7 @@ int hostif_data_request(struct ks_wlan_private *priv, 
struct sk_buff *skb)
 
/* skb check */
eth = (struct ethhdr *)skb->data;
-   if (memcmp(>eth_addr[0], eth->h_source, ETH_ALEN) != 0) {
+   if (memcmp(priv->net_dev->dev_addr, eth->h_source, ETH_ALEN) != 0) {
netdev_err(priv->net_dev, "invalid mac address !!\n");
netdev_err(priv->net_dev, "ethernet->h_source=%pM\n", 
eth->h_source);
ret = -ENXIO;
@@ -2167,7 +2160,7 @@ void hostif_sme_execute(struct ks_wlan_private *priv, int 
event)
case SME_MACADDRESS_SET_REQUEST:
hostif_mib_set_request(priv, LOCAL_CURRENTADDRESS, ETH_ALEN,
   MIB_VALUE_TYPE_OSTRING,
-  >eth_addr[0]);
+  priv->net_dev->dev_addr);