From 23095bd1c9c2805761bbac1cac99aa894c529ddc Mon Sep 17 00:00:00 2001 From: Kavi <15661106+kdaula@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:03:57 -0500 Subject: [PATCH] xen-pciback: free a device's config fields before its dev_data pcistub_device_release() frees dev_data and clears drvdata before calling xen_pcibk_config_free_dyn_fields() and xen_pcibk_config_free_dev(). Both look the fields up through drvdata, find NULL and return, so every release from pciback leaks the device's config field entries and their data. kmemleak reports them after the device is released. Free the fields first. Fixes: cd9db80e5257 ("xen/pciback: Support pci_reset_function, aka FLR or D3 support.") Signed-off-by: Kavi --- drivers/xen/xen-pciback/pci_stub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index d1a335233aab0c..59e8d10119f6b0 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c @@ -150,13 +150,13 @@ static void pcistub_device_release(struct kref *kref) /* Disable the device */ xen_pcibk_reset_device(dev); - kfree(dev_data); - pci_set_drvdata(dev, NULL); - - /* Clean-up the device */ + /* Clean-up the device. Both find the fields through drvdata. */ xen_pcibk_config_free_dyn_fields(dev); xen_pcibk_config_free_dev(dev); + kfree(dev_data); + pci_set_drvdata(dev, NULL); + pci_clear_dev_assigned(dev); pci_dev_put(dev);