netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: fs_enet: Fix warning due to wrong type
@ 2024-08-08  7:16 Christophe Leroy
  2024-08-09  9:49 ` Simon Horman
  2024-08-10  5:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe Leroy @ 2024-08-08  7:16 UTC (permalink / raw)
  To: Pantelis Antoniou, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Christophe Leroy, linux-kernel, netdev

Building fs_enet on powerpc e500 leads to following warning:

    CC      drivers/net/ethernet/freescale/fs_enet/mac-scc.o
  In file included from ./include/linux/build_bug.h:5,
                   from ./include/linux/container_of.h:5,
                   from ./include/linux/list.h:5,
                   from ./include/linux/module.h:12,
                   from drivers/net/ethernet/freescale/fs_enet/mac-scc.c:15:
  drivers/net/ethernet/freescale/fs_enet/mac-scc.c: In function 'allocate_bd':
  ./include/linux/err.h:28:49: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     28 | #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
        |                                                 ^
  ./include/linux/compiler.h:77:45: note: in definition of macro 'unlikely'
     77 | # define unlikely(x)    __builtin_expect(!!(x), 0)
        |                                             ^
  drivers/net/ethernet/freescale/fs_enet/mac-scc.c:138:13: note: in expansion of macro 'IS_ERR_VALUE'
    138 |         if (IS_ERR_VALUE(fep->ring_mem_addr))
        |             ^~~~~~~~~~~~

This is due to fep->ring_mem_addr not being a pointer but a DMA
address which is 64 bits on that platform while pointers are
32 bits as this is a 32 bits platform with wider physical bus.

However, using fep->ring_mem_addr is just wrong because
cpm_muram_alloc() returns an offset within the muram and not
a physical address directly. So use fpi->dpram_offset instead.

Fixes: 48257c4f168e ("Add fs_enet ethernet network driver, for several embedded platforms.")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 .../net/ethernet/freescale/fs_enet/mac-scc.c   | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-scc.c b/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
index a64cb6270515..9e89ac2b6ce3 100644
--- a/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
+++ b/drivers/net/ethernet/freescale/fs_enet/mac-scc.c
@@ -131,15 +131,14 @@ static int setup_data(struct net_device *dev)
 static int allocate_bd(struct net_device *dev)
 {
 	struct fs_enet_private *fep = netdev_priv(dev);
-	const struct fs_platform_info *fpi = fep->fpi;
+	struct fs_platform_info *fpi = fep->fpi;
 
-	fep->ring_mem_addr = cpm_muram_alloc((fpi->tx_ring + fpi->rx_ring) *
-					     sizeof(cbd_t), 8);
-	if (IS_ERR_VALUE(fep->ring_mem_addr))
+	fpi->dpram_offset = cpm_muram_alloc((fpi->tx_ring + fpi->rx_ring) *
+					    sizeof(cbd_t), 8);
+	if (IS_ERR_VALUE(fpi->dpram_offset))
 		return -ENOMEM;
 
-	fep->ring_base = (void __iomem __force*)
-		cpm_muram_addr(fep->ring_mem_addr);
+	fep->ring_base = cpm_muram_addr(fpi->dpram_offset);
 
 	return 0;
 }
@@ -147,9 +146,10 @@ static int allocate_bd(struct net_device *dev)
 static void free_bd(struct net_device *dev)
 {
 	struct fs_enet_private *fep = netdev_priv(dev);
+	const struct fs_platform_info *fpi = fep->fpi;
 
 	if (fep->ring_base)
-		cpm_muram_free(fep->ring_mem_addr);
+		cpm_muram_free(fpi->dpram_offset);
 }
 
 static void cleanup_data(struct net_device *dev)
@@ -247,9 +247,9 @@ static void restart(struct net_device *dev)
 		__fs_out8((u8 __iomem *)ep + i, 0);
 
 	/* point to bds */
-	W16(ep, sen_genscc.scc_rbase, fep->ring_mem_addr);
+	W16(ep, sen_genscc.scc_rbase, fpi->dpram_offset);
 	W16(ep, sen_genscc.scc_tbase,
-	    fep->ring_mem_addr + sizeof(cbd_t) * fpi->rx_ring);
+	    fpi->dpram_offset + sizeof(cbd_t) * fpi->rx_ring);
 
 	/* Initialize function code registers for big-endian.
 	 */
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: fs_enet: Fix warning due to wrong type
  2024-08-08  7:16 [PATCH net] net: fs_enet: Fix warning due to wrong type Christophe Leroy
@ 2024-08-09  9:49 ` Simon Horman
  2024-08-10  5:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2024-08-09  9:49 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Pantelis Antoniou, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, netdev

