mirror of
https://github.com/torvalds/linux.git
synced 2024-12-02 17:11:33 +00:00
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>
This commit is contained in:
parent
984c9d38ae
commit
e9f2f688d1
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user