diff options
author | Borislav Petkov <bp@alien8.de> | 2012-10-09 13:52:05 -0400 |
---|---|---|
committer | Borislav Petkov <bp@alien8.de> | 2012-10-26 08:37:55 -0400 |
commit | 91872392f08486f692887d2f06a333f512648f22 (patch) | |
tree | 24f82690f04c3282c36bc81d60763687badf33c6 | |
parent | 6f0c0580b70c89094b3422ba81118c7b959c7556 (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>
-rw-r--r-- | drivers/base/core.c | 21 | ||||
-rw-r--r-- | include/linux/device.h | 7 |
2 files changed, 28 insertions, 0 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index abea76c36a4b..c8ae1f6b01b9 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -171,6 +171,27 @@ ssize_t device_show_int(struct device *dev, | |||
171 | } | 171 | } |
172 | EXPORT_SYMBOL_GPL(device_show_int); | 172 | EXPORT_SYMBOL_GPL(device_show_int); |
173 | 173 | ||
174 | ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, | ||
175 | const char *buf, size_t size) | ||
176 | { | ||
177 | struct dev_ext_attribute *ea = to_ext_attr(attr); | ||
178 | |||
179 | if (strtobool(buf, ea->var) < 0) | ||
180 | return -EINVAL; | ||
181 | |||
182 | return size; | ||
183 | } | ||
184 | EXPORT_SYMBOL_GPL(device_store_bool); | ||
185 | |||
186 | ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, | ||
187 | char *buf) | ||
188 | { | ||
189 | struct dev_ext_attribute *ea = to_ext_attr(attr); | ||
190 | |||
191 | return snprintf(buf, PAGE_SIZE, "%d\n", *(bool *)(ea->var)); | ||
192 | } | ||
193 | EXPORT_SYMBOL_GPL(device_show_bool); | ||
194 | |||
174 | /** | 195 | /** |
175 | * device_release - free device structure. | 196 | * device_release - free device structure. |
176 | * @kobj: device's kobject. | 197 | * @kobj: device's kobject. |
diff --git a/include/linux/device.h b/include/linux/device.h index 86ef6ab553b1..50c85a26b003 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -496,6 +496,10 @@ ssize_t device_show_int(struct device *dev, struct device_attribute *attr, | |||
496 | char *buf); | 496 | char *buf); |
497 | ssize_t device_store_int(struct device *dev, struct device_attribute *attr, | 497 | ssize_t device_store_int(struct device *dev, struct device_attribute *attr, |
498 | const char *buf, size_t count); | 498 | const char *buf, size_t count); |
499 | ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, | ||
500 | char *buf); | ||
501 | ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, | ||
502 | const char *buf, size_t count); | ||
499 | 503 | ||
500 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ | 504 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ |
501 | struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) | 505 | struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) |
@@ -505,6 +509,9 @@ ssize_t device_store_int(struct device *dev, struct device_attribute *attr, | |||
505 | #define DEVICE_INT_ATTR(_name, _mode, _var) \ | 509 | #define DEVICE_INT_ATTR(_name, _mode, _var) \ |
506 | struct dev_ext_attribute dev_attr_##_name = \ | 510 | struct dev_ext_attribute dev_attr_##_name = \ |
507 | { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) } | 511 | { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) } |
512 | #define DEVICE_BOOL_ATTR(_name, _mode, _var) \ | ||
513 | struct dev_ext_attribute dev_attr_##_name = \ | ||
514 | { __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) } | ||
508 | #define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \ | 515 | #define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \ |
509 | struct device_attribute dev_attr_##_name = \ | 516 | struct device_attribute dev_attr_##_name = \ |
510 | __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) | 517 | __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) |