* [PATCH] drivers: hwmon: fix ioremap and memremap leak
@ 2023-03-18 11:27 Tianyi Jing
2023-03-18 12:31 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Tianyi Jing @ 2023-03-18 11:27 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, iounmap and memunmap is added to line: 754. And the
declaration of 'version' is moved to xgene-hwmon.c:620 to help simplify
getting 'version' below.
Signed-off-by: Tianyi Jing <jingfelix@hust.edu.cn>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
---
drivers/hwmon/xgene-hwmon.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c
index 5cde837bfd09..44d1004ddacb 100644
--- a/drivers/hwmon/xgene-hwmon.c
+++ b/drivers/hwmon/xgene-hwmon.c
@@ -617,6 +617,7 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
struct xgene_hwmon_dev *ctx;
struct mbox_client *cl;
int rc;
+ int version;
ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
@@ -655,7 +656,6 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
} else {
struct pcc_mbox_chan *pcc_chan;
const struct acpi_device_id *acpi_id;
- int version;
acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
&pdev->dev);
@@ -749,8 +749,15 @@ static int xgene_hwmon_probe(struct platform_device *pdev)
out:
if (acpi_disabled)
mbox_free_channel(ctx->mbox_chan);
- else
+ else {
+ if (ctx->comm_base_addr && ctx->pcc_comm_addr) {
+ if (version == XGENE_HWMON_V2)
+ iounmap(ctx->pcc_comm_addr);
+ else
+ memunmap(ctx->pcc_comm_addr);
+ }
pcc_mbox_free_channel(ctx->pcc_chan);
+ }
out_mbox_free:
kfifo_free(&ctx->async_msg_fifo);
@@ -765,9 +772,22 @@ static int xgene_hwmon_remove(struct platform_device *pdev)
kfifo_free(&ctx->async_msg_fifo);
if (acpi_disabled)
mbox_free_channel(ctx->mbox_chan);
- else
- pcc_mbox_free_channel(ctx->pcc_chan);
+ else {
+ int version;
+ const struct acpi_device_id *acpi_id;
+ acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
+ &pdev->dev);
+
+ version = (int)acpi_id->driver_data;
+
+ if (version == XGENE_HWMON_V2)
+ iounmap(ctx->pcc_comm_addr);
+ else
+ memunmap(ctx->pcc_comm_addr);
+
+ pcc_mbox_free_channel(ctx->pcc_chan);
+ }
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drivers: hwmon: fix ioremap and memremap leak
2023-03-18 11:27 [PATCH] drivers: hwmon: fix ioremap and memremap leak Tianyi Jing
@ 2023-03-18 12:31 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2023-03-18 12:31 UTC (permalink / raw)
To: Tianyi Jing; +Cc: Jean Delvare, Dongliang Mu, linux-hwmon, linux-kernel
On Sat, Mar 18, 2023 at 07:27:11PM +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, iounmap and memunmap is added to line: 754. And the
> declaration of 'version' is moved to xgene-hwmon.c:620 to help simplify
> getting 'version' below.
>
> Signed-off-by: Tianyi Jing <jingfelix@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
Please just use devm_ioremap() and devm_memremap().
Thanks,
Guenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-18 12:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-18 11:27 [PATCH] drivers: hwmon: fix ioremap and memremap leak Tianyi Jing
2023-03-18 12:31 ` 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).