* [PATCH 1/1] PCI: Cleanup convoluted logic in pci_create_slot()
@ 2024-10-04 15:22 Ilpo Järvinen
2024-10-04 22:03 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Ilpo Järvinen @ 2024-10-04 15:22 UTC (permalink / raw)
To: Lukas Wunner, Krzysztof Wilczyński, Lorenzo Pieralisi,
Rob Herring, Bjorn Helgaas, linux-pci, linux-kernel
Cc: Ilpo Järvinen
pci_create_slot() has an if () which can be made simpler by splitting
it into two parts. In order to not duplicate error handling, add a new
label too to handle kobj put.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/slot.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
index 0f87cade10f7..9ac5a4f26794 100644
--- a/drivers/pci/slot.c
+++ b/drivers/pci/slot.c
@@ -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;
}
@@ -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)
@@ -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;
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] PCI: Cleanup convoluted logic in pci_create_slot()
2024-10-04 15:22 [PATCH 1/1] PCI: Cleanup convoluted logic in pci_create_slot() Ilpo Järvinen
@ 2024-10-04 22:03 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2024-10-04 22:03 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Lukas Wunner, Krzysztof Wilczyński, Lorenzo Pieralisi,
Rob Herring, Bjorn Helgaas, linux-pci, linux-kernel
On Fri, Oct 04, 2024 at 06:22:40PM +0300, Ilpo Järvinen wrote:
> pci_create_slot() has an if () which can be made simpler by splitting
> it into two parts. In order to not duplicate error handling, add a new
> label too to handle kobj put.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Applied to pci/misc for v6.13, thank you!
> ---
> drivers/pci/slot.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
> index 0f87cade10f7..9ac5a4f26794 100644
> --- a/drivers/pci/slot.c
> +++ b/drivers/pci/slot.c
> @@ -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;
> }
> @@ -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)
> @@ -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;
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-04 22:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-04 15:22 [PATCH 1/1] PCI: Cleanup convoluted logic in pci_create_slot() Ilpo Järvinen
2024-10-04 22:03 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).