lkml.org 
[lkml]   [2020]   [Nov]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] PCI: Fix pci_create_slot() memory leak
Date
After commit 8a94644b440e ("PCI: Fix pci_create_slot() reference count
leak"), kobject_put() is called instead of kfree() if
kobject_init_and_add() fails. However, we still need to free the slot
memory before overwriting it as ERR_PTR(err).

This partially reverts the commit 8a94644b440e.

Fixes: 8a94644b440e ("PCI: Fix pci_create_slot() reference count leak")
Signed-off-by: Jubin Zhong <zhongjubin@huawei.com>
---
drivers/pci/slot.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
index 3861505..a4be62e 100644
--- a/drivers/pci/slot.c
+++ b/drivers/pci/slot.c
@@ -268,7 +268,6 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
slot_name = make_slot_name(name);
if (!slot_name) {
err = -ENOMEM;
- kfree(slot);
goto err;
}

@@ -296,6 +295,7 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
mutex_unlock(&pci_slot_mutex);
return slot;
err:
+ kfree(slot);
slot = ERR_PTR(err);
goto out;
}
--
1.8.5.6
\
 
 \ /
  Last update: 2020-11-25 08:23    [W:0.026 / U:1.272 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site