diff mbox series

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

Message ID 20211130063939.6929-1-rdunlap@infradead.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [1/2,-net] natsemi: xtensa: allow writing to const dev_addr array | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: czankel@Athlon.(none); 4 maintainers not CCed: czankel@Athlon.(none) arnd@arndb.de christophe.jaillet@wanadoo.fr fthain@linux-m68k.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch fail CHECK: spaces preferred around that '*' (ctx:VxV) CHECK: spaces preferred around that '+' (ctx:VxV) ERROR: spaces required around that '<' (ctx:VxV) ERROR: spaces required around that '=' (ctx:VxV)
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Randy Dunlap Nov. 30, 2021, 6:39 a.m. UTC
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 <rdunlap@infradead.org>
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(-)

Comments

Max Filippov Nov. 30, 2021, 2:44 p.m. UTC | #1
Hi Randy,

On Mon, Nov 29, 2021 at 10:39 PM Randy Dunlap <rdunlap@infradead.org> 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 <rdunlap@infradead.org>
> 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/
diff mbox series

Patch

--- 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;