2022-05-26 17:05:57

by Jianglei Nie

[permalink] [raw]
Subject: [PATCH] cw1200: Fix memory leak in cw1200_set_key()

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 <[email protected]>
---
drivers/net/wireless/st/cw1200/sta.c | 1 +
1 file changed, 1 insertion(+)

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