* [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable
[not found] <9918f1ae-5604-4bdc-a654-e0566ca77ad6@moroto.mountain>
@ 2023-09-07 15:14 ` Daniel Golle
2023-09-07 16:21 ` Simon Horman
` (3 more replies)
2023-09-10 21:40 ` [PATCH net v2] " Daniel Golle
1 sibling, 4 replies; 7+ messages in thread
From: Daniel Golle @ 2023-09-07 15:14 UTC (permalink / raw)
To: Dan Carpenter, Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
Lorenzo Bianconi, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno, netdev,
linux-kernel, linux-arm-kernel, linux-mediatek
Variable dma_addr in function mtk_poll_rx can be uninitialized on
some of the error paths. In practise this doesn't matter, even random
data present in uninitialized stack memory can safely be used in the
way it happens in the error path.
However, in order to make Smatch happy make sure the variable is
always initialized.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 31090490d47ce..6342eac90793e 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2119,11 +2119,11 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
u8 *data, *new_data;
struct mtk_rx_dma_v2 *rxd, trxd;
int done = 0, bytes = 0;
+ dma_addr_t dma_addr = NULL;
while (done < budget) {
unsigned int pktlen, *rxdcsum;
struct net_device *netdev;
- dma_addr_t dma_addr;
u32 hash, reason;
int mac = 0;
--
2.42.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable
2023-09-07 15:14 ` [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable Daniel Golle
@ 2023-09-07 16:21 ` Simon Horman
2023-09-07 16:53 ` kernel test robot
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2023-09-07 16:21 UTC (permalink / raw)
To: Daniel Golle
Cc: Dan Carpenter, Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
Lorenzo Bianconi, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno, netdev,
linux-kernel, linux-arm-kernel, linux-mediatek
On Thu, Sep 07, 2023 at 04:14:20PM +0100, Daniel Golle wrote:
> Variable dma_addr in function mtk_poll_rx can be uninitialized on
> some of the error paths. In practise this doesn't matter, even random
> data present in uninitialized stack memory can safely be used in the
> way it happens in the error path.
>
> However, in order to make Smatch happy make sure the variable is
> always initialized.
>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
> drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 31090490d47ce..6342eac90793e 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2119,11 +2119,11 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
> u8 *data, *new_data;
> struct mtk_rx_dma_v2 *rxd, trxd;
> int done = 0, bytes = 0;
> + dma_addr_t dma_addr = NULL;
Hi Daniel,
I'm not sure that NULL is a valid value for a variable of type dma_addr_t.
Is DMA_MAPPING_ERROR more appropriate here?
Flagged by Sparse and, W=1 builds with gcc-13 and clang-16.
>
> while (done < budget) {
> unsigned int pktlen, *rxdcsum;
> struct net_device *netdev;
> - dma_addr_t dma_addr;
> u32 hash, reason;
> int mac = 0;
>
> --
> 2.42.0
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable
2023-09-07 15:14 ` [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable Daniel Golle
2023-09-07 16:21 ` Simon Horman
@ 2023-09-07 16:53 ` kernel test robot
2023-09-07 17:14 ` kernel test robot
2023-09-08 6:58 ` Dan Carpenter
3 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2023-09-07 16:53 UTC (permalink / raw)
To: Daniel Golle, Dan Carpenter, Felix Fietkau, John Crispin,
Sean Wang, Mark Lee, Lorenzo Bianconi, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: oe-kbuild-all, netdev
Hi Daniel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net/main]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Golle/net-ethernet-mtk_eth_soc-fix-uninitialized-variable/20230907-234141
base: net/main
patch link: https://lore.kernel.org/r/51d1ae238aecde07b2b4fe02cdab0dc87287cd96.1694099183.git.daniel%40makrotopia.org
patch subject: [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230908/202309080027.e4rJ0o2x-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230908/202309080027.e4rJ0o2x-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202309080027.e4rJ0o2x-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:6,
from include/linux/of.h:14,
from drivers/net/ethernet/mediatek/mtk_eth_soc.c:9:
drivers/net/ethernet/mediatek/mtk_eth_soc.c: In function 'mtk_poll_rx':
>> include/linux/stddef.h:8:14: warning: initialization of 'dma_addr_t' {aka 'long long unsigned int'} from 'void *' makes integer from pointer without a cast [-Wint-conversion]
8 | #define NULL ((void *)0)
| ^
drivers/net/ethernet/mediatek/mtk_eth_soc.c:2008:31: note: in expansion of macro 'NULL'
2008 | dma_addr_t dma_addr = NULL;
| ^~~~
vim +8 include/linux/stddef.h
^1da177e4c3f41 Linus Torvalds 2005-04-16 6
^1da177e4c3f41 Linus Torvalds 2005-04-16 7 #undef NULL
^1da177e4c3f41 Linus Torvalds 2005-04-16 @8 #define NULL ((void *)0)
6e218287432472 Richard Knutsson 2006-09-30 9
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable
2023-09-07 15:14 ` [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable Daniel Golle
2023-09-07 16:21 ` Simon Horman
2023-09-07 16:53 ` kernel test robot
@ 2023-09-07 17:14 ` kernel test robot
2023-09-08 6:58 ` Dan Carpenter
3 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2023-09-07 17:14 UTC (permalink / raw)
To: Daniel Golle, Dan Carpenter, Felix Fietkau, John Crispin,
Sean Wang, Mark Lee, Lorenzo Bianconi, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthias Brugger,
AngeloGioacchino Del Regno, linux-kernel, linux-arm-kernel,
linux-mediatek
Cc: oe-kbuild-all, netdev
Hi Daniel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net/main]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Golle/net-ethernet-mtk_eth_soc-fix-uninitialized-variable/20230907-234141
base: net/main
patch link: https://lore.kernel.org/r/51d1ae238aecde07b2b4fe02cdab0dc87287cd96.1694099183.git.daniel%40makrotopia.org
patch subject: [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230908/202309080051.4UKDipfX-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230908/202309080051.4UKDipfX-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202309080051.4UKDipfX-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:6,
from include/linux/of.h:14,
from drivers/net/ethernet/mediatek/mtk_eth_soc.c:9:
drivers/net/ethernet/mediatek/mtk_eth_soc.c: In function 'mtk_poll_rx':
>> include/linux/stddef.h:8:14: warning: initialization of 'dma_addr_t' {aka 'unsigned int'} from 'void *' makes integer from pointer without a cast [-Wint-conversion]
8 | #define NULL ((void *)0)
| ^
drivers/net/ethernet/mediatek/mtk_eth_soc.c:2008:31: note: in expansion of macro 'NULL'
2008 | dma_addr_t dma_addr = NULL;
| ^~~~
vim +8 include/linux/stddef.h
^1da177e4c3f41 Linus Torvalds 2005-04-16 6
^1da177e4c3f41 Linus Torvalds 2005-04-16 7 #undef NULL
^1da177e4c3f41 Linus Torvalds 2005-04-16 @8 #define NULL ((void *)0)
6e218287432472 Richard Knutsson 2006-09-30 9
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable
2023-09-07 15:14 ` [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable Daniel Golle
` (2 preceding siblings ...)
2023-09-07 17:14 ` kernel test robot
@ 2023-09-08 6:58 ` Dan Carpenter
3 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2023-09-08 6:58 UTC (permalink / raw)
To: Daniel Golle
Cc: Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
Lorenzo Bianconi, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno, netdev,
linux-kernel, linux-arm-kernel, linux-mediatek
On Thu, Sep 07, 2023 at 04:14:20PM +0100, Daniel Golle wrote:
> Variable dma_addr in function mtk_poll_rx can be uninitialized on
> some of the error paths. In practise this doesn't matter, even random
> data present in uninitialized stack memory can safely be used in the
> way it happens in the error path.
KMemsan can detect unintialized memory at runtime as well. But
presumably no one runs that on production systems.
regards,
dan carpenter
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v2] net: ethernet: mtk_eth_soc: fix uninitialized variable
[not found] <9918f1ae-5604-4bdc-a654-e0566ca77ad6@moroto.mountain>
2023-09-07 15:14 ` [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable Daniel Golle
@ 2023-09-10 21:40 ` Daniel Golle
2023-09-11 9:40 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 7+ messages in thread
From: Daniel Golle @ 2023-09-10 21:40 UTC (permalink / raw)
To: Dan Carpenter, Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
Lorenzo Bianconi, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno, netdev,
linux-kernel, linux-arm-kernel, linux-mediatek
Variable dma_addr in function mtk_poll_rx can be uninitialized on
some of the error paths. In practise this doesn't matter, even random
data present in uninitialized stack memory can safely be used in the
way it happens in the error path.
However, in order to make Smatch happy make sure the variable is
always initialized.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
v2: initialize with DMA_MAPPING_ERROR instead of NULL
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 31090490d47ce..6145ddcff206c 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2119,11 +2119,11 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
u8 *data, *new_data;
struct mtk_rx_dma_v2 *rxd, trxd;
int done = 0, bytes = 0;
+ dma_addr_t dma_addr = DMA_MAPPING_ERROR;
while (done < budget) {
unsigned int pktlen, *rxdcsum;
struct net_device *netdev;
- dma_addr_t dma_addr;
u32 hash, reason;
int mac = 0;
@@ -2300,7 +2300,8 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
else
rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size);
- if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA))
+ if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA) &&
+ likely(dma_addr != DMA_MAPPING_ERROR))
rxd->rxd2 |= RX_DMA_PREP_ADDR64(dma_addr);
ring->calc_idx = idx;
--
2.42.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v2] net: ethernet: mtk_eth_soc: fix uninitialized variable
2023-09-10 21:40 ` [PATCH net v2] " Daniel Golle
@ 2023-09-11 9:40 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-09-11 9:40 UTC (permalink / raw)
To: Daniel Golle
Cc: dan.carpenter, nbd, john, sean.wang, Mark-MC.Lee, lorenzo, davem,
edumazet, kuba, pabeni, matthias.bgg, angelogioacchino.delregno,
netdev, linux-kernel, linux-arm-kernel, linux-mediatek
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Sun, 10 Sep 2023 22:40:30 +0100 you wrote:
> Variable dma_addr in function mtk_poll_rx can be uninitialized on
> some of the error paths. In practise this doesn't matter, even random
> data present in uninitialized stack memory can safely be used in the
> way it happens in the error path.
>
> However, in order to make Smatch happy make sure the variable is
> always initialized.
>
> [...]
Here is the summary with links:
- [net,v2] net: ethernet: mtk_eth_soc: fix uninitialized variable
https://git.kernel.org/netdev/net/c/e10a35abb3da
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-09-11 9:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <9918f1ae-5604-4bdc-a654-e0566ca77ad6@moroto.mountain>
2023-09-07 15:14 ` [PATCH net] net: ethernet: mtk_eth_soc: fix uninitialized variable Daniel Golle
2023-09-07 16:21 ` Simon Horman
2023-09-07 16:53 ` kernel test robot
2023-09-07 17:14 ` kernel test robot
2023-09-08 6:58 ` Dan Carpenter
2023-09-10 21:40 ` [PATCH net v2] " Daniel Golle
2023-09-11 9:40 ` 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).