[PATCH 6/8] greybus: make host API work without SVC

Damien Riégel posted 8 patches 1 month, 2 weeks ago
[PATCH 6/8] greybus: make host API work without SVC
Posted by Damien Riégel 1 month, 2 weeks ago
In preparation for an SVC-less topology, make host device API behaves
nicely if an SVC is not allocated.

Signed-off-by: Damien Riégel <damien.riegel@silabs.com>
---
 drivers/greybus/hd.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/greybus/hd.c b/drivers/greybus/hd.c
index 5de98d9177f..1e2f1f3a65f 100644
--- a/drivers/greybus/hd.c
+++ b/drivers/greybus/hd.c
@@ -45,11 +45,19 @@ static struct attribute *bus_attrs[] = {
 };
 ATTRIBUTE_GROUPS(bus);
 
+static bool gb_hd_is_p2p(struct gb_host_device *hd)
+{
+	return !hd->svc;
+}
+
 int gb_hd_cport_reserve(struct gb_host_device *hd, u16 cport_id)
 {
 	struct ida *id_map = &hd->cport_id_map;
 	int ret;
 
+	if (gb_hd_is_p2p(hd))
+		return -EPERM;
+
 	ret = ida_alloc_range(id_map, cport_id, cport_id, GFP_KERNEL);
 	if (ret < 0) {
 		dev_err(&hd->dev, "failed to reserve cport %u\n", cport_id);
@@ -64,6 +72,9 @@ void gb_hd_cport_release_reserved(struct gb_host_device *hd, u16 cport_id)
 {
 	struct ida *id_map = &hd->cport_id_map;
 
+	if (gb_hd_is_p2p(hd))
+		return;
+
 	ida_free(id_map, cport_id);
 }
 EXPORT_SYMBOL_GPL(gb_hd_cport_release_reserved);
@@ -205,10 +216,12 @@ int gb_hd_add(struct gb_host_device *hd)
 	if (ret)
 		return ret;
 
-	ret = gb_svc_add(hd->svc);
-	if (ret) {
-		device_del(&hd->dev);
-		return ret;
+	if (!gb_hd_is_p2p(hd)) {
+		ret = gb_svc_add(hd->svc);
+		if (ret) {
+			device_del(&hd->dev);
+			return ret;
+		}
 	}
 
 	trace_gb_hd_add(hd);
@@ -225,7 +238,8 @@ void gb_hd_del(struct gb_host_device *hd)
 	 * Tear down the svc and flush any on-going hotplug processing before
 	 * removing the remaining interfaces.
 	 */
-	gb_svc_del(hd->svc);
+	if (!gb_hd_is_p2p(hd))
+		gb_svc_del(hd->svc);
 
 	device_del(&hd->dev);
 }
@@ -233,7 +247,8 @@ EXPORT_SYMBOL_GPL(gb_hd_del);
 
 void gb_hd_shutdown(struct gb_host_device *hd)
 {
-	gb_svc_del(hd->svc);
+	if (!gb_hd_is_p2p(hd))
+		gb_svc_del(hd->svc);
 }
 EXPORT_SYMBOL_GPL(gb_hd_shutdown);
 
-- 
2.49.0