mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
To: <rjw@rjwysocki.net>, <lenb@kernel.org>, <bhelgaas@google.com>
Cc: <linux-acpi@vger.kernel.org>, <linux-pci@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linfeilong <linfeilong@huawei.com>, <liuzhiqiang26@huawei.com>
Subject: [PATCH v2] ACPI / hotplug / PCI: fix memory leak in enable_slot()
Date: Thu, 25 Mar 2021 15:26:00 +0800	[thread overview]
Message-ID: <b411af88-5049-a1c6-83ac-d104a1f429be@huawei.com> (raw)

From: Feilong Lin <linfeilong@huawei.com>

In enable_slot() in drivers/pci/hotplug/acpiphp_glue.c, if pci_get_slot()
will return NULL, we will do not set SLOT_ENABLED flag of slot. if one
device is found by calling pci_get_slot(), its reference count will be
increased. In this case, we did not call pci_dev_put() to decrement the
its reference count, the memory of the device (struct pci_dev type) will
leak.

Fix it by calling pci_dev_put() to decrement its reference count after that
pci_get_slot() returns a PCI device.

Signed-off-by: Feilong Lin <linfeilong@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
--
v2: rewrite subject and commit log as suggested by Bjorn Helgaas.
---
 drivers/pci/hotplug/acpiphp_glue.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 3365c93abf0e..f031302ad401 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
 			slot->flags &= ~SLOT_ENABLED;
 			continue;
 		}
+		pci_dev_put(dev);
 	}
 }

-- 
2.19.1


             reply	other threads:[~2021-03-25  7:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25  7:26 Zhiqiang Liu [this message]
2021-04-08 15:18 ` Rafael J. Wysocki
2021-04-08 15:25   ` Bjorn Helgaas
2021-04-08 16:19 ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b411af88-5049-a1c6-83ac-d104a1f429be@huawei.com \
    --to=liuzhiqiang26@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=lenb@kernel.org \
    --cc=linfeilong@huawei.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®