Skip to contentSkip to conversation

ath11k: Handle errors if peer creation fails

PATCH In review Alex Dewar 2 participants 10 messages Oct 4, 2020 – Nov 10, 2020

Subsystems (3)
lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 2/2 ath11k: Handle errors if peer creation fails

ath11k_peer_create() is called without its return value being checked, meaning errors will be unhandled. Add missing check and, as the mutex is unconditionally unlocked on leaving this function, simplify the exit path.

Addresses-Coverity-ID: 1497531 ("Code maintainability issues")

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")
---
 drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +9 -12
index 7f8dd47d2333..58db1b57b941 100644
@@ -5211,7 +5211,7 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
 	struct ath11k *ar = hw->priv;
 	struct ath11k_base *ab = ar->ab;
 	struct ath11k_vif *arvif = (void *)vif->drv_priv;
-	int ret;
+	int ret = 0;
 	struct peer_create_params param;
 
 	mutex_lock(&ar->conf_mutex);
@@ -5225,13 +5225,12 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
 	    arvif->vdev_type != WMI_VDEV_TYPE_AP &&
 	    arvif->vdev_type != WMI_VDEV_TYPE_MONITOR) {
 		memcpy(&arvif->chanctx, ctx, sizeof(*ctx));
-		mutex_unlock(&ar->conf_mutex);
-		return 0;
+		goto unlock;
 	}
 
 	if (WARN_ON(arvif->is_started)) {
-		mutex_unlock(&ar->conf_mutex);
-		return -EBUSY;
+		ret = -EBUSY;
+		goto unlock;
 	}
 
 	if (ab->hw_params.vdev_start_delay) {
@@ -5239,6 +5238,8 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
 		param.peer_type = WMI_PEER_TYPE_DEFAULT;
 		param.peer_addr = ar->mac_addr;
 		ret = ath11k_peer_create(ar, arvif, NULL, &param);
+		if (ret)
+			goto unlock;
 	}
 
 	ret = ath11k_mac_vdev_start(arvif, &ctx->def);
@@ -5246,23 +5247,19 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
 		ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
 			    arvif->vdev_id, vif->addr,
 			    ctx->def.chan->center_freq, ret);
-		goto err;
+		goto unlock;
 	}
 	if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
 		ret = ath11k_monitor_vdev_up(ar, arvif->vdev_id);
 		if (ret)
-			goto err;
+			goto unlock;
 	}
 
 	arvif->is_started = true;
 
 	/* TODO: Setup ps and cts/rts protection */
 
-	mutex_unlock(&ar->conf_mutex);
-
-	return 0;
-
-err:
+unlock:
 	mutex_unlock(&ar->conf_mutex);
 
 	return ret;
Signature · 1 line
2.28.0
author
#1 lore raw

PATCH 1/2 ath11k: Fix memory leak on error path

In ath11k_mac_setup_iface_combinations(), if memory cannot be assigned for the variable limits, then the memory assigned to combinations will be leaked. Fix this.

Addresses-Coverity-ID: 1497534 ("Resource leaks")

Fixes 2626c269702e ("ath11k: add interface_modes to hw_params")
---
 drivers/net/wireless/ath/ath11k/mac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/mac.c +3 -1
index 3f63a7bd6b59..7f8dd47d2333 100644
@@ -6041,8 +6041,10 @@ static int ath11k_mac_setup_iface_combinations(struct ath11k *ar)
 	n_limits = 2;
 
 	limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL);
-	if (!limits)
+	if (!limits) {
+		kfree(combinations);
 		return -ENOMEM;
+	}
 
 	limits[0].max = 1;
 	limits[0].types |= BIT(NL80211_IFTYPE_STATION);
Signature · 7 lines
2.28.0


-- 
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
#2 lore raw

Re: [PATCH 1/2] ath11k: Fix memory leak on error path

Quoted 7 lines · Alex Dewar

In ath11k_mac_setup_iface_combinations(), if memory cannot be assigned for the variable limits, then the memory assigned to combinations will be leaked. Fix this.

Addresses-Coverity-ID: 1497534 ("Resource leaks")

Fixes 2626c269702e ("ath11k: add interface_modes to hw_params")

Patch applied to wireless-drivers-next.git, thanks.

8431350eee2e ath11k: Fix memory leak on error path

Signature · 3 lines
https://patchwork.kernel.org/patch/11815579/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw

Re: [PATCH 1/2] ath11k: Fix memory leak on error path

In reply to Alex Dewar
Quoted 7 lines · Alex Dewar

In ath11k_mac_setup_iface_combinations(), if memory cannot be assigned for the variable limits, then the memory assigned to combinations will be leaked. Fix this.

