* [PATCH] mwifiex: fix error handling in mwifiex_create_custom_regdomain
@ 2016-09-14 12:42 Bob Copeland
2016-09-17 15:26 ` Kalle Valo
0 siblings, 1 reply; 2+ messages in thread
From: Bob Copeland @ 2016-09-14 12:42 UTC (permalink / raw)
To: linux-wireless; +Cc: Bob Copeland, Amitkumar Karwar, Nishant Sarmukadam
smatch reports:
sta_cmdresp.c:1053 mwifiex_create_custom_regdomain() warn: possible memory leak of 'regd'
Indeed, mwifiex_create_custom_regdomain() returns NULL in the
case that channel is missing in the TLV without freeing regd.
Moreover, some other error paths in this function return ERR_PTR
values which are assigned without checking to the regd field in
the mwifiex_adapter struct. The latter is only null-checked where
used.
Fix by freeing regd in the error path, and only update
priv->adapter->regd if the returned pointer is valid.
Cc: Amitkumar Karwar <akarwar@marvell.com>
Cc: Nishant Sarmukadam <nishants@marvell.com>
Signed-off-by: Bob Copeland <me@bobcopeland.com>
---
Note, compile-tested only. It might make sense to instead remove
the ERR_PTR stuff if there is no plan to report them further up the
call stack but I just went for the minimal patch here.
---
drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
index 3344a26..8548027 100644
--- a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
+++ b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
@@ -1049,8 +1049,10 @@ mwifiex_create_custom_regdomain(struct mwifiex_private *priv,
enum nl80211_band band;
chan = *buf++;
- if (!chan)
+ if (!chan) {
+ kfree(regd);
return NULL;
+ }
chflags = *buf++;
band = (chan <= 14) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
freq = ieee80211_channel_to_frequency(chan, band);
@@ -1116,6 +1118,7 @@ static int mwifiex_ret_chan_region_cfg(struct mwifiex_private *priv,
u16 action = le16_to_cpu(reg->action);
u16 tlv, tlv_buf_len, tlv_buf_left;
struct mwifiex_ie_types_header *head;
+ struct ieee80211_regdomain *regd;
u8 *tlv_buf;
if (action != HostCmd_ACT_GEN_GET)
@@ -1137,10 +1140,10 @@ static int mwifiex_ret_chan_region_cfg(struct mwifiex_private *priv,
mwifiex_dbg_dump(priv->adapter, CMD_D, "CHAN:",
(u8 *)head + sizeof(*head),
tlv_buf_len);
- priv->adapter->regd =
- mwifiex_create_custom_regdomain(priv,
- (u8 *)head +
- sizeof(*head), tlv_buf_len);
+ regd = mwifiex_create_custom_regdomain(priv,
+ (u8 *)head + sizeof(*head), tlv_buf_len);
+ if (!IS_ERR(regd))
+ priv->adapter->regd = regd;
break;
}
--
2.9.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: mwifiex: fix error handling in mwifiex_create_custom_regdomain
2016-09-14 12:42 [PATCH] mwifiex: fix error handling in mwifiex_create_custom_regdomain Bob Copeland
@ 2016-09-17 15:26 ` Kalle Valo
0 siblings, 0 replies; 2+ messages in thread
From: Kalle Valo @ 2016-09-17 15:26 UTC (permalink / raw)
To: Bob Copeland
Cc: linux-wireless, Bob Copeland, Amitkumar Karwar,
Nishant Sarmukadam
Bob Copeland <me@bobcopeland.com> wrote:
> smatch reports:
>
> sta_cmdresp.c:1053 mwifiex_create_custom_regdomain() warn: possible memory leak of 'regd'
>
> Indeed, mwifiex_create_custom_regdomain() returns NULL in the
> case that channel is missing in the TLV without freeing regd.
>
> Moreover, some other error paths in this function return ERR_PTR
> values which are assigned without checking to the regd field in
> the mwifiex_adapter struct. The latter is only null-checked where
> used.
>
> Fix by freeing regd in the error path, and only update
> priv->adapter->regd if the returned pointer is valid.
>
> Cc: Amitkumar Karwar <akarwar@marvell.com>
> Cc: Nishant Sarmukadam <nishants@marvell.com>
> Signed-off-by: Bob Copeland <me@bobcopeland.com>
Thanks, 1 patch applied to wireless-drivers-next.git:
92ca4f92eca7 mwifiex: fix error handling in mwifiex_create_custom_regdomain
--
Sent by pwcli
https://patchwork.kernel.org/patch/9331337/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-17 15:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-14 12:42 [PATCH] mwifiex: fix error handling in mwifiex_create_custom_regdomain Bob Copeland
2016-09-17 15:26 ` Kalle Valo
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).