device_links_read_unlock(idx);
 }
 
+static void device_link_rpm_prepare(struct device *consumer,
+                                   struct device *supplier)
+{
+       pm_runtime_new_link(consumer);
+       /*
+        * If the link is being added by the consumer driver at probe time,
+        * balance the decrementation of the supplier's runtime PM usage counter
+        * after consumer probe in driver_probe_device().
+        */
+       if (consumer->links.status == DL_DEV_PROBING)
+               pm_runtime_get_noresume(supplier);
+}
+
 /**
  * device_link_add - Create a link between two devices.
  * @consumer: Consumer end of the link.
                                    struct device *supplier, u32 flags)
 {
        struct device_link *link;
-       bool rpm_put_supplier = false;
 
        if (!consumer || !supplier ||
            (flags & DL_FLAG_STATELESS &&
                        pm_runtime_put_noidle(supplier);
                        return NULL;
                }
-               rpm_put_supplier = true;
        }
 
        device_links_write_lock();
                if (flags & DL_FLAG_AUTOREMOVE_SUPPLIER)
                        link->flags |= DL_FLAG_AUTOREMOVE_SUPPLIER;
 
+               if (flags & DL_FLAG_PM_RUNTIME) {
+                       if (!(link->flags & DL_FLAG_PM_RUNTIME)) {
+                               device_link_rpm_prepare(consumer, supplier);
+                               link->flags |= DL_FLAG_PM_RUNTIME;
+                       }
+                       if (flags & DL_FLAG_RPM_ACTIVE)
+                               refcount_inc(&link->rpm_active);
+               }
+
                kref_get(&link->kref);
                goto out;
        }
        if (!link)
                goto out;
 
+       refcount_set(&link->rpm_active, 1);
+
        if (flags & DL_FLAG_PM_RUNTIME) {
-               if (flags & DL_FLAG_RPM_ACTIVE) {
-                       link->rpm_active = true;
-                       rpm_put_supplier = false;
-               }
-               pm_runtime_new_link(consumer);
-               /*
-                * If the link is being added by the consumer driver at probe
-                * time, balance the decrementation of the supplier's runtime PM
-                * usage counter after consumer probe in driver_probe_device().
-                */
-               if (consumer->links.status == DL_DEV_PROBING)
-                       pm_runtime_get_noresume(supplier);
+               if (flags & DL_FLAG_RPM_ACTIVE)
+                       refcount_inc(&link->rpm_active);
+
+               device_link_rpm_prepare(consumer, supplier);
        }
+
        get_device(supplier);
        link->supplier = supplier;
        INIT_LIST_HEAD(&link->s_node);
        device_pm_unlock();
        device_links_write_unlock();
 
-       if (rpm_put_supplier)
+       if ((flags & DL_FLAG_PM_RUNTIME && flags & DL_FLAG_RPM_ACTIVE) && !link)
                pm_runtime_put(supplier);
 
        return link;
 
        list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) {
                int retval;
 
-               if (!(link->flags & DL_FLAG_PM_RUNTIME))
-                       continue;
-
-               if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND ||
-                   link->rpm_active)
+               if (!(link->flags & DL_FLAG_PM_RUNTIME) ||
+                   READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND)
                        continue;
 
                retval = pm_runtime_get_sync(link->supplier);
                        pm_runtime_put_noidle(link->supplier);
                        return retval;
                }
-               link->rpm_active = true;
+               refcount_inc(&link->rpm_active);
        }
        return 0;
 }
 {
        struct device_link *link;
 
-       list_for_each_entry_rcu(link, &dev->links.suppliers, c_node)
-               if (link->rpm_active &&
-                   READ_ONCE(link->status) != DL_STATE_SUPPLIER_UNBIND) {
+       list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) {
+               if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND)
+                       continue;
+
+               while (refcount_dec_not_one(&link->rpm_active))
                        pm_runtime_put(link->supplier);
-                       link->rpm_active = false;
-               }
+       }
 }
 
 /**
  *
  * Check links from this device to any consumers and if any of them have active
  * runtime PM references to the device, drop the usage counter of the device
- * (once per link).
+ * (as many times as needed).
  *
  * Links with the DL_FLAG_STATELESS flag set are ignored.
  *
                if (link->flags & DL_FLAG_STATELESS)
                        continue;
 
-               if (link->rpm_active) {
+               while (refcount_dec_not_one(&link->rpm_active))
                        pm_runtime_put_noidle(dev);
-                       link->rpm_active = false;
-               }
        }
 
        device_links_read_unlock(idx);