From 729b260a67e051bcabdd83c8a29fc13c5617cd6b Mon Sep 17 00:00:00 2001
From: Johan Hovold <johan@hovoldconsulting.com>
Date: Wed, 25 Nov 2015 15:59:14 +0100
Subject: [PATCH] greybus: connection: add name field

Add a name field to connections that can be used in log messages.

A connection always belongs to a host-device (bus) and can be uniquely
identified by its host-device cport id, but include remote interface and
cport id nonetheless on the following format:

	<hd_cport_id>/<intf_id>:<cport_id>

The remote interface and cport id will be zero for static connections.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
---
 drivers/staging/greybus/connection.c | 17 +++++++++++++++++
 drivers/staging/greybus/connection.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index 3f2fe0103547..65d72b81ea8e 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -95,6 +95,21 @@ int svc_update_connection(struct gb_interface *intf,
 	return 0;
 }
 
+static void gb_connection_init_name(struct gb_connection *connection)
+{
+	u16 hd_cport_id = connection->hd_cport_id;
+	u16 cport_id = 0;
+	u8 intf_id = 0;
+
+	if (connection->intf) {
+		intf_id = connection->intf->interface_id;
+		cport_id = connection->intf_cport_id;
+	}
+
+	snprintf(connection->name, sizeof(connection->name),
+			"%hu/%hhu:%hu", hd_cport_id, intf_id, cport_id);
+}
+
 /*
  * gb_connection_create() - create a Greybus connection
  * @hd:			host device of the connection
@@ -179,6 +194,8 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
 
 	kref_init(&connection->kref);
 
+	gb_connection_init_name(connection);
+
 	spin_lock_irq(&gb_connections_lock);
 	list_add(&connection->hd_links, &hd->connections);
 
diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h
index 446ffe157a12..028f278b77e0 100644
--- a/drivers/staging/greybus/connection.h
+++ b/drivers/staging/greybus/connection.h
@@ -43,6 +43,7 @@ struct gb_connection {
 	enum gb_connection_state	state;
 	struct list_head		operations;
 
+	char				name[16];
 	struct workqueue_struct		*wq;
 
 	atomic_t			op_cycle;
-- 
2.30.9