Skip to content

Commit

Permalink
applicom: Fix PCI device refcount leak in applicom_init()
Browse files Browse the repository at this point in the history
As comment of pci_get_class() says, it returns a pci_device with its
refcount increased and decreased the refcount for the input parameter
@from if it is not NULL.

If we break the loop in applicom_init() with 'dev' not NULL, we need to
call pci_dev_put() to decrease the refcount. Add the missing
pci_dev_put() to avoid refcount leak.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Link: https://lore.kernel.org/r/20221122114035.24194-1-wangxiongfeng2@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
fenghusthu authored and gregkh committed Jan 20, 2023
1 parent cd0ac51 commit ce4273d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/char/applicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ static int __init applicom_init(void)
if (!pci_match_id(applicom_pci_tbl, dev))
continue;

if (pci_enable_device(dev))
if (pci_enable_device(dev)) {
pci_dev_put(dev);
return -EIO;
}

RamIO = ioremap(pci_resource_start(dev, 0), LEN_RAM_IO);

Expand All @@ -207,6 +209,7 @@ static int __init applicom_init(void)
"space at 0x%llx\n",
(unsigned long long)pci_resource_start(dev, 0));
pci_disable_device(dev);
pci_dev_put(dev);
return -EIO;
}

Expand Down

0 comments on commit ce4273d

Please sign in to comment.