Addresses-Coverity-ID: 1497534 ("Resource leaks")

Fixes 2626c269702e ("ath11k: add interface_modes to hw_params")

Patch applied to wireless-drivers-next.git, thanks.

8431350eee2e ath11k: Fix memory leak on error path

Signature · 9 lines
https://patchwork.kernel.org/patch/11815579/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


-- 
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
#4 lore raw
In reply to Alex Dewar
Quoted 17 lines · Alex Dewar

ath11k_peer_create() is called without its return value being checked, meaning errors will be unhandled. Add missing check and, as the mutex is unconditionally unlocked on leaving this function, simplify the exit path.

Addresses-Coverity-ID: 1497531 ("Code maintainability issues")

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")
---
 drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +0 -0
index 7f8dd47d2333..58db1b57b941 100644

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, · line 5214

Quoted 5 lines
drivers/net/wireless/ath/ath11k/mac.c +1 -1
@@ -5211,7 +5211,7 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
 	struct ath11k *ar = hw->priv;
 	struct ath11k_base *ab = ar->ab;
 	struct ath11k_vif *arvif = (void *)vif->drv_priv;
-	int ret;
+	int ret = 0;

I prefer not to initialise the ret variable.

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, · line 5265

Quoted 13 lines
drivers/net/wireless/ath/ath11k/mac.c +1 -5
 	arvif->is_started = true;
 
 	/* TODO: Setup ps and cts/rts protection */
 
-	mutex_unlock(&ar->conf_mutex);
-
-	return 0;
-
-err:
+unlock:
 	mutex_unlock(&ar->conf_mutex);
 
 	return ret;

So in the pending branch I changed this to:

	ret = 0;

out:

	mutex_unlock(&ar->conf_mutex);

	return ret;

Please check.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
author
#5 lore raw
Quoted 43 lines · Kalle Valo
Quoted 17 lines · Alex Dewar

ath11k_peer_create() is called without its return value being checked, meaning errors will be unhandled. Add missing check and, as the mutex is unconditionally unlocked on leaving this function, simplify the exit path.

Addresses-Coverity-ID: 1497531 ("Code maintainability issues")

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")
---
 drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +0 -0
index 7f8dd47d2333..58db1b57b941 100644

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, · line 5214

Quoted 5 lines
drivers/net/wireless/ath/ath11k/mac.c +1 -1
@@ -5211,7 +5211,7 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
 	struct ath11k *ar = hw->priv;
 	struct ath11k_base *ab = ar->ab;
 	struct ath11k_vif *arvif = (void *)vif->drv_priv;
-	int ret;
+	int ret = 0;

I prefer not to initialise the ret variable.

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, · line 5265

Quoted 13 lines
drivers/net/wireless/ath/ath11k/mac.c +1 -5
 	arvif->is_started = true;
 
 	/* TODO: Setup ps and cts/rts protection */
 
-	mutex_unlock(&ar->conf_mutex);
-
-	return 0;
-
-err:
+unlock:
 	mutex_unlock(&ar->conf_mutex);
 
 	return ret;

So in the pending branch I changed this to:

Quoted 8 lines
	ret = 0;

out:

	mutex_unlock(&ar->conf_mutex);

	return ret;

Please check.

Hi Kalle,

I'm afraid you've introduced a bug ;). The body of the first if-statement in the function doesn't set ret because no error has occurred. So now it'll jump to the label and the function will return ret uninitialized.

With the gcc extension, ret will be initialised to zero anyway, so we're not saving anything by explicitly assigning to ret later in the function.

Best,
Alex

Quoted 5 lines
Signature · 4 lines
-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Signature · 3 lines
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
#6 lore raw
Quoted 49 lines · Alex Dewar
Quoted 48 lines · Kalle Valo
Quoted 17 lines · Alex Dewar

ath11k_peer_create() is called without its return value being checked, meaning errors will be unhandled. Add missing check and, as the mutex is unconditionally unlocked on leaving this function, simplify the exit path.

Addresses-Coverity-ID: 1497531 ("Code maintainability issues")

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")
---
 drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +0 -0
index 7f8dd47d2333..58db1b57b941 100644

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, · line 5214

Quoted 5 lines
drivers/net/wireless/ath/ath11k/mac.c +1 -1
@@ -5211,7 +5211,7 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
 	struct ath11k *ar = hw->priv;
 	struct ath11k_base *ab = ar->ab;
 	struct ath11k_vif *arvif = (void *)vif->drv_priv;
-	int ret;
+	int ret = 0;

I prefer not to initialise the ret variable.

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, · line 5265

Quoted 13 lines
drivers/net/wireless/ath/ath11k/mac.c +1 -5
 	arvif->is_started = true;
 
 	/* TODO: Setup ps and cts/rts protection */
 
