vmd: extract freeing device resources to vmd_dev_free
This allows to free resources tied to a vmd_pci_device that isn't on the dev_list or wasn't hooked to the PCI driver. Also, use that function whenever a vmd_pci_device is freed instead of regular free(). Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com> Change-Id: Ifca177a7eb6d8180d6f2ee2a9d9e36d58810e8ad Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14259 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tom Nabarro <tom.nabarro@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
3f4e968dab
commit
ac8b65bdd2
@ -840,21 +840,16 @@ vmd_dev_cfg_write(struct spdk_pci_device *_dev, void *value,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vmd_dev_detach(struct spdk_pci_device *dev)
|
vmd_dev_free(struct vmd_pci_device *dev)
|
||||||
{
|
{
|
||||||
struct vmd_pci_device *vmd_device = (struct vmd_pci_device *)dev;
|
struct vmd_pci_device *bus_device = dev->bus->self;
|
||||||
struct vmd_pci_device *bus_device = vmd_device->bus->self;
|
size_t i, num_bars = dev->header_type ? 2 : 6;
|
||||||
struct vmd_pci_bus *bus = vmd_device->bus;
|
|
||||||
size_t i, num_bars = vmd_device->header_type ? 2 : 6;
|
|
||||||
|
|
||||||
spdk_pci_unhook_device(dev);
|
|
||||||
TAILQ_REMOVE(&bus->dev_list, vmd_device, tailq);
|
|
||||||
|
|
||||||
/* Release the hotplug region if the device is under hotplug-capable bus */
|
/* Release the hotplug region if the device is under hotplug-capable bus */
|
||||||
if (bus_device && bus_device->hotplug_capable) {
|
if (bus_device && bus_device->hotplug_capable) {
|
||||||
for (i = 0; i < num_bars; ++i) {
|
for (i = 0; i < num_bars; ++i) {
|
||||||
if (vmd_device->bar[i].start != 0) {
|
if (dev->bar[i].start != 0) {
|
||||||
vmd_hotplug_free_addr(&bus_device->hp, vmd_device->bar[i].start);
|
vmd_hotplug_free_addr(&bus_device->hp, dev->bar[i].start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -862,6 +857,18 @@ vmd_dev_detach(struct spdk_pci_device *dev)
|
|||||||
free(dev);
|
free(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vmd_dev_detach(struct spdk_pci_device *dev)
|
||||||
|
{
|
||||||
|
struct vmd_pci_device *vmd_device = (struct vmd_pci_device *)dev;
|
||||||
|
struct vmd_pci_bus *bus = vmd_device->bus;
|
||||||
|
|
||||||
|
spdk_pci_unhook_device(dev);
|
||||||
|
TAILQ_REMOVE(&bus->dev_list, vmd_device, tailq);
|
||||||
|
|
||||||
|
vmd_dev_free(vmd_device);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vmd_dev_init(struct vmd_pci_device *dev)
|
vmd_dev_init(struct vmd_pci_device *dev)
|
||||||
{
|
{
|
||||||
@ -962,12 +969,12 @@ vmd_scan_single_bus(struct vmd_pci_bus *bus, struct vmd_pci_device *parent_bridg
|
|||||||
|
|
||||||
new_bus_num = vmd_get_next_bus_number(bus->vmd->is_hotplug_scan ? new_dev : NULL, bus->vmd);
|
new_bus_num = vmd_get_next_bus_number(bus->vmd->is_hotplug_scan ? new_dev : NULL, bus->vmd);
|
||||||
if (new_bus_num == 0xff) {
|
if (new_bus_num == 0xff) {
|
||||||
free(new_dev);
|
vmd_dev_free(new_dev);
|
||||||
return dev_cnt;
|
return dev_cnt;
|
||||||
}
|
}
|
||||||
new_bus = vmd_create_new_bus(bus, new_dev, new_bus_num);
|
new_bus = vmd_create_new_bus(bus, new_dev, new_bus_num);
|
||||||
if (!new_bus) {
|
if (!new_bus) {
|
||||||
free(new_dev);
|
vmd_dev_free(new_dev);
|
||||||
return dev_cnt;
|
return dev_cnt;
|
||||||
}
|
}
|
||||||
new_bus->primary_bus = bus->secondary_bus;
|
new_bus->primary_bus = bus->secondary_bus;
|
||||||
@ -1010,7 +1017,7 @@ vmd_scan_single_bus(struct vmd_pci_bus *bus, struct vmd_pci_device *parent_bridg
|
|||||||
} else {
|
} else {
|
||||||
rc = vmd_init_end_device(new_dev);
|
rc = vmd_init_end_device(new_dev);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
free(new_dev);
|
vmd_dev_free(new_dev);
|
||||||
if (dev_cnt) {
|
if (dev_cnt) {
|
||||||
dev_cnt--;
|
dev_cnt--;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user