diff options
author | Emilio López <emilio.lopez@collabora.co.uk> | 2015-09-21 10:38:20 -0300 |
---|---|---|
committer | Olof Johansson <olof@lixom.net> | 2015-10-07 15:05:31 -0700 |
commit | 7f5028cf6190407b7a632b0f30b83187577824cc (patch) | |
tree | 5f2ebc65f91ad1d816cefa2ea686bc76188456cf /fs/sysfs | |
parent | f14ae099bdad32414ad968909973bfade9b37967 (diff) | |
download | lwn-7f5028cf6190407b7a632b0f30b83187577824cc.tar.gz lwn-7f5028cf6190407b7a632b0f30b83187577824cc.zip |
sysfs: Support is_visible() on binary attributes
According to the sysfs header file:
"The returned value will replace static permissions defined in
struct attribute or struct bin_attribute."
but this isn't the case, as is_visible is only called on struct attribute
only. This patch introduces a new is_bin_visible() function to implement
the same functionality for binary attributes, and updates documentation
accordingly.
Note that to keep functionality and code similar to that of normal
attributes, the mode is now checked as well to ensure it contains only
read/write permissions or SYSFS_PREALLOC.
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Olof Johansson <olof@lixom.net>
Diffstat (limited to 'fs/sysfs')
-rw-r--r-- | fs/sysfs/group.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 39a019936768..51b56e6d9537 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -73,13 +73,26 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj, } if (grp->bin_attrs) { - for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) { + for (i = 0, bin_attr = grp->bin_attrs; *bin_attr; i++, bin_attr++) { + umode_t mode = (*bin_attr)->attr.mode; + if (update) kernfs_remove_by_name(parent, (*bin_attr)->attr.name); + if (grp->is_bin_visible) { + mode = grp->is_bin_visible(kobj, *bin_attr, i); + if (!mode) + continue; + } + + WARN(mode & ~(SYSFS_PREALLOC | 0664), + "Attribute %s: Invalid permissions 0%o\n", + (*bin_attr)->attr.name, mode); + + mode &= SYSFS_PREALLOC | 0664; error = sysfs_add_file_mode_ns(parent, &(*bin_attr)->attr, true, - (*bin_attr)->attr.mode, NULL); + mode, NULL); if (error) break; } |