OSDN Git Service

greybus: endo: clean up id assignment code
authorAlex Elder <elder@linaro.org>
Tue, 9 Jun 2015 22:42:52 +0000 (17:42 -0500)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 10 Jun 2015 17:38:23 +0000 (10:38 -0700)
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 <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/core.c
drivers/staging/greybus/endo.c
drivers/staging/greybus/endo.h

index 8da120b..18b5d5f 100644 (file)
@@ -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);
index 37bd8ae..c778614 100644 (file)
@@ -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;
 }
 
index 0ff40e9..d9f4976 100644 (file)
@@ -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;