diff options
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/sys.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/drivers/base/sys.c b/drivers/base/sys.c index dc7dace14e1c..40fc14f03540 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c | |||
@@ -479,3 +479,52 @@ int __init system_bus_init(void) | |||
479 | 479 | ||
480 | EXPORT_SYMBOL_GPL(sysdev_register); | 480 | EXPORT_SYMBOL_GPL(sysdev_register); |
481 | EXPORT_SYMBOL_GPL(sysdev_unregister); | 481 | EXPORT_SYMBOL_GPL(sysdev_unregister); |
482 | |||
483 | #define to_ext_attr(x) container_of(x, struct sysdev_ext_attribute, attr) | ||
484 | |||
485 | ssize_t sysdev_store_ulong(struct sys_device *sysdev, | ||
486 | struct sysdev_attribute *attr, | ||
487 | const char *buf, size_t size) | ||
488 | { | ||
489 | struct sysdev_ext_attribute *ea = to_ext_attr(attr); | ||
490 | char *end; | ||
491 | unsigned long new = simple_strtoul(buf, &end, 0); | ||
492 | if (end == buf) | ||
493 | return -EINVAL; | ||
494 | *(unsigned long *)(ea->var) = new; | ||
495 | return end - buf; | ||
496 | } | ||
497 | EXPORT_SYMBOL_GPL(sysdev_store_ulong); | ||
498 | |||
499 | ssize_t sysdev_show_ulong(struct sys_device *sysdev, | ||
500 | struct sysdev_attribute *attr, | ||
501 | char *buf) | ||
502 | { | ||
503 | struct sysdev_ext_attribute *ea = to_ext_attr(attr); | ||
504 | return snprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var)); | ||
505 | } | ||
506 | EXPORT_SYMBOL_GPL(sysdev_show_ulong); | ||
507 | |||
508 | ssize_t sysdev_store_int(struct sys_device *sysdev, | ||
509 | struct sysdev_attribute *attr, | ||
510 | const char *buf, size_t size) | ||
511 | { | ||
512 | struct sysdev_ext_attribute *ea = to_ext_attr(attr); | ||
513 | char *end; | ||
514 | long new = simple_strtol(buf, &end, 0); | ||
515 | if (end == buf || new > INT_MAX || new < INT_MIN) | ||
516 | return -EINVAL; | ||
517 | *(int *)(ea->var) = new; | ||
518 | return end - buf; | ||
519 | } | ||
520 | EXPORT_SYMBOL_GPL(sysdev_store_int); | ||
521 | |||
522 | ssize_t sysdev_show_int(struct sys_device *sysdev, | ||
523 | struct sysdev_attribute *attr, | ||
524 | char *buf) | ||
525 | { | ||
526 | struct sysdev_ext_attribute *ea = to_ext_attr(attr); | ||
527 | return snprintf(buf, PAGE_SIZE, "%d\n", *(int *)(ea->var)); | ||
528 | } | ||
529 | EXPORT_SYMBOL_GPL(sysdev_show_int); | ||
530 | |||