Skip to content

Commit

Permalink
PCI: Simplify pci_create_slot() logic
Browse files Browse the repository at this point in the history
Simplify pci_create_slot() by splitting an "if" statement into two parts.
In order to not duplicate error handling, add a new label to handle kobj
put.

Link: https://lore.kernel.org/r/20241004152240.7926-1-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
  • Loading branch information
Ilpo Järvinen authored and Bjorn Helgaas committed Oct 4, 2024
1 parent 2985b18 commit 3ca2589
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions drivers/pci/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,13 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
slot = get_slot(parent, slot_nr);
if (slot) {
if (hotplug) {
if ((err = slot->hotplug ? -EBUSY : 0)
|| (err = rename_slot(slot, name))) {
kobject_put(&slot->kobj);
slot = NULL;
goto err;
if (slot->hotplug) {
err = -EBUSY;
goto put_slot;
}
err = rename_slot(slot, name);
if (err)
goto put_slot;
}
goto out;
}
Expand Down Expand Up @@ -278,10 +279,8 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,

err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL,
"%s", slot_name);
if (err) {
kobject_put(&slot->kobj);
goto err;
}
if (err)
goto put_slot;

down_read(&pci_bus_sem);
list_for_each_entry(dev, &parent->devices, bus_list)
Expand All @@ -296,6 +295,9 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
kfree(slot_name);
mutex_unlock(&pci_slot_mutex);
return slot;

put_slot:
kobject_put(&slot->kobj);
err:
slot = ERR_PTR(err);
goto out;
Expand Down

0 comments on commit 3ca2589

Please sign in to comment.