public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
	knv418@gmail.com, jiapeng.chong@linux.alibaba.com,
	ojaswin98@gmail.com, arnd@arndb.de, lee.jones@linaro.org,
	clrrm@isep.ipp.pt, fabioaiuto83@gmail.com, hdegoede@redhat.com,
	ross.schm.dev@gmail.com, insafonov@gmail.com
Subject: Re: [PATCH 7/8] staging: rtl: use eth_hw_addr_set()
Date: Wed, 3 Nov 2021 14:29:06 +0300	[thread overview]
Message-ID: <20211103112906.GQ2794@kadam> (raw)
In-Reply-To: <20211019171243.1412240-8-kuba@kernel.org>

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

  reply	other threads:[~2021-11-03 11:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19 17:12 [PATCH 0/8] staging: prepare for const netdev->dev_addr Jakub Kicinski
2021-10-19 17:12 ` [PATCH 1/8] staging: use eth_hw_addr_set() Jakub Kicinski
2021-10-19 17:12 ` [PATCH 2/8] staging: use eth_hw_addr_set() instead of ether_addr_copy() Jakub Kicinski
2021-10-19 17:12 ` [PATCH 3/8] staging: use eth_hw_addr_set() for dev->addr_len cases Jakub Kicinski
2021-10-19 17:12 ` [PATCH 4/8] staging: qlge: use eth_hw_addr_set() Jakub Kicinski
2021-10-19 17:12 ` [PATCH 5/8] staging: rtl8712: prepare for const netdev->dev_addr Jakub Kicinski
2021-10-19 17:12 ` [PATCH 6/8] staging: unisys: use eth_hw_addr_set() Jakub Kicinski
2021-10-19 17:12 ` [PATCH 7/8] staging: rtl: " Jakub Kicinski
2021-11-03 11:29   ` Dan Carpenter [this message]
2021-11-03 13:36     ` Jakub Kicinski
2021-11-03 14:08       ` Dan Carpenter
2021-10-19 17:12 ` [PATCH 8/8] staging: use eth_hw_addr_set() in orphan drivers Jakub Kicinski
2021-10-20 16:53   ` Kees Cook
2021-10-19 17:34 ` [PATCH 0/8] staging: prepare for const netdev->dev_addr Greg KH
2021-10-19 18:01   ` Jakub Kicinski
2021-10-19 18:15     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211103112906.GQ2794@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=arnd@arndb.de \
    --cc=clrrm@isep.ipp.pt \
    --cc=fabioaiuto83@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=insafonov@gmail.com \
    --cc=jiapeng.chong@linux.alibaba.com \
    --cc=knv418@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=ojaswin98@gmail.com \
    --cc=ross.schm.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox