summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorAlex Elder <elder@linaro.org>2015-06-13 11:02:10 -0500
committerGreg Kroah-Hartman <gregkh@google.com>2015-06-15 16:49:00 -0700
commit88d18a975ddac4fa849909c2ae178b0c126f7f8e (patch)
treec325e9983735460f0d232d968352a861dab9c5b4 /drivers
parentfb690ca96f9a7aff8bc8135ce23606e243f4cbae (diff)
greybus: reserve host cport id 0
For ES1 and ES2, we use pad bytes in an operation message header to encode the CPort ID used for transferring the message. The pad bytes should otherwise be zero, and we ensure this as the message is passed to or from the upper layer. If host-side CPort ID 0 is used, we have no way of knowing whether the CPort field has been "packed" into the header. To allow detection of this, reserve host CPort id 0. Update cport_id_valid() to treat 0 as invalid. (CPort ID 0 is reserved by one of the UniPro standards. We'll assume for now that we never use it for Greybus.) Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/greybus/core.c10
-rw-r--r--drivers/staging/greybus/greybus.h2
2 files changed, 10 insertions, 2 deletions
diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c
index d4fffecb1abc..bc9c1ebf7983 100644
--- a/drivers/staging/greybus/core.c
+++ b/drivers/staging/greybus/core.c
@@ -170,6 +170,7 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver
size_t buffer_size_max)
{
struct greybus_host_device *hd;
+ int ret;
/*
* Validate that the driver implements all of the callbacks
@@ -200,12 +201,19 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver
if (!hd)
return ERR_PTR(-ENOMEM);
+ ida_init(&hd->cport_id_map);
+ /* Reserve CPort id 0 */
+ ret = ida_simple_get(&hd->cport_id_map, 0, 1, GFP_KERNEL);
+ if (ret < 0) {
+ kfree(hd);
+ return ERR_PTR(ret);
+ }
+
kref_init(&hd->kref);
hd->parent = parent;
hd->driver = driver;
INIT_LIST_HEAD(&hd->interfaces);
INIT_LIST_HEAD(&hd->connections);
- ida_init(&hd->cport_id_map);
hd->buffer_size_max = buffer_size_max;
return hd;
diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h
index 5c6f9607cf73..d727dea6847e 100644
--- a/drivers/staging/greybus/greybus.h
+++ b/drivers/staging/greybus/greybus.h
@@ -198,7 +198,7 @@ static inline int is_gb_connection(const struct device *dev)
static inline bool cport_id_valid(u16 cport_id)
{
- return cport_id != CPORT_ID_BAD && cport_id <= CPORT_ID_MAX;
+ return cport_id && cport_id != CPORT_ID_BAD && cport_id <= CPORT_ID_MAX;
}
#endif /* __KERNEL__ */