Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/sysfs.h
| Show All 37 Lines | |||||
| #include <linux/mm.h> | #include <linux/mm.h> | ||||
| struct sysfs_ops { | struct sysfs_ops { | ||||
| ssize_t (*show)(struct kobject *, struct attribute *, char *); | ssize_t (*show)(struct kobject *, struct attribute *, char *); | ||||
| ssize_t (*store)(struct kobject *, struct attribute *, const char *, | ssize_t (*store)(struct kobject *, struct attribute *, const char *, | ||||
| size_t); | size_t); | ||||
| }; | }; | ||||
| struct attribute_group { | |||||
| const char *name; | |||||
| mode_t (*is_visible)(struct kobject *, | |||||
| struct attribute *, int); | |||||
| struct attribute **attrs; | |||||
| }; | |||||
| struct bin_attribute { | struct bin_attribute { | ||||
| struct attribute attr; | struct attribute attr; | ||||
| size_t size; | size_t size; | ||||
| ssize_t (*read)(struct linux_file *, struct kobject *, | ssize_t (*read)(struct linux_file *, struct kobject *, | ||||
| struct bin_attribute *, char *, loff_t, size_t); | struct bin_attribute *, char *, loff_t, size_t); | ||||
| ssize_t (*write)(struct linux_file *, struct kobject *, | ssize_t (*write)(struct linux_file *, struct kobject *, | ||||
| struct bin_attribute *, char *, loff_t, size_t); | struct bin_attribute *, char *, loff_t, size_t); | ||||
| }; | }; | ||||
| struct attribute_group { | |||||
| const char *name; | |||||
| mode_t (*is_visible)(struct kobject *, | |||||
| struct attribute *, int); | |||||
| struct attribute **attrs; | |||||
| struct bin_attribute **bin_attrs; | |||||
| }; | |||||
| #define __ATTR(_name, _mode, _show, _store) { \ | #define __ATTR(_name, _mode, _show, _store) { \ | ||||
| .attr = { .name = __stringify(_name), .mode = _mode }, \ | .attr = { .name = __stringify(_name), .mode = _mode }, \ | ||||
| .show = _show, .store = _store, \ | .show = _show, .store = _store, \ | ||||
| } | } | ||||
| #define __ATTR_RO(_name) { \ | #define __ATTR_RO(_name) { \ | ||||
| .attr = { .name = __stringify(_name), .mode = 0444 }, \ | .attr = { .name = __stringify(_name), .mode = 0444 }, \ | ||||
| .show = _name##_show, \ | .show = _name##_show, \ | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attrs) | ||||
| for (i = 0; attrs[i]; i++) | for (i = 0; attrs[i]; i++) | ||||
| sysfs_remove_file(kobj, attrs[i]); | sysfs_remove_file(kobj, attrs[i]); | ||||
| } | } | ||||
| static inline int | static inline int | ||||
| sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp) | sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp) | ||||
| { | { | ||||
| struct attribute **attr; | struct attribute **attr; | ||||
| struct bin_attribute **bin_attr; | |||||
| struct sysctl_oid *oidp; | struct sysctl_oid *oidp; | ||||
| /* Don't create the group node if grp->name is undefined. */ | /* Don't create the group node if grp->name is undefined. */ | ||||
| if (grp->name) | if (grp->name) | ||||
| oidp = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(kobj->oidp), | oidp = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(kobj->oidp), | ||||
| OID_AUTO, grp->name, CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, grp->name); | OID_AUTO, grp->name, CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, grp->name); | ||||
| else | else | ||||
| oidp = kobj->oidp; | oidp = kobj->oidp; | ||||
| for (attr = grp->attrs; *attr != NULL; attr++) { | for (attr = grp->attrs; attr != NULL && *attr != NULL; attr++) { | ||||
| SYSCTL_ADD_OID(NULL, SYSCTL_CHILDREN(oidp), OID_AUTO, | SYSCTL_ADD_OID(NULL, SYSCTL_CHILDREN(oidp), OID_AUTO, | ||||
| (*attr)->name, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_MPSAFE, | (*attr)->name, CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_MPSAFE, | ||||
| kobj, (uintptr_t)*attr, sysctl_handle_attr, "A", ""); | kobj, (uintptr_t)*attr, sysctl_handle_attr, "A", ""); | ||||
| } | } | ||||
| for (bin_attr = grp->bin_attrs; | |||||
| bin_attr != NULL && *bin_attr != NULL; | |||||
| bin_attr++) { | |||||
| SYSCTL_ADD_OID(NULL, SYSCTL_CHILDREN(oidp), OID_AUTO, | |||||
| (*bin_attr)->attr.name, | |||||
| CTLTYPE_OPAQUE|CTLFLAG_RW|CTLFLAG_MPSAFE, | |||||
| kobj, (uintptr_t)*bin_attr, sysctl_handle_bin_attr, "", ""); | |||||
| } | |||||
| return (0); | return (0); | ||||
| } | } | ||||
| static inline void | static inline void | ||||
| sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp) | sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp) | ||||
| { | { | ||||
| Show All 35 Lines | sysfs_merge_group(struct kobject *kobj, const struct attribute_group *grp) | ||||
| /* Really expected behavior is to return failure if group exists. */ | /* Really expected behavior is to return failure if group exists. */ | ||||
| return (sysfs_create_group(kobj, grp)); | return (sysfs_create_group(kobj, grp)); | ||||
| } | } | ||||
| static inline void | static inline void | ||||
| sysfs_unmerge_group(struct kobject *kobj, const struct attribute_group *grp) | sysfs_unmerge_group(struct kobject *kobj, const struct attribute_group *grp) | ||||
| { | { | ||||
| struct attribute **attr; | struct attribute **attr; | ||||
| struct bin_attribute **bin_attr; | |||||
| struct sysctl_oid *oidp; | struct sysctl_oid *oidp; | ||||
| SYSCTL_FOREACH(oidp, SYSCTL_CHILDREN(kobj->oidp)) { | SYSCTL_FOREACH(oidp, SYSCTL_CHILDREN(kobj->oidp)) { | ||||
| if (strcmp(oidp->oid_name, grp->name) != 0) | if (strcmp(oidp->oid_name, grp->name) != 0) | ||||
| continue; | continue; | ||||
| for (attr = grp->attrs; *attr != NULL; attr++) { | for (attr = grp->attrs; attr != NULL && *attr != NULL; attr++) { | ||||
emaste: We're iterating over `grp->attrs` here, so `grp->bin_attrs` seems missing. | |||||
Done Inline ActionsAnd attr != NULL check added previously seems missing too wulf: And `attr != NULL` check added previously seems missing too | |||||
| sysctl_remove_name(oidp, (*attr)->name, 1, 1); | sysctl_remove_name(oidp, (*attr)->name, 1, 1); | ||||
| } | |||||
| for (bin_attr = grp->bin_attrs; | |||||
Done Inline Actionsthis line may nee emaste: this line may nee | |||||
| bin_attr != NULL && *bin_attr != NULL; | |||||
| bin_attr++) { | |||||
| sysctl_remove_name(oidp, (*bin_attr)->attr.name, 1, 1); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static inline int | static inline int | ||||
| sysfs_create_dir(struct kobject *kobj) | sysfs_create_dir(struct kobject *kobj) | ||||
| { | { | ||||
| struct sysctl_oid *oid; | struct sysctl_oid *oid; | ||||
| ▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines | |||||
We're iterating over grp->attrs here, so grp->bin_attrs seems missing.