* of the link.  If DL_FLAG_PM_RUNTIME is not set, DL_FLAG_RPM_ACTIVE will be
  * ignored.
  *
- * If the DL_FLAG_AUTOREMOVE_CONSUMER is set, the link will be removed
- * automatically when the consumer device driver unbinds from it.
- * The combination of both DL_FLAG_AUTOREMOVE_CONSUMER and DL_FLAG_STATELESS
- * set is invalid and will cause NULL to be returned.
+ * If the DL_FLAG_AUTOREMOVE_CONSUMER flag is set, the link will be removed
+ * automatically when the consumer device driver unbinds from it.  Analogously,
+ * if DL_FLAG_AUTOREMOVE_SUPPLIER is set in @flags, the link will be removed
+ * automatically when the supplier device driver unbinds from it.
+ *
+ * The combination of DL_FLAG_STATELESS and either DL_FLAG_AUTOREMOVE_CONSUMER
+ * or DL_FLAG_AUTOREMOVE_SUPPLIER set in @flags at the same time is invalid and
+ * will cause NULL to be returned upfront.
  *
  * A side effect of the link creation is re-ordering of dpm_list and the
  * devices_kset list by moving the consumer device and all devices depending
        struct device_link *link;
 
        if (!consumer || !supplier ||
-           ((flags & DL_FLAG_STATELESS) &&
-            (flags & DL_FLAG_AUTOREMOVE_CONSUMER)))
+           (flags & DL_FLAG_STATELESS &&
+            flags & (DL_FLAG_AUTOREMOVE_CONSUMER | DL_FLAG_AUTOREMOVE_SUPPLIER)))
                return NULL;
 
        device_links_write_lock();
  */
 void device_links_driver_cleanup(struct device *dev)
 {
-       struct device_link *link;
+       struct device_link *link, *ln;
 
        device_links_write_lock();
 
-       list_for_each_entry(link, &dev->links.consumers, s_node) {
+       list_for_each_entry_safe(link, ln, &dev->links.consumers, s_node) {
                if (link->flags & DL_FLAG_STATELESS)
                        continue;