On Tue, Mar 13, 2018 at 3:10 PM, Rafael J. Wysocki <rjw@xxxxxxxxxxxxx> wrote:
On Tuesday, March 13, 2018 9:55:30 AM CET Vivek Gautam wrote:
The lists managing the device-links can be traversed to
find the link between two devices. The device_link_add() APIs
does traverse these lists to check if there's already a link
setup between the two devices.
So, add a new APIs, device_link_find(), to find an existing
device link between two devices - suppliers and consumers.
Signed-off-by: Vivek Gautam <vivek.gautam@xxxxxxxxxxxxxx>
Cc: Rafael J. Wysocki <rjw@xxxxxxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
* New patch added to this series.
drivers/base/core.c | 30 +++++++++++++++++++++++++++---
include/linux/device.h | 2 ++
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 5847364f25d9..e8c9774e4ba2 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -144,6 +144,30 @@ static int device_reorder_to_tail(struct device *dev, void *not_used)
return 0;
}
+/**
+ * device_link_find - find any existing link between two devices.
+ * @consumer: Consumer end of the link.
+ * @supplier: Supplier end of the link.
+ *
+ * Returns pointer to the existing link between a supplier and
+ * and consumer devices, or NULL if no link exists.
+ */
+struct device_link *device_link_find(struct device *consumer,
+ struct device *supplier)
+{
+ struct device_link *link = NULL;
+
+ if (!consumer || !supplier)
+ return NULL;
+
+ list_for_each_entry(link, &supplier->links.consumers, s_node)
+ if (link->consumer == consumer)
+ break;
+
Any mutual exclusion?
Or is the caller expected to take care of it? And if so, then how?
I think it's better that we take care of lock here in the code rather
than depending
on the caller.
But i can't take device_links_write_lock() since device_link_add()
already takes that.