pci_set_drvdata(pdev, adapter) is set as the last step of
idpf_cfg_device(), but its declared inverse, idpf_decfg_device(),
does not clear it. idpf_remove() open-codes the clear right after
calling idpf_decfg_device(), so the two functions are not true
opposites of each other.

Move the pci_set_drvdata(pdev, NULL) into idpf_decfg_device() so the
set/clear pairing lives in one place, and drop the now-redundant
explicit clear from idpf_remove(). idpf_decfg_device() is also called
from idpf_probe()'s err_init_wq unwind path, which did not previously
clear drvdata at all; it now does too, closing that window for
consistency with the rest of the teardown path. This has no
observable effect: the driver core already clears drvdata via
dev_set_drvdata() when a probe function returns an error, under
device_lock(), before any consumer of drvdata can observe a stale
pointer.

Reviewed-by: Przemek Kitszel <[email protected]>
Reviewed-by: Aleksandr Loktionov <[email protected]>
Signed-off-by: Paul Greenwalt <[email protected]>
---
 drivers/net/ethernet/intel/idpf/idpf_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/idpf/idpf_main.c 
b/drivers/net/ethernet/intel/idpf/idpf_main.c
index 1e4dd9b713a0..fc67d8f02569 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_main.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_main.c
@@ -112,6 +112,9 @@ static void idpf_decfg_device(struct idpf_adapter *adapter)
                pci_disable_ptm(pdev);
 
        libie_pci_unmap_all_mmio_regions(&adapter->ctlq_ctx.mmio_info);
+
+       /* pairs with pci_set_drvdata() in idpf_cfg_device() */
+       pci_set_drvdata(pdev, NULL);
 }
 
 /**
@@ -182,7 +185,6 @@ static void idpf_remove(struct pci_dev *pdev)
        mutex_destroy(&adapter->vc_buf_lock);
 
        idpf_decfg_device(adapter);
-       pci_set_drvdata(pdev, NULL);
        kfree(adapter);
 }
 
-- 
2.52.0

Reply via email to