]> git.karo-electronics.de Git - linux-beck.git/commitdiff
greybus: legacy: add private driver data
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 19 Jan 2016 11:51:28 +0000 (12:51 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 19 Jan 2016 20:17:13 +0000 (12:17 -0800)
Allocate private data structure at probe and release at disconnect.

The private data will be used to track the connections managed by the
driver, but for now only holds a count of the number of cports the
bundle has.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/legacy.c

index 186482300682ff193f648d05bc1418a56009dc17..1e878beea8a514b7b8912afc2c99a5301e85efce 100644 (file)
 #include "protocol.h"
 
 
+struct legacy_data {
+       size_t num_cports;
+};
+
+
 static int legacy_connection_get_version(struct gb_connection *connection)
 {
        int ret;
@@ -123,11 +128,23 @@ static void legacy_connection_exit(struct gb_connection *connection)
 static int legacy_probe(struct gb_bundle *bundle,
                        const struct greybus_bundle_id *id)
 {
+       struct legacy_data *data;
        struct gb_connection *connection;
        int ret;
 
-       dev_dbg(&bundle->dev, "%s - bundle class = 0x%02x\n", __func__,
-                       bundle->class);
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+
+       data->num_cports = 0;
+       list_for_each_entry(connection, &bundle->connections, bundle_links)
+               data->num_cports++;
+
+       dev_dbg(&bundle->dev,
+                       "%s - bundle class = 0x%02x, num_cports = %zu\n",
+                       __func__, bundle->class, data->num_cports);
+
+       greybus_set_drvdata(bundle, data);
 
        list_for_each_entry(connection, &bundle->connections, bundle_links) {
                dev_dbg(&bundle->dev, "enabling connection %s\n",
@@ -145,12 +162,14 @@ err_connections_disable:
                                                        bundle_links) {
                legacy_connection_exit(connection);
        }
+       kfree(data);
 
        return ret;
 }
 
 static void legacy_disconnect(struct gb_bundle *bundle)
 {
+       struct legacy_data *data = greybus_get_drvdata(bundle);
        struct gb_connection *connection;
 
        dev_dbg(&bundle->dev, "%s - bundle class = 0x%02x\n", __func__,
@@ -160,6 +179,8 @@ static void legacy_disconnect(struct gb_bundle *bundle)
                                                        bundle_links) {
                legacy_connection_exit(connection);
        }
+
+       kfree(data);
 }
 
 static const struct greybus_bundle_id legacy_id_table[] = {