Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 104784
b: refs/heads/master
c: 9800794
h: refs/heads/master
v: v3
  • Loading branch information
Andi Kleen authored and Greg Kroah-Hartman committed Jul 22, 2008
1 parent 187e66e commit df14d85
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4a0b2b4dbe1335b8b9886ba3dc85a145d5d938ed
refs/heads/master: 9800794ac11d4646384b3a310dfd1fe2eed577bf
49 changes: 49 additions & 0 deletions trunk/drivers/base/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,52 @@ int __init system_bus_init(void)

EXPORT_SYMBOL_GPL(sysdev_register);
EXPORT_SYMBOL_GPL(sysdev_unregister);

#define to_ext_attr(x) container_of(x, struct sysdev_ext_attribute, attr)

ssize_t sysdev_store_ulong(struct sys_device *sysdev,
struct sysdev_attribute *attr,
const char *buf, size_t size)
{
struct sysdev_ext_attribute *ea = to_ext_attr(attr);
char *end;
unsigned long new = simple_strtoul(buf, &end, 0);
if (end == buf)
return -EINVAL;
*(unsigned long *)(ea->var) = new;
return end - buf;
}
EXPORT_SYMBOL_GPL(sysdev_store_ulong);

ssize_t sysdev_show_ulong(struct sys_device *sysdev,
struct sysdev_attribute *attr,
char *buf)
{
struct sysdev_ext_attribute *ea = to_ext_attr(attr);
return snprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var));
}
EXPORT_SYMBOL_GPL(sysdev_show_ulong);

ssize_t sysdev_store_int(struct sys_device *sysdev,
struct sysdev_attribute *attr,
const char *buf, size_t size)
{
struct sysdev_ext_attribute *ea = to_ext_attr(attr);
char *end;
long new = simple_strtol(buf, &end, 0);
if (end == buf || new > INT_MAX || new < INT_MIN)
return -EINVAL;
*(int *)(ea->var) = new;
return end - buf;
}
EXPORT_SYMBOL_GPL(sysdev_store_int);

ssize_t sysdev_show_int(struct sys_device *sysdev,
struct sysdev_attribute *attr,
char *buf)
{
struct sysdev_ext_attribute *ea = to_ext_attr(attr);
return snprintf(buf, PAGE_SIZE, "%d\n", *(int *)(ea->var));
}
EXPORT_SYMBOL_GPL(sysdev_show_int);

34 changes: 34 additions & 0 deletions trunk/include/linux/sysdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,38 @@ struct sysdev_attribute {
extern int sysdev_create_file(struct sys_device *, struct sysdev_attribute *);
extern void sysdev_remove_file(struct sys_device *, struct sysdev_attribute *);

struct sysdev_ext_attribute {
struct sysdev_attribute attr;
void *var;
};

/*
* Support for simple variable sysdev attributes.
* The pointer to the variable is stored in a sysdev_ext_attribute
*/

/* Add more types as needed */

extern ssize_t sysdev_show_ulong(struct sys_device *, struct sysdev_attribute *,
char *);
extern ssize_t sysdev_store_ulong(struct sys_device *,
struct sysdev_attribute *, const char *, size_t);
extern ssize_t sysdev_show_int(struct sys_device *, struct sysdev_attribute *,
char *);
extern ssize_t sysdev_store_int(struct sys_device *,
struct sysdev_attribute *, const char *, size_t);

#define _SYSDEV_ULONG_ATTR(_name, _mode, _var) \
{ _SYSDEV_ATTR(_name, _mode, sysdev_show_ulong, sysdev_store_ulong), \
&(_var) }
#define SYSDEV_ULONG_ATTR(_name, _mode, _var) \
struct sysdev_ext_attribute attr_##_name = \
_SYSDEV_ULONG_ATTR(_name, _mode, _var);
#define _SYSDEV_INT_ATTR(_name, _mode, _var) \
{ _SYSDEV_ATTR(_name, _mode, sysdev_show_int, sysdev_store_int), \
&(_var) }
#define SYSDEV_INT_ATTR(_name, _mode, _var) \
struct sysdev_ext_attribute attr_##_name = \
_SYSDEV_INT_ATTR(_name, _mode, _var);

#endif /* _SYSDEV_H_ */

0 comments on commit df14d85

Please sign in to comment.