diff options
author | Johan Hovold <johan@hovoldconsulting.com> | 2016-03-29 18:56:06 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@google.com> | 2016-03-30 14:23:19 -0700 |
commit | e9f2f688d1a9434f615eec7180f14f0c52941bb9 (patch) | |
tree | 673b9c1e802a8798c43616321f3d5b934418e574 /drivers/staging/greybus/interface.c | |
parent | 984c9d38ae370993f28b36c8be9923b1de39f5e7 (diff) | |
download | op-kernel-dev-e9f2f688d1a9434f615eec7180f14f0c52941bb9.zip op-kernel-dev-e9f2f688d1a9434f615eec7180f14f0c52941bb9.tar.gz |
greybus: interface: clean up device-id handling
Clean up the device id-handling and make sure we never allocate invalid
device ids due to a missing upper bound.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers/staging/greybus/interface.c')
-rw-r--r-- | drivers/staging/greybus/interface.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c index 48f64fb..7e7bcda 100644 --- a/drivers/staging/greybus/interface.c +++ b/drivers/staging/greybus/interface.c @@ -10,6 +10,9 @@ #include "greybus.h" +#define GB_INTERFACE_DEVICE_ID_BAD 0xff + + static int gb_interface_route_create(struct gb_interface *intf) { struct gb_svc *svc = intf->hd->svc; @@ -17,16 +20,10 @@ static int gb_interface_route_create(struct gb_interface *intf) u8 device_id; int ret; - /* - * Create a device id for the interface: - * - device id 0 (GB_DEVICE_ID_SVC) belongs to the SVC - * - device id 1 (GB_DEVICE_ID_AP) belongs to the AP - * - * XXX Do we need to allocate device ID for SVC or the AP here? And what - * XXX about an AP with multiple interface blocks? - */ + /* Allocate an interface device id. */ ret = ida_simple_get(&svc->device_id_map, - GB_DEVICE_ID_MODULES_START, 0, GFP_KERNEL); + GB_SVC_DEVICE_ID_MIN, GB_SVC_DEVICE_ID_MAX + 1, + GFP_KERNEL); if (ret < 0) { dev_err(&intf->dev, "failed to allocate device id: %d\n", ret); return ret; @@ -40,8 +37,8 @@ static int gb_interface_route_create(struct gb_interface *intf) goto err_ida_remove; } - /* Create a two-way route between the AP and the new interface. */ - ret = gb_svc_route_create(svc, svc->ap_intf_id, GB_DEVICE_ID_AP, + /* FIXME: Hard-coded AP device id. */ + ret = gb_svc_route_create(svc, svc->ap_intf_id, GB_SVC_DEVICE_ID_AP, intf_id, device_id); if (ret) { dev_err(&intf->dev, "failed to create route: %d\n", ret); @@ -67,12 +64,12 @@ static void gb_interface_route_destroy(struct gb_interface *intf) { struct gb_svc *svc = intf->hd->svc; - if (intf->device_id == GB_DEVICE_ID_BAD) + if (intf->device_id == GB_INTERFACE_DEVICE_ID_BAD) return; gb_svc_route_destroy(svc, svc->ap_intf_id, intf->interface_id); ida_simple_remove(&svc->device_id_map, intf->device_id); - intf->device_id = GB_DEVICE_ID_BAD; + intf->device_id = GB_INTERFACE_DEVICE_ID_BAD; } /* @@ -257,7 +254,7 @@ struct gb_interface *gb_interface_create(struct gb_host_device *hd, INIT_LIST_HEAD(&intf->manifest_descs); /* Invalid device id to start with */ - intf->device_id = GB_DEVICE_ID_BAD; + intf->device_id = GB_INTERFACE_DEVICE_ID_BAD; intf->dev.parent = &hd->dev; intf->dev.bus = &greybus_bus_type; |