summaryrefslogtreecommitdiff
path: root/drivers/staging/greybus
diff options
context:
space:
mode:
authorAlex Elder <elder@linaro.org>2015-06-13 11:02:09 -0500
committerGreg Kroah-Hartman <gregkh@google.com>2015-06-15 16:49:00 -0700
commitfb690ca96f9a7aff8bc8135ce23606e243f4cbae (patch)
tree57a404e32984edcc4ce3363a530e4022aefabeff /drivers/staging/greybus
parentd29b3d631e572400b45b5f9e48e432493663b0fc (diff)
greybus: rename HOST_DEV_CPORT_ID_MAX
We limit the number of host-side CPorts to a fixed maximum (which is less than the 4096 that UniPro allows). This patch imposes a similar limit on the CPort IDs defined by modules (signaling an error if one too large is found in a manifest). It seems reasonable to use the same value for both limits. Change the name of the constant that defines the host limit and use it for both. Update cport_id_valid() to enforce the maximum. (Ultimately we should impose a limit like this; this change is being made in preparation for supporting multiple connections over a single CPort.) Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers/staging/greybus')
-rw-r--r--drivers/staging/greybus/connection.c2
-rw-r--r--drivers/staging/greybus/core.c2
-rw-r--r--drivers/staging/greybus/greybus.h12
-rw-r--r--drivers/staging/greybus/manifest.c5
4 files changed, 12 insertions, 9 deletions
diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index 7236e47ea9c8..9467aaba2b32 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -158,7 +158,7 @@ struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
if (!connection)
return NULL;
- retval = ida_simple_get(id_map, 0, HOST_DEV_CPORT_ID_MAX, GFP_KERNEL);
+ retval = ida_simple_get(id_map, 0, CPORT_ID_MAX, GFP_KERNEL);
if (retval < 0) {
kfree(connection);
return NULL;
diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c
index 18b5d5f48398..d4fffecb1abc 100644
--- a/drivers/staging/greybus/core.c
+++ b/drivers/staging/greybus/core.c
@@ -246,7 +246,7 @@ static int __init gb_init(void)
if (greybus_disabled())
return -ENODEV;
- BUILD_BUG_ON(HOST_DEV_CPORT_ID_MAX >= (long)CPORT_ID_BAD);
+ BUILD_BUG_ON(CPORT_ID_MAX >= (long)CPORT_ID_BAD);
gb_debugfs_init();
diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h
index 518f142b6b5f..5c6f9607cf73 100644
--- a/drivers/staging/greybus/greybus.h
+++ b/drivers/staging/greybus/greybus.h
@@ -52,14 +52,14 @@
.serial_number = (s),
/* XXX I couldn't get my Kconfig file to be noticed for out-of-tree build */
-#ifndef CONFIG_HOST_DEV_CPORT_ID_MAX
-#define CONFIG_HOST_DEV_CPORT_ID_MAX 128
-#endif /* !CONFIG_HOST_DEV_CPORT_ID_MAX */
+#ifndef CONFIG_CPORT_ID_MAX
+#define CONFIG_CPORT_ID_MAX 128
+#endif /* !CONFIG_CPORT_ID_MAX */
/* Maximum number of CPorts usable by a host device */
/* XXX This should really be determined by the AP module manifest */
-#define HOST_DEV_CPORT_ID_MAX CONFIG_HOST_DEV_CPORT_ID_MAX
-#define CPORT_ID_BAD U16_MAX /* UniPro max id is 4095 */
+#define CPORT_ID_MAX CONFIG_CPORT_ID_MAX
+#define CPORT_ID_BAD U16_MAX /* UniPro max id is 4095 */
/* For SP1 hardware, we are going to "hardcode" each device to have all logical
* blocks in order to be able to address them as one unified "unit". Then
@@ -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;
+ return cport_id != CPORT_ID_BAD && cport_id <= CPORT_ID_MAX;
}
#endif /* __KERNEL__ */
diff --git a/drivers/staging/greybus/manifest.c b/drivers/staging/greybus/manifest.c
index e329f3763176..ad55a73b737b 100644
--- a/drivers/staging/greybus/manifest.c
+++ b/drivers/staging/greybus/manifest.c
@@ -224,9 +224,12 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
if (desc_cport->bundle != bundle_id)
continue;
+ cport_id = le16_to_cpu(desc_cport->id);
+ if (cport_id > CPORT_ID_MAX)
+ goto cleanup;
+
/* Found one. Set up its function structure */
protocol_id = desc_cport->protocol_id;
- cport_id = le16_to_cpu(desc_cport->id);
if (!gb_connection_create(bundle, cport_id, protocol_id))
goto cleanup;