On Thu, Aug 08, 2024 at 09:16:48AM +0200, Christophe Leroy wrote:
> Building fs_enet on powerpc e500 leads to following warning:
> 
>     CC      drivers/net/ethernet/freescale/fs_enet/mac-scc.o
>   In file included from ./include/linux/build_bug.h:5,
>                    from ./include/linux/container_of.h:5,
>                    from ./include/linux/list.h:5,
>                    from ./include/linux/module.h:12,
>                    from drivers/net/ethernet/freescale/fs_enet/mac-scc.c:15:
>   drivers/net/ethernet/freescale/fs_enet/mac-scc.c: In function 'allocate_bd':
>   ./include/linux/err.h:28:49: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>      28 | #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
>         |                                                 ^
>   ./include/linux/compiler.h:77:45: note: in definition of macro 'unlikely'
>      77 | # define unlikely(x)    __builtin_expect(!!(x), 0)
>         |                                             ^
>   drivers/net/ethernet/freescale/fs_enet/mac-scc.c:138:13: note: in expansion of macro 'IS_ERR_VALUE'
>     138 |         if (IS_ERR_VALUE(fep->ring_mem_addr))
>         |             ^~~~~~~~~~~~
> 
> This is due to fep->ring_mem_addr not being a pointer but a DMA
> address which is 64 bits on that platform while pointers are
> 32 bits as this is a 32 bits platform with wider physical bus.
> 
> However, using fep->ring_mem_addr is just wrong because
> cpm_muram_alloc() returns an offset within the muram and not
> a physical address directly. So use fpi->dpram_offset instead.
> 
> Fixes: 48257c4f168e ("Add fs_enet ethernet network driver, for several embedded platforms.")
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>

Reviewed-by: Simon Horman <horms@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: fs_enet: Fix warning due to wrong type
  2024-08-08  7:16 [PATCH net] net: fs_enet: Fix warning due to wrong type Christophe Leroy
  2024-08-09  9:49 ` Simon Horman
@ 2024-08-10  5:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-10  5:20 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: pantelis.antoniou, davem, edumazet, kuba, pabeni, linux-kernel,
	netdev

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu,  8 Aug 2024 09:16:48 +0200 you wrote:
> Building fs_enet on powerpc e500 leads to following warning:
> 
>     CC      drivers/net/ethernet/freescale/fs_enet/mac-scc.o
>   In file included from ./include/linux/build_bug.h:5,
>                    from ./include/linux/container_of.h:5,
>                    from ./include/linux/list.h:5,
>                    from ./include/linux/module.h:12,
>                    from drivers/net/ethernet/freescale/fs_enet/mac-scc.c:15:
>   drivers/net/ethernet/freescale/fs_enet/mac-scc.c: In function 'allocate_bd':
>   ./include/linux/err.h:28:49: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>      28 | #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
>         |                                                 ^
>   ./include/linux/compiler.h:77:45: note: in definition of macro 'unlikely'
>      77 | # define unlikely(x)    __builtin_expect(!!(x), 0)
>         |                                             ^
>   drivers/net/ethernet/freescale/fs_enet/mac-scc.c:138:13: note: in expansion of macro 'IS_ERR_VALUE'
>     138 |         if (IS_ERR_VALUE(fep->ring_mem_addr))
>         |             ^~~~~~~~~~~~
> 
> [...]

Here is the summary with links:
  - [net] net: fs_enet: Fix warning due to wrong type
    https://git.kernel.org/netdev/net-next/c/c146f3d19114

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-10  5:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08  7:16 [PATCH net] net: fs_enet: Fix warning due to wrong type Christophe Leroy
2024-08-09  9:49 ` Simon Horman
2024-08-10  5:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).