Re: [PATCH 7/8] staging: rtl: use eth_hw_addr_set()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 19, 2021 at 10:12:42AM -0700, Jakub Kicinski wrote:
> diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
> index cfeaa9c1542f..7f9dee42a04d 100644
> --- a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
> +++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
> @@ -360,11 +360,14 @@ static void _rtl92e_read_eeprom_info(struct net_device *dev)
>  		 priv->eeprom_CustomerID);
>  
>  	if (!priv->AutoloadFailFlag) {
> +		u8 addr[ETH_ALEN];
> +
>  		for (i = 0; i < 6; i += 2) {
>  			usValue = rtl92e_eeprom_read(dev,
>  				 (EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1);
> -			*(u16 *)(&dev->dev_addr[i]) = usValue;
> +			*(u16 *)(&addr[i]) = usValue;

No this doesn't work.  It writes 2 bytes instead of one so it will
write one element beyond the end of addr[].  It doesn't work at all on
little endian systems.

I'm not sure what's going on here or how to fix it but array overflows
are always bad.

>  		}
> +		eth_hw_addr_set(dev, addr);
>  	} else {
>  		eth_hw_addr_set(dev, bMac_Tmp_Addr);
>  	}
> diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
> index f75a12543781..d7630f02a910 100644
> --- a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
> +++ b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
> @@ -184,7 +184,7 @@ void rtl92e_cam_restore(struct net_device *dev)
>  		if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
>  			rtl92e_set_key(dev, 4, 0,
>  				       priv->rtllib->pairwise_key_type,
> -				       (u8 *)dev->dev_addr, 0,
> +				       (const u8 *)dev->dev_addr, 0,
>  				       (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0]));
>  		} else {
>  			rtl92e_set_key(dev, 4, 0,
> @@ -197,7 +197,7 @@ void rtl92e_cam_restore(struct net_device *dev)
>  		if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
>  			rtl92e_set_key(dev, 4, 0,
>  				       priv->rtllib->pairwise_key_type,
> -				       (u8 *)dev->dev_addr, 0,
> +				       (const u8 *)dev->dev_addr, 0,
>  				       (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0]));
>  		} else {
>  			rtl92e_set_key(dev, 4, 0,
> diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
> index 4013107cd93a..14ca00a2789b 100644
> --- a/drivers/staging/rtl8192u/r8192U.h
> +++ b/drivers/staging/rtl8192u/r8192U.h
> @@ -1114,6 +1114,7 @@ void rtl8192_set_rxconf(struct net_device *dev);
>  void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate);
>  
>  void EnableHWSecurityConfig8192(struct net_device *dev);
> -void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, u8 *MacAddr, u8 DefaultKey, u32 *KeyContent);
> +void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
> +	    const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent);
>  
>  #endif
> diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
> index 3718d72e217e..cfbd9d79baa7 100644
> --- a/drivers/staging/rtl8192u/r8192U_core.c
> +++ b/drivers/staging/rtl8192u/r8192U_core.c
> @@ -2300,12 +2300,15 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
>  	/* set channelplan from eeprom */
>  	priv->ChannelPlan = priv->eeprom_ChannelPlan;
>  	if (bLoad_From_EEPOM) {
> +		u8 addr[ETH_ALEN];
> +
>  		for (i = 0; i < 6; i += 2) {
>  			ret = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
>  			if (ret < 0)
>  				return ret;
> -			*(u16 *)(&dev->dev_addr[i]) = (u16)ret;
> +			*(u16 *)(&addr[i]) = (u16)ret;

Same thing here.

>  		}
> +		eth_hw_addr_set(dev, addr);
>  	} else {
>  		eth_hw_addr_set(dev, bMac_Tmp_Addr);
>  		/* should I set IDR0 here? */

regards,
dan carpenter




[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux