driver core: Add device_link_remove function
authorpascal paillet <p.paillet@st.com>
Thu, 5 Jul 2018 14:25:56 +0000 (14:25 +0000)
committerMark Brown <broonie@kernel.org>
Thu, 5 Jul 2018 17:55:08 +0000 (18:55 +0100)
Device_link_remove uses the same arguments than device_link_add. The Goal
is to avoid storing the link pointer.

Signed-off-by: pascal paillet <p.paillet@st.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/core.c
include/linux/device.h

index 36622b52e419db9573c5cfb31f03bf740324e961..3b380b1f27682c9f90334e4b2c79ee79b61ef18d 100644 (file)
@@ -365,6 +365,36 @@ void device_link_del(struct device_link *link)
 }
 EXPORT_SYMBOL_GPL(device_link_del);
 
+/**
+ * device_link_remove - remove a link between two devices.
+ * @consumer: Consumer end of the link.
+ * @supplier: Supplier end of the link.
+ *
+ * The caller must ensure proper synchronization of this function with runtime
+ * PM.
+ */
+void device_link_remove(void *consumer, struct device *supplier)
+{
+       struct device_link *link;
+
+       if (WARN_ON(consumer == supplier))
+               return;
+
+       device_links_write_lock();
+       device_pm_lock();
+
+       list_for_each_entry(link, &supplier->links.consumers, s_node) {
+               if (link->consumer == consumer) {
+                       kref_put(&link->kref, __device_link_del);
+                       break;
+               }
+       }
+
+       device_pm_unlock();
+       device_links_write_unlock();
+}
+EXPORT_SYMBOL_GPL(device_link_remove);
+
 static void device_links_missing_supplier(struct device *dev)
 {
        struct device_link *link;
index 055a69dbcd18a8a5286d8e612fe16c1ae6245455..9c1c3b1d5e11cf0ddcf9f7d3151e8d9a285bcf35 100644 (file)
@@ -1316,6 +1316,7 @@ extern const char *dev_driver_string(const struct device *dev);
 struct device_link *device_link_add(struct device *consumer,
                                    struct device *supplier, u32 flags);
 void device_link_del(struct device_link *link);
+void device_link_remove(void *consumer, struct device *supplier);
 
 #ifdef CONFIG_PRINTK