summaryrefslogtreecommitdiffstats
path: root/drivers/staging/greybus/connection.c
diff options
context:
space:
mode:
authorJohan Hovold <johan@hovoldconsulting.com>2016-01-19 12:51:27 +0100
committerGreg Kroah-Hartman <gregkh@google.com>2016-01-19 12:17:13 -0800
commitb53e0c9e8dceb170b054f186200b2fe3fb3718f2 (patch)
tree03f844d337ebfe01fb5c559139ee21bc5c5e5a2c /drivers/staging/greybus/connection.c
parent210b508e45f00fd81c1ba35c979836d8ffea3980 (diff)
downloadlinux-stable-b53e0c9e8dceb170b054f186200b2fe3fb3718f2.tar.gz
linux-stable-b53e0c9e8dceb170b054f186200b2fe3fb3718f2.tar.bz2
linux-stable-b53e0c9e8dceb170b054f186200b2fe3fb3718f2.zip
greybus: connection: make cport lookup thread-safe
Use the gb_connection_mutex when making sure a remote CPort is available. This is needed when moving to driver-managed connections that can be created and destroyed at any time. Also check for duplicate bundle-less connections. Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers/staging/greybus/connection.c')
-rw-r--r--drivers/staging/greybus/connection.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index de44775b0bc5..88c8a3fab2c6 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -19,7 +19,7 @@ static DEFINE_SPINLOCK(gb_connections_lock);
static DEFINE_MUTEX(gb_connection_mutex);
-/* This is only used at initialization time; no locking is required. */
+/* Caller holds gb_connection_mutex. */
static struct gb_connection *
gb_connection_intf_find(struct gb_interface *intf, u16 cport_id)
{
@@ -142,17 +142,6 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
struct ida *id_map = &hd->cport_id_map;
int ida_start, ida_end;
- /*
- * If a manifest tries to reuse a cport, reject it. We
- * initialize connections serially so we don't need to worry
- * about holding the connection lock.
- */
- if (bundle && gb_connection_intf_find(bundle->intf, cport_id)) {
- dev_err(&bundle->dev, "cport %u already connected\n",
- cport_id);
- return NULL;
- }
-
if (hd_cport_id < 0) {
ida_start = 0;
ida_end = hd->num_cports;
@@ -166,6 +155,11 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
mutex_lock(&gb_connection_mutex);
+ if (intf && gb_connection_intf_find(intf, cport_id)) {
+ dev_err(&intf->dev, "cport %u already in use\n", cport_id);
+ goto err_unlock;
+ }
+
hd_cport_id = ida_simple_get(id_map, ida_start, ida_end, GFP_KERNEL);
if (hd_cport_id < 0)
goto err_unlock;