diff mbox series

cw1200: Fix memory leak in cw1200_set_key()

Message ID 20220526033003.473943-1-niejianglei2021@163.com
State New
Headers show
Series cw1200: Fix memory leak in cw1200_set_key() | expand

Commit Message

Jianglei Nie May 26, 2022, 3:30 a.m. UTC
When wsm_key.index > WSM_KEY_MAX_INDEX, cw1200_set_key() returns without
calling cw1200_free_key() like other wrong paths, which may lead to a
potential memory leak.

We can fix it by calling cw1200_free_key() when some error occurs.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/net/wireless/st/cw1200/sta.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Kalle Valo May 27, 2022, 6:27 a.m. UTC | #1
kernel test robot <lkp@intel.com> writes:

> Hi Jianglei,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on wireless-next/main]
> [also build test ERROR on wireless/main v5.18 next-20220526]
> [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]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Jianglei-Nie/cw1200-Fix-memory-leak-in-cw1200_set_key/20220526-114747
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
> config: x86_64-randconfig-a003 (https://download.01.org/0day-ci/archive/20220526/202205261656.CWDWN8nG-lkp@intel.com/config)
> compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 3d546191ad9d7d2ad2c7928204b9de51deafa675)
> 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
>         # https://github.com/intel-lab-lkp/linux/commit/1e40283730dea11a1556d589925313cdca295484
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Jianglei-Nie/cw1200-Fix-memory-leak-in-cw1200_set_key/20220526-114747
>         git checkout 1e40283730dea11a1556d589925313cdca295484
>         # 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=x86_64 SHELL=/bin/bash drivers/net/wireless/st/cw1200/
>
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>>> drivers/net/wireless/st/cw1200/sta.c:826:26: error: use of undeclared identifier 'idx'
>                            cw1200_free_key(priv, idx);
>                                                  ^

So you don't even compile your patches? That is bad.

The patches sent to linux-wireless should be properly tested. In some
trivial cases a compilation test might enough, but even then that needs
to be clearly documented with "Compile tested only" in the commit log.

I'm getting worried how frequent it has become that people submit
untested patches or that they test them using simulation tools like
syzbot, but not on real hardware.
diff mbox series

Patch

diff --git a/drivers/net/wireless/st/cw1200/sta.c b/drivers/net/wireless/st/cw1200/sta.c
index 236022d4ae2a..c0097577978d 100644
--- a/drivers/net/wireless/st/cw1200/sta.c
+++ b/drivers/net/wireless/st/cw1200/sta.c
@@ -823,6 +823,7 @@  int cw1200_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
 		};
 
 		if (wsm_key.index > WSM_KEY_MAX_INDEX) {
+			cw1200_free_key(priv, idx);
 			ret = -EINVAL;
 			goto finally;
 		}