[PATCH 1/2 -net] natsemi: xtensa: allow writing to const dev_addr array

STALE1714d

2 messages, 2 authors, 2021-11-30 · open the first message on its own page

[PATCH 1/2 -net] natsemi: xtensa: allow writing to const dev_addr array

From: Randy Dunlap <hidden>
Date: 2021-11-30 06:39:43

Let the compiler know that it's ok to write to this const field.

Fixes these build errors:

../drivers/net/ethernet/natsemi/xtsonic.c: In function 'sonic_probe1':
../drivers/net/ethernet/natsemi/xtsonic.c:166:36: error: assignment of read-only location '*(dev->dev_addr + (sizetype)(i * 2))'
  166 |                 dev->dev_addr[i*2] = val;
../drivers/net/ethernet/natsemi/xtsonic.c:167:38: error: assignment of read-only location '*(dev->dev_addr + ((sizetype)(i * 2) + 1))'
  167 |                 dev->dev_addr[i*2+1] = val >> 8;

Fixes: 74f2a5f0ef64 ("xtensa: Add support for the Sonic Ethernet device for the XT2000 board.")
Signed-off-by: Randy Dunlap <redacted>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: linux-xtensa@linux-xtensa.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
---
 drivers/net/ethernet/natsemi/xtsonic.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
--- linux-next-20211129.orig/drivers/net/ethernet/natsemi/xtsonic.c
+++ linux-next-20211129/drivers/net/ethernet/natsemi/xtsonic.c
@@ -125,6 +125,7 @@ static int __init sonic_probe1(struct ne
 	unsigned int silicon_revision;
 	struct sonic_local *lp = netdev_priv(dev);
 	unsigned int base_addr = dev->base_addr;
+	unsigned char *devadr;
 	int i;
 	int err = 0;
 
@@ -161,10 +162,10 @@ static int __init sonic_probe1(struct ne
 	SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
 	SONIC_WRITE(SONIC_CEP,0);
 
-	for (i=0; i<3; i++) {
+	for (i=0, devadr = (unsigned char *)dev->dev_addr; i<3; i++) {
 		unsigned int val = SONIC_READ(SONIC_CAP0-i);
-		dev->dev_addr[i*2] = val;
-		dev->dev_addr[i*2+1] = val >> 8;
+		devadr[i*2] = val;
+		devadr[i*2+1] = val >> 8;
 	}
 
 	lp->dma_bitmode = SONIC_BITMODE32;

Re: [PATCH 1/2 -net] natsemi: xtensa: allow writing to const dev_addr array

From: Max Filippov <jcmvbkbc@gmail.com>
Date: 2021-11-30 14:44:15

Hi Randy,

On Mon, Nov 29, 2021 at 10:39 PM Randy Dunlap [off-list ref] wrote:
Let the compiler know that it's ok to write to this const field.

Fixes these build errors:

../drivers/net/ethernet/natsemi/xtsonic.c: In function 'sonic_probe1':
../drivers/net/ethernet/natsemi/xtsonic.c:166:36: error: assignment of read-only location '*(dev->dev_addr + (sizetype)(i * 2))'
  166 |                 dev->dev_addr[i*2] = val;
../drivers/net/ethernet/natsemi/xtsonic.c:167:38: error: assignment of read-only location '*(dev->dev_addr + ((sizetype)(i * 2) + 1))'
  167 |                 dev->dev_addr[i*2+1] = val >> 8;

Fixes: 74f2a5f0ef64 ("xtensa: Add support for the Sonic Ethernet device for the XT2000 board.")
I don't think the original code was broken. But the change
adeef3e32146 ("net: constify netdev->dev_addr")
stated that all users of net_device::dev_addr were converted
to use helpers which is not correct.
Signed-off-by: Randy Dunlap <redacted>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: linux-xtensa@linux-xtensa.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
---
 drivers/net/ethernet/natsemi/xtsonic.c |    7 ++++---
There's also jazzsonic.c in this directory with the same pattern
in it. I've posted another patch that fixes them both using helper
function, as I guess was originally intended, here:
https://lore.kernel.org/lkml/20211130143600.31970-1-jcmvbkbc@gmail.com/

-- 
Thanks.
-- Max
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help