i2c: piix4: Fix a memory leak in the EFCH MMIO support

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>
Reviewed-by: Terry Bowman <terry.bowman@amd.com>
Tested-by: Terry Bowman <Terry.Bowman@amd.com>
Fixes: 7c148722d0 ("i2c: piix4: Add EFCH MMIO support to region request and release")
Signed-off-by: Wolfram Sang <wsa@kernel.org>
This commit is contained in:
Jean Delvare 2022-06-22 08:37:43 +02:00 коммит произвёл Wolfram Sang
Родитель 03c765b0e3
Коммит 8ad59b397f
1 изменённых файлов: 7 добавлений и 9 удалений

Просмотреть файл

@ -161,7 +161,6 @@ static const char *piix4_aux_port_name_sb800 = " port 1";
struct sb800_mmio_cfg { struct sb800_mmio_cfg {
void __iomem *addr; void __iomem *addr;
struct resource *res;
bool use_mmio; bool use_mmio;
}; };
@ -179,13 +178,11 @@ static int piix4_sb800_region_request(struct device *dev,
struct sb800_mmio_cfg *mmio_cfg) struct sb800_mmio_cfg *mmio_cfg)
{ {
if (mmio_cfg->use_mmio) { if (mmio_cfg->use_mmio) {
struct resource *res;
void __iomem *addr; void __iomem *addr;
res = request_mem_region_muxed(SB800_PIIX4_FCH_PM_ADDR, if (!request_mem_region_muxed(SB800_PIIX4_FCH_PM_ADDR,
SB800_PIIX4_FCH_PM_SIZE, SB800_PIIX4_FCH_PM_SIZE,
"sb800_piix4_smb"); "sb800_piix4_smb")) {
if (!res) {
dev_err(dev, dev_err(dev,
"SMBus base address memory region 0x%x already in use.\n", "SMBus base address memory region 0x%x already in use.\n",
SB800_PIIX4_FCH_PM_ADDR); SB800_PIIX4_FCH_PM_ADDR);
@ -195,12 +192,12 @@ static int piix4_sb800_region_request(struct device *dev,
addr = ioremap(SB800_PIIX4_FCH_PM_ADDR, addr = ioremap(SB800_PIIX4_FCH_PM_ADDR,
SB800_PIIX4_FCH_PM_SIZE); SB800_PIIX4_FCH_PM_SIZE);
if (!addr) { 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"); dev_err(dev, "SMBus base address mapping failed.\n");
return -ENOMEM; return -ENOMEM;
} }
mmio_cfg->res = res;
mmio_cfg->addr = addr; mmio_cfg->addr = addr;
return 0; return 0;
@ -222,7 +219,8 @@ static void piix4_sb800_region_release(struct device *dev,
{ {
if (mmio_cfg->use_mmio) { if (mmio_cfg->use_mmio) {
iounmap(mmio_cfg->addr); iounmap(mmio_cfg->addr);
release_resource(mmio_cfg->res); release_mem_region(SB800_PIIX4_FCH_PM_ADDR,
SB800_PIIX4_FCH_PM_SIZE);
return; return;
} }