treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / pci / hotplug / shpchp_pci.c
blob11570130148769dfe0e1f061b03d9b2e4392f9e8
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Standard Hot Plug Controller Driver
5 * Copyright (C) 1995,2001 Compaq Computer Corporation
6 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
7 * Copyright (C) 2001 IBM Corp.
8 * Copyright (C) 2003-2004 Intel Corporation
10 * All rights reserved.
12 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/pci.h>
20 #include "../pci.h"
21 #include "shpchp.h"
23 int shpchp_configure_device(struct slot *p_slot)
25 struct pci_dev *dev;
26 struct controller *ctrl = p_slot->ctrl;
27 struct pci_dev *bridge = ctrl->pci_dev;
28 struct pci_bus *parent = bridge->subordinate;
29 int num, ret = 0;
31 pci_lock_rescan_remove();
33 dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, 0));
34 if (dev) {
35 ctrl_err(ctrl, "Device %s already exists at %04x:%02x:%02x, cannot hot-add\n",
36 pci_name(dev), pci_domain_nr(parent),
37 p_slot->bus, p_slot->device);
38 pci_dev_put(dev);
39 ret = -EINVAL;
40 goto out;
43 num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0));
44 if (num == 0) {
45 ctrl_err(ctrl, "No new device found\n");
46 ret = -ENODEV;
47 goto out;
50 for_each_pci_bridge(dev, parent) {
51 if (PCI_SLOT(dev->devfn) == p_slot->device)
52 pci_hp_add_bridge(dev);
55 pci_assign_unassigned_bridge_resources(bridge);
56 pcie_bus_configure_settings(parent);
57 pci_bus_add_devices(parent);
59 out:
60 pci_unlock_rescan_remove();
61 return ret;
64 int shpchp_unconfigure_device(struct slot *p_slot)
66 int rc = 0;
67 struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate;
68 struct pci_dev *dev, *temp;
69 struct controller *ctrl = p_slot->ctrl;
71 ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:%02x\n",
72 __func__, pci_domain_nr(parent), p_slot->bus, p_slot->device);
74 pci_lock_rescan_remove();
76 list_for_each_entry_safe(dev, temp, &parent->devices, bus_list) {
77 if (PCI_SLOT(dev->devfn) != p_slot->device)
78 continue;
80 pci_dev_get(dev);
81 pci_stop_and_remove_bus_device(dev);
82 pci_dev_put(dev);
85 pci_unlock_rescan_remove();
86 return rc;