[PATCH 2/7] greybus: connection: Add gb_connection_hd_find_by_intf()

From: Ayush Singh

Date: Thu Aug 20 2026 - 05:27:27 EST


gb_connection_hd_find() looks up a connection on a host device by its
host-side CPort id. Callers that only know the remote end of a
connection (the interface id and the CPort id) have no way to find it.

Add gb_connection_hd_find_by_intf(), which walks the host device's
connection list and returns a reference-counted pointer to the matching
connection, or NULL if there is none. The caller is responsible for
dropping the reference with gb_connection_put(). The first user is
gb-softsvc driver, added later in this series.

Signed-off-by: Ayush Singh <ayush@xxxxxxxxxxxxxxx>
---
drivers/greybus/connection.c | 22 ++++++++++++++++++++++
include/linux/greybus/connection.h | 3 +++
2 files changed, 25 insertions(+)

diff --git a/drivers/greybus/connection.c b/drivers/greybus/connection.c
index f8fda22bc466..262161fa4721 100644
--- a/drivers/greybus/connection.c
+++ b/drivers/greybus/connection.c
@@ -71,6 +71,28 @@ gb_connection_hd_find(struct gb_host_device *hd, u16 cport_id)
return connection;
}

+struct gb_connection *gb_connection_hd_find_by_intf(struct gb_host_device *hd,
+ u8 intf_id, u16 intf_cport)
+{
+ struct gb_connection *connection;
+ unsigned long flags;
+
+ spin_lock_irqsave(&gb_connections_lock, flags);
+ list_for_each_entry(connection, &hd->connections, hd_links) {
+ if (connection->intf->interface_id == intf_id &&
+ connection->intf_cport_id == intf_cport) {
+ gb_connection_get(connection);
+ goto found;
+ }
+ }
+ connection = NULL;
+found:
+ spin_unlock_irqrestore(&gb_connections_lock, flags);
+
+ return connection;
+}
+EXPORT_SYMBOL_GPL(gb_connection_hd_find_by_intf);
+
/*
* Callback from the host driver to let us know that data has been
* received on the bundle.
diff --git a/include/linux/greybus/connection.h b/include/linux/greybus/connection.h
index b53aad2270d6..589721d46015 100644
--- a/include/linux/greybus/connection.h
+++ b/include/linux/greybus/connection.h
@@ -131,4 +131,7 @@ static inline void gb_connection_set_data(struct gb_connection *connection,
void gb_connection_get(struct gb_connection *connection);
void gb_connection_put(struct gb_connection *connection);

+struct gb_connection *gb_connection_hd_find_by_intf(struct gb_host_device *hd,
+ u8 intf_id, u16 intf_cport);
+
#endif /* __CONNECTION_H */

--
2.55.0