* [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
@ 2022-06-29 17:56 Jianglei Nie
2022-07-01 3:19 ` Jakub Kicinski
0 siblings, 1 reply; 9+ messages in thread
From: Jianglei Nie @ 2022-06-29 17:56 UTC (permalink / raw)
To: irusskikh, davem, edumazet, kuba, pabeni
Cc: netdev, linux-kernel, Jianglei Nie
If aq_nic_stop() fails, aq_ndev_close() returns err without calling
aq_nic_deinit() to release the relevant memory and resource, which
will lead to a memory leak.
We can fix it by deleting the if condition judgment and goto statement to
call aq_nic_deinit() directly after aq_nic_stop() to fix the memory leak.
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
drivers/net/ethernet/aquantia/atlantic/aq_main.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_main.c b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
index 88595863d8bc..362f8077ff97 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_main.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
@@ -94,8 +94,6 @@ static int aq_ndev_close(struct net_device *ndev)
int err = 0;
err = aq_nic_stop(aq_nic);
- if (err < 0)
- goto err_exit;
aq_nic_deinit(aq_nic, true);
err_exit:
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
2022-06-29 17:56 [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close() Jianglei Nie
@ 2022-07-01 3:19 ` Jakub Kicinski
0 siblings, 0 replies; 9+ messages in thread
From: Jakub Kicinski @ 2022-07-01 3:19 UTC (permalink / raw)
To: Jianglei Nie; +Cc: irusskikh, davem, edumazet, pabeni, netdev, linux-kernel
On Thu, 30 Jun 2022 01:56:45 +0800 Jianglei Nie wrote:
> err = aq_nic_stop(aq_nic);
> - if (err < 0)
> - goto err_exit;
> aq_nic_deinit(aq_nic, true);
>
> err_exit:
label is now unused, please make sure you build test your changes with
W=1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
@ 2022-07-01 6:52 Jianglei Nie
2022-07-01 14:33 ` Francois Romieu
0 siblings, 1 reply; 9+ messages in thread
From: Jianglei Nie @ 2022-07-01 6:52 UTC (permalink / raw)
To: irusskikh, davem, edumazet, kuba, pabeni
Cc: netdev, linux-kernel, Jianglei Nie
If aq_nic_stop() fails, aq_ndev_close() returns err without calling
aq_nic_deinit() to release the relevant memory and resource, which
will lead to a memory leak.
We can fix it by deleting the if condition judgment and goto statement to
call aq_nic_deinit() directly after aq_nic_stop() to fix the memory leak.
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
drivers/net/ethernet/aquantia/atlantic/aq_main.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_main.c b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
index 88595863d8bc..8a0af371e7dc 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_main.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
@@ -94,11 +94,8 @@ static int aq_ndev_close(struct net_device *ndev)
int err = 0;
err = aq_nic_stop(aq_nic);
- if (err < 0)
- goto err_exit;
aq_nic_deinit(aq_nic, true);
-err_exit:
return err;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
2022-07-01 6:52 Jianglei Nie
@ 2022-07-01 14:33 ` Francois Romieu
0 siblings, 0 replies; 9+ messages in thread
From: Francois Romieu @ 2022-07-01 14:33 UTC (permalink / raw)
To: Jianglei Nie
Cc: irusskikh, davem, edumazet, kuba, pabeni, netdev, linux-kernel
Jianglei Nie <niejianglei2021@163.com> :
> If aq_nic_stop() fails, aq_ndev_close() returns err without calling
> aq_nic_deinit() to release the relevant memory and resource, which
> will lead to a memory leak.
>
> We can fix it by deleting the if condition judgment and goto statement to
> call aq_nic_deinit() directly after aq_nic_stop() to fix the memory leak.
>
> Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
Either (1) the hardware is stopped and the relevance of error returning
aq_nic_stop is dubious at best or (2) the hardware is not stopped and
it may not be safe to remove its kernel allocated resources behind its
back.
There is a problem but this patch is imho targeting the symptom.
A knowledgeable answer to (1), (2) could also help to avoid the
dev_{close/open} danse in drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c.
--
Ueimor
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
@ 2022-09-13 6:39 Jianglei Nie
2022-09-13 10:25 ` kernel test robot
2022-09-13 14:29 ` kernel test robot
0 siblings, 2 replies; 9+ messages in thread
From: Jianglei Nie @ 2022-09-13 6:39 UTC (permalink / raw)
To: irusskikh, davem, edumazet, kuba, pabeni
Cc: netdev, linux-kernel, Jianglei Nie
If aq_nic_stop() fails, aq_ndev_close() returns err without calling
aq_nic_deinit() to release the relevant memory and resource, which
will lead to a memory leak.
We can fix it by deleting the if condition judgment and goto statement to
call aq_nic_deinit() directly after aq_nic_stop() to fix the memory leak.
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
drivers/net/ethernet/aquantia/atlantic/aq_main.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_main.c b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
index 88595863d8bc..362f8077ff97 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_main.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
@@ -94,8 +94,6 @@ static int aq_ndev_close(struct net_device *ndev)
int err = 0;
err = aq_nic_stop(aq_nic);
- if (err < 0)
- goto err_exit;
aq_nic_deinit(aq_nic, true);
err_exit:
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
2022-09-13 6:39 Jianglei Nie
@ 2022-09-13 10:25 ` kernel test robot
2022-09-13 14:29 ` kernel test robot
1 sibling, 0 replies; 9+ messages in thread
From: kernel test robot @ 2022-09-13 10:25 UTC (permalink / raw)
To: Jianglei Nie, irusskikh, davem, edumazet, kuba, pabeni
Cc: kbuild-all, netdev, linux-kernel, Jianglei Nie
Hi Jianglei,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
[also build test WARNING on net/master linus/master v6.0-rc5 next-20220912]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jianglei-Nie/net-atlantic-fix-potential-memory-leak-in-aq_ndev_close/20220913-144300
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 169ccf0e40825d9e465863e4707d8e8546d3c3cb
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20220913/202209131828.hYRSPYF2-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/e1ce8c41446db3a7dd59206ff9c8a75baf7be067
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jianglei-Nie/net-atlantic-fix-potential-memory-leak-in-aq_ndev_close/20220913-144300
git checkout e1ce8c41446db3a7dd59206ff9c8a75baf7be067
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/net/
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
drivers/net/ethernet/aquantia/atlantic/aq_main.c: In function 'aq_ndev_close':
>> drivers/net/ethernet/aquantia/atlantic/aq_main.c:99:1: warning: label 'err_exit' defined but not used [-Wunused-label]
99 | err_exit:
| ^~~~~~~~
vim +/err_exit +99 drivers/net/ethernet/aquantia/atlantic/aq_main.c
97bde5c4f909a5 David VomLehn 2017-01-23 90
97bde5c4f909a5 David VomLehn 2017-01-23 91 static int aq_ndev_close(struct net_device *ndev)
97bde5c4f909a5 David VomLehn 2017-01-23 92 {
97bde5c4f909a5 David VomLehn 2017-01-23 93 struct aq_nic_s *aq_nic = netdev_priv(ndev);
7b0c342f1f6754 Nikita Danilov 2019-11-07 94 int err = 0;
97bde5c4f909a5 David VomLehn 2017-01-23 95
97bde5c4f909a5 David VomLehn 2017-01-23 96 err = aq_nic_stop(aq_nic);
837c637869bef2 Nikita Danilov 2019-11-07 97 aq_nic_deinit(aq_nic, true);
97bde5c4f909a5 David VomLehn 2017-01-23 98
97bde5c4f909a5 David VomLehn 2017-01-23 @99 err_exit:
97bde5c4f909a5 David VomLehn 2017-01-23 100 return err;
97bde5c4f909a5 David VomLehn 2017-01-23 101 }
97bde5c4f909a5 David VomLehn 2017-01-23 102
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
2022-09-13 6:39 Jianglei Nie
2022-09-13 10:25 ` kernel test robot
@ 2022-09-13 14:29 ` kernel test robot
1 sibling, 0 replies; 9+ messages in thread
From: kernel test robot @ 2022-09-13 14:29 UTC (permalink / raw)
To: Jianglei Nie, irusskikh, davem, edumazet, kuba, pabeni
Cc: llvm, kbuild-all, netdev, linux-kernel, Jianglei Nie
Hi Jianglei,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
[also build test WARNING on net/master linus/master v6.0-rc5 next-20220913]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jianglei-Nie/net-atlantic-fix-potential-memory-leak-in-aq_ndev_close/20220913-144300
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 169ccf0e40825d9e465863e4707d8e8546d3c3cb
config: s390-randconfig-r026-20220912 (https://download.01.org/0day-ci/archive/20220913/202209132232.nSnoIBSi-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 1546df49f5a6d09df78f569e4137ddb365a3e827)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/e1ce8c41446db3a7dd59206ff9c8a75baf7be067
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jianglei-Nie/net-atlantic-fix-potential-memory-leak-in-aq_ndev_close/20220913-144300
git checkout e1ce8c41446db3a7dd59206ff9c8a75baf7be067
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash drivers/net/ethernet/aquantia/atlantic/ fs/f2fs/
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
In file included from drivers/net/ethernet/aquantia/atlantic/aq_main.c:10:
In file included from drivers/net/ethernet/aquantia/atlantic/aq_main.h:12:
In file included from drivers/net/ethernet/aquantia/atlantic/aq_common.h:13:
In file included from include/linux/etherdevice.h:20:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
^
include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
^
In file included from drivers/net/ethernet/aquantia/atlantic/aq_main.c:10:
In file included from drivers/net/ethernet/aquantia/atlantic/aq_main.h:12:
In file included from drivers/net/ethernet/aquantia/atlantic/aq_common.h:13:
In file included from include/linux/etherdevice.h:20:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
^
In file included from drivers/net/ethernet/aquantia/atlantic/aq_main.c:10:
In file included from drivers/net/ethernet/aquantia/atlantic/aq_main.h:12:
In file included from drivers/net/ethernet/aquantia/atlantic/aq_common.h:13:
In file included from include/linux/etherdevice.h:20:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> drivers/net/ethernet/aquantia/atlantic/aq_main.c:99:1: warning: unused label 'err_exit' [-Wunused-label]
err_exit:
^~~~~~~~~
13 warnings generated.
vim +/err_exit +99 drivers/net/ethernet/aquantia/atlantic/aq_main.c
97bde5c4f909a5 David VomLehn 2017-01-23 90
97bde5c4f909a5 David VomLehn 2017-01-23 91 static int aq_ndev_close(struct net_device *ndev)
97bde5c4f909a5 David VomLehn 2017-01-23 92 {
97bde5c4f909a5 David VomLehn 2017-01-23 93 struct aq_nic_s *aq_nic = netdev_priv(ndev);
7b0c342f1f6754 Nikita Danilov 2019-11-07 94 int err = 0;
97bde5c4f909a5 David VomLehn 2017-01-23 95
97bde5c4f909a5 David VomLehn 2017-01-23 96 err = aq_nic_stop(aq_nic);
837c637869bef2 Nikita Danilov 2019-11-07 97 aq_nic_deinit(aq_nic, true);
97bde5c4f909a5 David VomLehn 2017-01-23 98
97bde5c4f909a5 David VomLehn 2017-01-23 @99 err_exit:
97bde5c4f909a5 David VomLehn 2017-01-23 100 return err;
97bde5c4f909a5 David VomLehn 2017-01-23 101 }
97bde5c4f909a5 David VomLehn 2017-01-23 102
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
@ 2022-09-14 1:42 Jianglei Nie
2022-09-21 12:00 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 9+ messages in thread
From: Jianglei Nie @ 2022-09-14 1:42 UTC (permalink / raw)
To: irusskikh, davem, edumazet, kuba, pabeni
Cc: netdev, linux-kernel, Jianglei Nie
If aq_nic_stop() fails, aq_ndev_close() returns err without calling
aq_nic_deinit() to release the relevant memory and resource, which
will lead to a memory leak.
We can fix it by deleting the if condition judgment and goto statement to
call aq_nic_deinit() directly after aq_nic_stop() to fix the memory leak.
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
drivers/net/ethernet/aquantia/atlantic/aq_main.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_main.c b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
index 88595863d8bc..8a0af371e7dc 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_main.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
@@ -94,11 +94,8 @@ static int aq_ndev_close(struct net_device *ndev)
int err = 0;
err = aq_nic_stop(aq_nic);
- if (err < 0)
- goto err_exit;
aq_nic_deinit(aq_nic, true);
-err_exit:
return err;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
2022-09-14 1:42 Jianglei Nie
@ 2022-09-21 12:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-09-21 12:00 UTC (permalink / raw)
To: Jianglei Nie
Cc: irusskikh, davem, edumazet, kuba, pabeni, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Wed, 14 Sep 2022 09:42:38 +0800 you wrote:
> If aq_nic_stop() fails, aq_ndev_close() returns err without calling
> aq_nic_deinit() to release the relevant memory and resource, which
> will lead to a memory leak.
>
> We can fix it by deleting the if condition judgment and goto statement to
> call aq_nic_deinit() directly after aq_nic_stop() to fix the memory leak.
>
> [...]
Here is the summary with links:
- net: atlantic: fix potential memory leak in aq_ndev_close()
https://git.kernel.org/netdev/net/c/65e5d27df612
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] 9+ messages in thread
end of thread, other threads:[~2022-09-21 12:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-29 17:56 [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close() Jianglei Nie
2022-07-01 3:19 ` Jakub Kicinski
-- strict thread matches above, loose matches on Subject: below --
2022-07-01 6:52 Jianglei Nie
2022-07-01 14:33 ` Francois Romieu
2022-09-13 6:39 Jianglei Nie
2022-09-13 10:25 ` kernel test robot
2022-09-13 14:29 ` kernel test robot
2022-09-14 1:42 Jianglei Nie
2022-09-21 12:00 ` 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).