diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 503c01d4015dcb5af74d78bb8677ecb622fe0099..1e8318acf621863b075cb22434bea54b0b456fe5 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1187,8 +1187,6 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 		else if (drv->remove)
 			drv->remove(dev);
 
-		device_links_driver_cleanup(dev);
-
 		devres_release_all(dev);
 		arch_teardown_dma_ops(dev);
 		kfree(dev->dma_range_map);
@@ -1200,6 +1198,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 		pm_runtime_reinit(dev);
 		dev_pm_set_driver_flags(dev, 0);
 
+		device_links_driver_cleanup(dev);
+
 		klist_remove(&dev->p->knode_driver);
 		device_pm_check_callbacks(dev);
 		if (dev->bus)