Skip to content

Commit 3ca2589

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Simplify pci_create_slot() logic
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/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 2985b18 commit 3ca2589

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

drivers/pci/slot.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,13 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
244244
slot = get_slot(parent, slot_nr);
245245
if (slot) {
246246
if (hotplug) {
247-
if ((err = slot->hotplug ? -EBUSY : 0)
248-
|| (err = rename_slot(slot, name))) {
249-
kobject_put(&slot->kobj);
250-
slot = NULL;
251-
goto err;
247+
if (slot->hotplug) {
248+
err = -EBUSY;
249+
goto put_slot;
252250
}
251+
err = rename_slot(slot, name);
252+
if (err)
253+
goto put_slot;
253254
}
254255
goto out;
255256
}
@@ -278,10 +279,8 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
278279

279280
err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL,
280281
"%s", slot_name);
281-
if (err) {
282-
kobject_put(&slot->kobj);
283-
goto err;
284-
}
282+
if (err)
283+
goto put_slot;
285284

286285
down_read(&pci_bus_sem);
287286
list_for_each_entry(dev, &parent->devices, bus_list)
@@ -296,6 +295,9 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
296295
kfree(slot_name);
297296
mutex_unlock(&pci_slot_mutex);
298297
return slot;
298+
299+
put_slot:
300+
kobject_put(&slot->kobj);
299301
err:
300302
slot = ERR_PTR(err);
301303
goto out;

0 commit comments

Comments
 (0)