-	mutex_unlock(&ar->conf_mutex);
-
-	return 0;
-
-err:
+unlock:
 	mutex_unlock(&ar->conf_mutex);
 
 	return ret;

So in the pending branch I changed this to:

	ret = 0;

out:

	mutex_unlock(&ar->conf_mutex);
Quoted 7 lines
Quoted 3 lines
	return ret;

Please check.

I'm afraid you've introduced a bug ;). The body of the first if-statement in the function doesn't set ret because no error has occurred. So now it'll jump to the label and the function will return ret uninitialized.

Ouch, so I did. Good catch! I would have hoped that GCC warns about that but it didn't.

I fixed the bug and added also a warning messages if peer_create() fails:

https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git/commit/?h=pending&id=e3e7b8072fa6bb0928b9066cf76e19e6bd2ec663

Does this look better now? :)

Quoted 3 lines

With the gcc extension, ret will be initialised to zero anyway, so we're not saving anything by explicitly assigning to ret later in the function.

I prefer not to initialise ret in the beginning of the function and I try to maintain that style in ath11k. I think it's more readable that the error value is assigned just before the goto.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
author
#7 lore raw
Quoted 62 lines · Kalle Valo
Quoted 49 lines · Alex Dewar
Quoted 48 lines · Kalle Valo
Quoted 17 lines · Alex Dewar

ath11k_peer_create() is called without its return value being checked, meaning errors will be unhandled. Add missing check and, as the mutex is unconditionally unlocked on leaving this function, simplify the exit path.

Addresses-Coverity-ID: 1497531 ("Code maintainability issues")

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")
---
 drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +0 -0
index 7f8dd47d2333..58db1b57b941 100644

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, · line 5214

Quoted 5 lines
drivers/net/wireless/ath/ath11k/mac.c +1 -1
@@ -5211,7 +5211,7 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
 	struct ath11k *ar = hw->priv;
 	struct ath11k_base *ab = ar->ab;
 	struct ath11k_vif *arvif = (void *)vif->drv_priv;
-	int ret;
+	int ret = 0;

I prefer not to initialise the ret variable.

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, · line 5265

Quoted 13 lines
drivers/net/wireless/ath/ath11k/mac.c +1 -5
 	arvif->is_started = true;
 
 	/* TODO: Setup ps and cts/rts protection */
 
-	mutex_unlock(&ar->conf_mutex);
-
-	return 0;
-
-err:
+unlock:
 	mutex_unlock(&ar->conf_mutex);
 
 	return ret;

So in the pending branch I changed this to:

	ret = 0;

out:

	mutex_unlock(&ar->conf_mutex);
Quoted 7 lines
Quoted 3 lines
	return ret;

Please check.

I'm afraid you've introduced a bug ;). The body of the first if-statement in the function doesn't set ret because no error has occurred. So now it'll jump to the label and the function will return ret uninitialized.

Ouch, so I did. Good catch! I would have hoped that GCC warns about that but it didn't.

Quoted 6 lines

I fixed the bug and added also a warning messages if peer_create() fails:

https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git/commit/?h=pending&id=e3e7b8072fa6bb0928b9066cf76e19e6bd2ec663

Does this look better now? :)

LGTM!

Quoted 8 lines
Quoted 4 lines

With the gcc extension, ret will be initialised to zero anyway, so we're not saving anything by explicitly assigning to ret later in the function.

I prefer not to initialise ret in the beginning of the function and I try to maintain that style in ath11k. I think it's more readable that the error value is assigned just before the goto.

Fair enough. I appreciate that it's a style issue.

Quoted 5 lines
Signature · 4 lines
-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Signature · 3 lines
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
#8 lore raw
In reply to Alex Dewar
Quoted 9 lines · Alex Dewar

ath11k_peer_create() is called without its return value being checked, meaning errors will be unhandled. Add missing check and, as the mutex is unconditionally unlocked on leaving this function, simplify the exit path.

Addresses-Coverity-ID: 1497531 ("Code maintainability issues")

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")

Patch applied to ath-next branch of ath.git, thanks.

c134d1f8c436 ath11k: Handle errors if peer creation fails

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#9 lore raw
In reply to Alex Dewar
Quoted 9 lines · Alex Dewar

ath11k_peer_create() is called without its return value being checked, meaning errors will be unhandled. Add missing check and, as the mutex is unconditionally unlocked on leaving this function, simplify the exit path.

Addresses-Coverity-ID: 1497531 ("Code maintainability issues")

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")

Patch applied to ath-next branch of ath.git, thanks.

c134d1f8c436 ath11k: Handle errors if peer creation fails

Signature · 9 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


-- 
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k