diff options
author | Greg Kroah-Hartman <gregkh@google.com> | 2015-04-13 19:48:37 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@google.com> | 2015-04-17 16:12:49 +0200 |
commit | 75052a5504705aded68e544967fdd1d296470bcc (patch) | |
tree | 82f1f81a84cc473440ea22a89072fffc420c170f /drivers/staging/greybus/bundle.c | |
parent | 1ffc12be5549085faac2d6116f666cb9cbcb2930 (diff) |
greybus: bundle: add state sysfs file
A bundle has a state file, that is managed by the endo userspace
process. This file can be written to and any process that is polling on
the file will be woken up and can read the new value. It's a "cheap"
IPC for programs that are not allowed to do anything other than
read/write to kernel sysfs files.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers/staging/greybus/bundle.c')
-rw-r--r-- | drivers/staging/greybus/bundle.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/drivers/staging/greybus/bundle.c b/drivers/staging/greybus/bundle.c index 3f1aa6490e48..e7b2199f39b4 100644 --- a/drivers/staging/greybus/bundle.c +++ b/drivers/staging/greybus/bundle.c @@ -1,8 +1,8 @@ /* * Greybus bundles * - * Copyright 2014 Google Inc. - * Copyright 2014 Linaro Ltd. + * Copyright 2014-2015 Google Inc. + * Copyright 2014-2015 Linaro Ltd. * * Released under the GPLv2 only. */ @@ -31,9 +31,41 @@ static ssize_t class_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(class); +static ssize_t state_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct gb_bundle *bundle = to_gb_bundle(dev); + + if (bundle->state == NULL) + return sprintf(buf, "\n"); + + return sprintf(buf, "%s\n", bundle->state); +} + +static ssize_t state_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t size) +{ + struct gb_bundle *bundle = to_gb_bundle(dev); + + kfree(bundle->state); + bundle->state = kzalloc(size + 1, GFP_KERNEL); + if (!bundle->state) + return -ENOMEM; + + memcpy(bundle->state, buf, size); + + /* Tell userspace that the file contents changed */ + sysfs_notify(&bundle->dev.kobj, NULL, "state"); + + return size; +} +static DEVICE_ATTR_RW(state); + + static struct attribute *bundle_attrs[] = { &dev_attr_device_id.attr, &dev_attr_class.attr, + &dev_attr_state.attr, NULL, }; @@ -43,6 +75,7 @@ static void gb_bundle_release(struct device *dev) { struct gb_bundle *bundle = to_gb_bundle(dev); + kfree(bundle->state); kfree(bundle); } |