From 79dda60987bc8df963c910bbcbfd9dc11bfada03 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Tue, 9 Jun 2015 17:42:52 -0500 Subject: [PATCH] greybus: endo: clean up id assignment code Recently code was added (back) to assign a unique id to each endo, so satisfy uniqueness requirements of the Linux device subsystem. An ID allocator is used to manage the space of IDs. Now that we have gb_endo_init(), we can initialize the map there, and fully hide the ID map within "endo.c". The original functions gb_endo_id_alloc() and gb_endo_id_free() provided a nice abstract interface, but the direct ID allocation calls are quite simple, so just call them directly. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/core.c | 2 -- drivers/staging/greybus/endo.c | 41 ++++++---------------------------- drivers/staging/greybus/endo.h | 2 -- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 8da120bcdf3d..18b5d5f48398 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -256,8 +256,6 @@ static int __init gb_init(void) goto error_bus; } - ida_init(&greybus_endo_id_map); - retval = gb_ap_init(); if (retval) { pr_err("gb_ap_init failed (%d)\n", retval); diff --git a/drivers/staging/greybus/endo.c b/drivers/staging/greybus/endo.c index 37bd8ae15bfe..c77861463883 100644 --- a/drivers/staging/greybus/endo.c +++ b/drivers/staging/greybus/endo.c @@ -43,7 +43,7 @@ #define max_endo_interface_id(endo_layout) \ (4 + ((endo_layout)->max_ribs + 1) * 2) -struct ida greybus_endo_id_map; +static struct ida greybus_endo_id_map; /* endo sysfs attributes */ static ssize_t serial_number_show(struct device *dev, @@ -434,42 +434,13 @@ static int create_modules(struct gb_endo *endo) return 0; } -/* - * Allocate an available Id to uniquely identify the endo device. The lowest - * available id is returned, so the first call is guaranteed to allocate endo Id - * 0. - * - * Assigns the endo's id and returns 0 if successful. - * Returns error otherwise. - */ -static int gb_endo_id_alloc(struct gb_endo *endo) -{ - int id; - - id = ida_simple_get(&greybus_endo_id_map, 0, 0, GFP_ATOMIC); - if (id < 0) - return id; - - endo->dev_id = (u16)id; - - return 0; -} - -/* - * Free a previously-allocated Endo Id. - */ -static void gb_endo_id_free(struct gb_endo *endo) -{ - ida_simple_remove(&greybus_endo_id_map, endo->dev_id); -} - static int gb_endo_register(struct greybus_host_device *hd, struct gb_endo *endo) { int retval; - retval = gb_endo_id_alloc(endo); - if (retval) + retval = ida_simple_get(&greybus_endo_id_map, 0, 0, GFP_ATOMIC); + if (retval < 0) return retval; endo->dev.parent = hd->parent; @@ -491,7 +462,7 @@ static int gb_endo_register(struct greybus_host_device *hd, dev_err(hd->parent, "failed to add endo device of id 0x%04x\n", endo->id); put_device(&endo->dev); - gb_endo_id_free(endo); + ida_simple_remove(&greybus_endo_id_map, endo->dev_id); } return retval; @@ -547,12 +518,14 @@ void gb_endo_remove(struct gb_endo *endo) /* remove all modules for this endo */ gb_module_remove_all(endo); - gb_endo_id_free(endo); + ida_simple_remove(&greybus_endo_id_map, endo->dev_id); device_unregister(&endo->dev); } int __init gb_endo_init(void) { + ida_init(&greybus_endo_id_map); + return 0; } diff --git a/drivers/staging/greybus/endo.h b/drivers/staging/greybus/endo.h index 0ff40e990ab8..d9f4976ac63d 100644 --- a/drivers/staging/greybus/endo.h +++ b/drivers/staging/greybus/endo.h @@ -46,8 +46,6 @@ struct gb_endo { }; #define to_gb_endo(d) container_of(d, struct gb_endo, dev) -extern struct ida greybus_endo_id_map; - /* Greybus "private" definitions */ struct greybus_host_device; -- 2.39.5