From: Johan Hovold Date: Tue, 29 Mar 2016 22:56:06 +0000 (-0400) Subject: greybus: interface: clean up device-id handling X-Git-Tag: Ubuntu-4.9.0-1.2~749^2~378^2~21^2~558 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=e9f2f688d1a9434f615eec7180f14f0c52941bb9;p=mirror_ubuntu-zesty-kernel.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/bundle.h b/drivers/staging/greybus/bundle.h index 18b125e8169b..2dc61ab7495d 100644 --- a/drivers/staging/greybus/bundle.h +++ b/drivers/staging/greybus/bundle.h @@ -32,8 +32,6 @@ struct gb_bundle { }; #define to_gb_bundle(d) container_of(d, struct gb_bundle, dev) -#define GB_DEVICE_ID_BAD 0xff - /* Greybus "private" definitions" */ struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id, u8 class); diff --git a/drivers/staging/greybus/greybus_protocols.h b/drivers/staging/greybus/greybus_protocols.h index 8370cfead6f2..2e126e671bd6 100644 --- a/drivers/staging/greybus/greybus_protocols.h +++ b/drivers/staging/greybus/greybus_protocols.h @@ -54,10 +54,11 @@ /* Fixed IDs for control/svc protocols */ -/* Device ID of SVC and AP */ -#define GB_DEVICE_ID_SVC 0 -#define GB_DEVICE_ID_AP 1 -#define GB_DEVICE_ID_MODULES_START 2 +/* SVC switch-port device ids */ +#define GB_SVC_DEVICE_ID_SVC 0 +#define GB_SVC_DEVICE_ID_AP 1 +#define GB_SVC_DEVICE_ID_MIN 2 +#define GB_SVC_DEVICE_ID_MAX 31 #define GB_SVC_CPORT_ID 0 #define GB_CONTROL_BUNDLE_ID 0 diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c index 48f64fbe9248..7e7bcdafa6e2 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; diff --git a/drivers/staging/greybus/interface.h b/drivers/staging/greybus/interface.h index 5dfaea51eb9f..8b6fcfe90883 100644 --- a/drivers/staging/greybus/interface.h +++ b/drivers/staging/greybus/interface.h @@ -21,7 +21,7 @@ struct gb_interface { struct list_head links; /* gb_host_device->interfaces */ struct list_head manifest_descs; u8 interface_id; /* Physical location within the Endo */ - u8 device_id; /* Device id allocated for the interface block by the SVC */ + u8 device_id; /* Information taken from the manifest descriptor */ char *vendor_string;