diff options
author | Johan Hovold <johan@hovoldconsulting.com> | 2016-01-19 12:51:28 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@google.com> | 2016-01-19 12:17:13 -0800 |
commit | 7d81bafa4ca477a4d364dd229bbbeffb1fa7af4e (patch) | |
tree | d3bccb6309ad7420321f4f1191ce20cef910e1fc /drivers/staging/greybus/legacy.c | |
parent | b53e0c9e8dceb170b054f186200b2fe3fb3718f2 (diff) |
greybus: legacy: add private driver data
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>
Diffstat (limited to 'drivers/staging/greybus/legacy.c')
-rw-r--r-- | drivers/staging/greybus/legacy.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/drivers/staging/greybus/legacy.c b/drivers/staging/greybus/legacy.c index 186482300682..1e878beea8a5 100644 --- a/drivers/staging/greybus/legacy.c +++ b/drivers/staging/greybus/legacy.c @@ -12,6 +12,11 @@ #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[] = { |