diff options
author | 2025-02-25 18:06:03 +0100 | |
---|---|---|
committer | 2025-03-04 17:00:12 -0600 | |
commit | 62460bcb5a2ac37bb416aada0167db3fe78ac385 (patch) | |
tree | 368e07466836fa0926de70ac53789cc7383a9b1a | |
parent | PCI: hotplug: Drop superfluous try_module_get() calls (diff) | |
download | wireguard-linux-62460bcb5a2ac37bb416aada0167db3fe78ac385.tar.xz wireguard-linux-62460bcb5a2ac37bb416aada0167db3fe78ac385.zip |
PCI: hotplug: Drop superfluous NULL pointer checks in has_*_file()
The PCI hotplug core contains five has_*_file() functions to determine
whether a certain sysfs file shall be added (or removed) for a given
hotplug slot.
The functions perform NULL pointer checks for the hotplug_slot and its
hotplug_slot_ops. However the callers already perform these checks:
pci_hp_register()
__pci_hp_register()
__pci_hp_initialize()
pci_hp_deregister()
pci_hp_del()
The only way to actually trigger these checks is to call pci_hp_add()
without having called pci_hp_initialize().
Amend pci_hp_add() to catch that and drop the now superfluous NULL
pointer checks in has_*_file().
Drop the same superfluous checks from pci_hp_create_module_link(),
which is (only) called from pci_hp_add().
Link: https://lore.kernel.org/r/37d1928edf8c3201a8b10794f1db3142e16e02b9.1740501868.git.lukas@wunner.de
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r-- | drivers/pci/hotplug/pci_hotplug_core.c | 17 | ||||
-rw-r--r-- | drivers/pci/slot.c | 2 |
2 files changed, 6 insertions, 13 deletions
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c index de5b501b40be..d4c12451570b 100644 --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c @@ -209,8 +209,6 @@ static bool has_power_file(struct pci_slot *pci_slot) { struct hotplug_slot *slot = pci_slot->hotplug; - if ((!slot) || (!slot->ops)) - return false; if ((slot->ops->enable_slot) || (slot->ops->disable_slot) || (slot->ops->get_power_status)) @@ -222,8 +220,6 @@ static bool has_attention_file(struct pci_slot *pci_slot) { struct hotplug_slot *slot = pci_slot->hotplug; - if ((!slot) || (!slot->ops)) - return false; if ((slot->ops->set_attention_status) || (slot->ops->get_attention_status)) return true; @@ -234,8 +230,6 @@ static bool has_latch_file(struct pci_slot *pci_slot) { struct hotplug_slot *slot = pci_slot->hotplug; - if ((!slot) || (!slot->ops)) - return false; if (slot->ops->get_latch_status) return true; return false; @@ -245,8 +239,6 @@ static bool has_adapter_file(struct pci_slot *pci_slot) { struct hotplug_slot *slot = pci_slot->hotplug; - if ((!slot) || (!slot->ops)) - return false; if (slot->ops->get_adapter_status) return true; return false; @@ -256,8 +248,6 @@ static bool has_test_file(struct pci_slot *pci_slot) { struct hotplug_slot *slot = pci_slot->hotplug; - if ((!slot) || (!slot->ops)) - return false; if (slot->ops->hardware_test) return true; return false; @@ -439,9 +429,14 @@ EXPORT_SYMBOL_GPL(__pci_hp_initialize); */ int pci_hp_add(struct hotplug_slot *slot) { - struct pci_slot *pci_slot = slot->pci_slot; + struct pci_slot *pci_slot; int result; + if (WARN_ON(!slot)) + return -EINVAL; + + pci_slot = slot->pci_slot; + result = fs_add_slot(pci_slot); if (result) return result; diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c index 36b44be0489d..dd6e80b7db09 100644 --- a/drivers/pci/slot.c +++ b/drivers/pci/slot.c @@ -340,8 +340,6 @@ void pci_hp_create_module_link(struct pci_slot *pci_slot) struct kobject *kobj = NULL; int ret; - if (!slot || !slot->ops) - return; kobj = kset_find_obj(module_kset, slot->mod_name); if (!kobj) return; |