linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ath11k: Fix some resource leaks in error path in 'ath11k_thermal_register()'
@ 2020-05-13 20:14 Christophe JAILLET
  2020-05-13 21:22 ` Rajkumar Manoharan
  2020-05-19  6:56 ` Kalle Valo
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2020-05-13 20:14 UTC (permalink / raw)
  To: kvalo, davem, pradeepc
  Cc: ath11k, linux-wireless, netdev, linux-kernel, kernel-janitors,
	Christophe JAILLET

If 'thermal_cooling_device_register()' fails, we must undo what has been
allocated so far. So we must go to 'err_thermal_destroy' instead of
returning directly

In case of error in 'ath11k_thermal_register()', the previous
'thermal_cooling_device_register()' call must also be undone. Move the
'ar->thermal.cdev = cdev' a few lines above in order for this to be done
in 'ath11k_thermal_unregister()' which is called in the error handling
path.

Fixes: 2a63bbca06b2 ("ath11k: add thermal cooling device support")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
I'm not 100% confident with this patch.

- When calling 'ath11k_thermal_unregister()', we try to release some
  resources that have not been allocated yet. I don't know if it can be an
  issue or not.
- I think that we should propagate the error code, instead of forcing
  -EINVAL.
---
 drivers/net/wireless/ath/ath11k/thermal.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/thermal.c b/drivers/net/wireless/ath/ath11k/thermal.c
index 259dddbda2c7..5a7e150c621b 100644
--- a/drivers/net/wireless/ath/ath11k/thermal.c
+++ b/drivers/net/wireless/ath/ath11k/thermal.c
@@ -174,9 +174,12 @@ int ath11k_thermal_register(struct ath11k_base *sc)
 		if (IS_ERR(cdev)) {
 			ath11k_err(sc, "failed to setup thermal device result: %ld\n",
 				   PTR_ERR(cdev));
-			return -EINVAL;
+			ret = -EINVAL;
+			goto err_thermal_destroy;
 		}
 
+		ar->thermal.cdev = cdev;
+
 		ret = sysfs_create_link(&ar->hw->wiphy->dev.kobj, &cdev->device.kobj,
 					"cooling_device");
 		if (ret) {
@@ -184,7 +187,6 @@ int ath11k_thermal_register(struct ath11k_base *sc)
 			goto err_thermal_destroy;
 		}
 
-		ar->thermal.cdev = cdev;
 		if (!IS_REACHABLE(CONFIG_HWMON))
 			return 0;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ath11k: Fix some resource leaks in error path in 'ath11k_thermal_register()'
  2020-05-13 20:14 [PATCH] ath11k: Fix some resource leaks in error path in 'ath11k_thermal_register()' Christophe JAILLET
@ 2020-05-13 21:22 ` Rajkumar Manoharan
  2020-05-19  6:56 ` Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Rajkumar Manoharan @ 2020-05-13 21:22 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: kvalo, davem, pradeepc, ath11k, linux-wireless, netdev,
	linux-kernel, kernel-janitors, linux-wireless-owner

On 2020-05-13 13:14, Christophe JAILLET wrote:
> If 'thermal_cooling_device_register()' fails, we must undo what has 
> been
> allocated so far. So we must go to 'err_thermal_destroy' instead of
> returning directly
> 
> In case of error in 'ath11k_thermal_register()', the previous
> 'thermal_cooling_device_register()' call must also be undone. Move the
> 'ar->thermal.cdev = cdev' a few lines above in order for this to be 
> done
> in 'ath11k_thermal_unregister()' which is called in the error handling
> path.
> 
> Fixes: 2a63bbca06b2 ("ath11k: add thermal cooling device support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> I'm not 100% confident with this patch.
> 
> - When calling 'ath11k_thermal_unregister()', we try to release some
>   resources that have not been allocated yet. I don't know if it can be 
> an
>   issue or not.
> - I think that we should propagate the error code, instead of forcing
>   -EINVAL.
> 
Good catch.

-Rajkumar

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ath11k: Fix some resource leaks in error path in 'ath11k_thermal_register()'
  2020-05-13 20:14 [PATCH] ath11k: Fix some resource leaks in error path in 'ath11k_thermal_register()' Christophe JAILLET
  2020-05-13 21:22 ` Rajkumar Manoharan
@ 2020-05-19  6:56 ` Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2020-05-19  6:56 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: davem, pradeepc, ath11k, linux-wireless, netdev, linux-kernel,
	kernel-janitors, Christophe JAILLET

Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> If 'thermal_cooling_device_register()' fails, we must undo what has been
> allocated so far. So we must go to 'err_thermal_destroy' instead of
> returning directly
> 
> In case of error in 'ath11k_thermal_register()', the previous
> 'thermal_cooling_device_register()' call must also be undone. Move the
> 'ar->thermal.cdev = cdev' a few lines above in order for this to be done
> in 'ath11k_thermal_unregister()' which is called in the error handling
> path.
> 
> Fixes: 2a63bbca06b2 ("ath11k: add thermal cooling device support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>

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

25ca180ad380 ath11k: Fix some resource leaks in error path in 'ath11k_thermal_register()'

-- 
https://patchwork.kernel.org/patch/11547195/

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-19  6:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13 20:14 [PATCH] ath11k: Fix some resource leaks in error path in 'ath11k_thermal_register()' Christophe JAILLET
2020-05-13 21:22 ` Rajkumar Manoharan
2020-05-19  6:56 ` 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).