* [PATCH v2] i2c: piix4: Fix a memory leak in the EFCH MMIO support
@ 2022-06-22 6:37 Jean Delvare
2022-06-29 19:37 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Jean Delvare @ 2022-06-22 6:37 UTC (permalink / raw)
To: Linux I2C; +Cc: Yi Zhang, Terry Bowman, Wolfram Sang
The recently added support for EFCH MMIO regions introduced a memory
leak in that code path. The leak is caused by the fact that
release_resource() merely removes the resource from the tree but does
not free its memory. We need to call release_mem_region() instead,
which does free the memory. As a nice side effect, this brings back
some symmetry between the legacy and MMIO paths.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Tested-by: Yi Zhang <yi.zhang@redhat.com>
Fixes: 7c148722d074 ("i2c: piix4: Add EFCH MMIO support to region request and release")
Cc: Terry Bowman <terry.bowman@amd.com>
---
Changes since v1:
* Added Reported-by and Tested-by tags for Yi Zhang
* Removed local variable res as it is not needed
Technically this isn't the patch Yi Zhang tested, but I verified that
the generated binary code is the same, so it is safe to keep the
Tested-by tag.
drivers/i2c/busses/i2c-piix4.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
--- linux-5.18.orig/drivers/i2c/busses/i2c-piix4.c 2022-06-21 16:17:35.040806444 +0200
+++ linux-5.18/drivers/i2c/busses/i2c-piix4.c 2022-06-21 23:07:52.605179908 +0200
@@ -161,7 +161,6 @@ static const char *piix4_aux_port_name_s
struct sb800_mmio_cfg {
void __iomem *addr;
- struct resource *res;
bool use_mmio;
};
@@ -179,13 +178,11 @@ static int piix4_sb800_region_request(st
struct sb800_mmio_cfg *mmio_cfg)
{
if (mmio_cfg->use_mmio) {
- struct resource *res;
void __iomem *addr;
- res = request_mem_region_muxed(SB800_PIIX4_FCH_PM_ADDR,
- SB800_PIIX4_FCH_PM_SIZE,
- "sb800_piix4_smb");
- if (!res) {
+ if (!request_mem_region_muxed(SB800_PIIX4_FCH_PM_ADDR,
+ SB800_PIIX4_FCH_PM_SIZE,
+ "sb800_piix4_smb")) {
dev_err(dev,
"SMBus base address memory region 0x%x already in use.\n",
SB800_PIIX4_FCH_PM_ADDR);
@@ -195,12 +192,12 @@ static int piix4_sb800_region_request(st
addr = ioremap(SB800_PIIX4_FCH_PM_ADDR,
SB800_PIIX4_FCH_PM_SIZE);
if (!addr) {
- release_resource(res);
+ release_mem_region(SB800_PIIX4_FCH_PM_ADDR,
+ SB800_PIIX4_FCH_PM_SIZE);
dev_err(dev, "SMBus base address mapping failed.\n");
return -ENOMEM;
}
- mmio_cfg->res = res;
mmio_cfg->addr = addr;
return 0;
@@ -222,7 +219,8 @@ static void piix4_sb800_region_release(s
{
if (mmio_cfg->use_mmio) {
iounmap(mmio_cfg->addr);
- release_resource(mmio_cfg->res);
+ release_mem_region(SB800_PIIX4_FCH_PM_ADDR,
+ SB800_PIIX4_FCH_PM_SIZE);
return;
}
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] i2c: piix4: Fix a memory leak in the EFCH MMIO support
2022-06-22 6:37 [PATCH v2] i2c: piix4: Fix a memory leak in the EFCH MMIO support Jean Delvare
@ 2022-06-29 19:37 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2022-06-29 19:37 UTC (permalink / raw)
To: Jean Delvare; +Cc: Linux I2C, Yi Zhang, Terry Bowman
[-- Attachment #1: Type: text/plain, Size: 811 bytes --]
On Wed, Jun 22, 2022 at 08:37:43AM +0200, Jean Delvare wrote:
> The recently added support for EFCH MMIO regions introduced a memory
> leak in that code path. The leak is caused by the fact that
> release_resource() merely removes the resource from the tree but does
> not free its memory. We need to call release_mem_region() instead,
> which does free the memory. As a nice side effect, this brings back
> some symmetry between the legacy and MMIO paths.
>
> Signed-off-by: Jean Delvare <jdelvare@suse.de>
> Reported-by: Yi Zhang <yi.zhang@redhat.com>
> Tested-by: Yi Zhang <yi.zhang@redhat.com>
> Fixes: 7c148722d074 ("i2c: piix4: Add EFCH MMIO support to region request and release")
> Cc: Terry Bowman <terry.bowman@amd.com>
Applied to for-current with Terry's tags given to v1, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-29 19:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-22 6:37 [PATCH v2] i2c: piix4: Fix a memory leak in the EFCH MMIO support Jean Delvare
2022-06-29 19:37 ` Wolfram Sang
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).