PCI: Fix pci_create_slot() reference count leak
authorQiushi Wu <wu000273@umn.edu>
Thu, 28 May 2020 02:13:22 +0000 (21:13 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Sep 2020 09:21:17 +0000 (11:21 +0200)
commite840d01d940e7192877a062f5176276795b4c51d
tree8910fb10477bf0ca2e0c1bbade6dbb364f5bc342
parentbb3a2d575e1d46f91e841505c9b25646e5a50efc
PCI: Fix pci_create_slot() reference count leak

[ Upstream commit 8a94644b440eef5a7b9c104ac8aa7a7f413e35e5 ]

kobject_init_and_add() takes a reference even when it fails.  If it returns
an error, kobject_put() must be called to clean up the memory associated
with the object.

When kobject_init_and_add() fails, call kobject_put() instead of kfree().

b8eb718348b8 ("net-sysfs: Fix reference count leak in
rx|netdev_queue_add_kobject") fixed a similar problem.

Link: https://lore.kernel.org/r/20200528021322.1984-1-wu000273@umn.edu
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pci/slot.c