linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drivers: hwmon: fix ioremap and memremap leak
@ 2023-03-18 14:38 Tianyi Jing
  2023-03-21 14:52 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Tianyi Jing @ 2023-03-18 14:38 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck
  Cc: Tianyi Jing, Dongliang Mu, linux-hwmon, linux-kernel

Smatch reports:

drivers/hwmon/xgene-hwmon.c:757 xgene_hwmon_probe() warn:
'ctx->pcc_comm_addr' from ioremap() not released on line: 757.

This is because in drivers/hwmon/xgene-hwmon.c:701 xgene_hwmon_probe(),
ioremap and memremap is not released, which may cause a leak.

To fix this, ioremap and memremap is modified to devm_ioremap and
devm_memremap.

Signed-off-by: Tianyi Jing <jingfelix@hust.edu.cn>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
---
v1 -> v2: use devm_ioremap and devm_memremap instead.
 drivers/hwmon/xgene-hwmon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
index 5cde837bfd09..a25fae9b19b7 100644
--- a/drivers/hwmon/xgene-hwmon.c
+++ b/drivers/hwmon/xgene-hwmon.c
@@ -698,11 +698,13 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
 		ctx->comm_base_addr = pcc_chan->shmem_base_addr;
 		if (ctx->comm_base_addr) {
 			if (version == XGENE_HWMON_V2)
-				ctx->pcc_comm_addr = (void __force *)ioremap(
+				ctx->pcc_comm_addr = (void __force *)devm_ioremap(
+							&pdev->dev,
 							ctx->comm_base_addr,
 							pcc_chan->shmem_size);
 			else
-				ctx->pcc_comm_addr = memremap(
+				ctx->pcc_comm_addr = devm_memremap(
+							&pdev->dev,
 							ctx->comm_base_addr,
 							pcc_chan->shmem_size,
 							MEMREMAP_WB);
-- 
2.34.1


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

* Re: [PATCH v2] drivers: hwmon: fix ioremap and memremap leak
  2023-03-18 14:38 [PATCH v2] drivers: hwmon: fix ioremap and memremap leak Tianyi Jing
@ 2023-03-21 14:52 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2023-03-21 14:52 UTC (permalink / raw)
  To: Tianyi Jing; +Cc: Jean Delvare, Dongliang Mu, linux-hwmon, linux-kernel

On Sat, Mar 18, 2023 at 10:38:51PM +0800, Tianyi Jing wrote:
> Smatch reports:
> 
> drivers/hwmon/xgene-hwmon.c:757 xgene_hwmon_probe() warn:
> 'ctx->pcc_comm_addr' from ioremap() not released on line: 757.
> 
> This is because in drivers/hwmon/xgene-hwmon.c:701 xgene_hwmon_probe(),
> ioremap and memremap is not released, which may cause a leak.
> 
> To fix this, ioremap and memremap is modified to devm_ioremap and
> devm_memremap.
> 
> Signed-off-by: Tianyi Jing <jingfelix@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>

Applied. Note that I updated the subject and changed formatting a bit.

Guenter

> ---
> v1 -> v2: use devm_ioremap and devm_memremap instead.
>  drivers/hwmon/xgene-hwmon.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
> index 5cde837bfd09..a25fae9b19b7 100644
> --- a/drivers/hwmon/xgene-hwmon.c
> +++ b/drivers/hwmon/xgene-hwmon.c
> @@ -698,11 +698,13 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
>  		ctx->comm_base_addr = pcc_chan->shmem_base_addr;
>  		if (ctx->comm_base_addr) {
>  			if (version == XGENE_HWMON_V2)
> -				ctx->pcc_comm_addr = (void __force *)ioremap(
> +				ctx->pcc_comm_addr = (void __force *)devm_ioremap(
> +							&pdev->dev,
>  							ctx->comm_base_addr,
>  							pcc_chan->shmem_size);
>  			else
> -				ctx->pcc_comm_addr = memremap(
> +				ctx->pcc_comm_addr = devm_memremap(
> +							&pdev->dev,
>  							ctx->comm_base_addr,
>  							pcc_chan->shmem_size,
>  							MEMREMAP_WB);

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

end of thread, other threads:[~2023-03-21 14:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-18 14:38 [PATCH v2] drivers: hwmon: fix ioremap and memremap leak Tianyi Jing
2023-03-21 14:52 ` Guenter Roeck

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).