summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBorislav Petkov <bp@alien8.de>2012-10-09 19:52:05 +0200
committerBorislav Petkov <bp@alien8.de>2012-10-26 14:37:55 +0200
commit91872392f08486f692887d2f06a333f512648f22 (patch)
tree24f82690f04c3282c36bc81d60763687badf33c6 /drivers
parent6f0c0580b70c89094b3422ba81118c7b959c7556 (diff)
drivers/base: Add a DEVICE_BOOL_ATTR macro
... which, analogous to DEVICE_INT_ATTR provides functionality to set/clear bools. Its purpose is to be used where values need to be used as booleans in configuration context. Next patch uses this. Signed-off-by: Borislav Petkov <bp@alien8.de> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/core.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index abea76c36a4..c8ae1f6b01b 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -171,6 +171,27 @@ ssize_t device_show_int(struct device *dev,
}
EXPORT_SYMBOL_GPL(device_show_int);
+ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct dev_ext_attribute *ea = to_ext_attr(attr);
+
+ if (strtobool(buf, ea->var) < 0)
+ return -EINVAL;
+
+ return size;
+}
+EXPORT_SYMBOL_GPL(device_store_bool);
+
+ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct dev_ext_attribute *ea = to_ext_attr(attr);
+
+ return snprintf(buf, PAGE_SIZE, "%d\n", *(bool *)(ea->var));
+}
+EXPORT_SYMBOL_GPL(device_show_bool);
+
/**
* device_release - free device structure.
* @kobj: device's kobject.