Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1220726

[PATCH 1/3] sysfs: Fix is_visible() support for binary attributes

From Emilio López <emilio.lopez@collabora.co.uk>
Newsgroups linux.kernel
Subject [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes
Date 2015-09-08 14:10 +0200
Message-ID <q6pSO-3LC-19@gated-at.bofh.it> (permalink)
References <q6pSN-3LC-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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 adds the code paths required
to support is_visible() on binary attributes.

Signed-off-by: Emilio López <emilio.lopez@collabora.co.uk>
---
 fs/sysfs/group.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 39a0199..eb6996a 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -37,10 +37,10 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj,
 {
 	struct attribute *const *attr;
 	struct bin_attribute *const *bin_attr;
-	int error = 0, i;
+	int error = 0, i = 0;
 
 	if (grp->attrs) {
-		for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++) {
+		for (attr = grp->attrs; *attr && !error; i++, attr++) {
 			umode_t mode = (*attr)->mode;
 
 			/*
@@ -73,13 +73,27 @@ 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 (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_visible) {
+				mode = grp->is_visible(kobj,
+						       &(*bin_attr)->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;
 		}
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Emilio López <emilio.lopez@collabora.co.uk> - 2015-09-08 14:10 +0200
  Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Guenter Roeck <linux@roeck-us.net> - 2015-09-08 17:40 +0200
    Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Greg KH <gregkh@linuxfoundation.org> - 2015-09-08 21:20 +0200
      Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Guenter Roeck <linux@roeck-us.net> - 2015-09-08 21:40 +0200
        Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Emilio López <emilio.lopez@collabora.co.uk> - 2015-09-09 03:00 +0200
          Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Guenter Roeck <linux@roeck-us.net> - 2015-09-09 03:20 +0200
            Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Greg KH <gregkh@linuxfoundation.org> - 2015-09-09 06:00 +0200
              Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Guenter Roeck <linux@roeck-us.net> - 2015-09-09 06:20 +0200
                Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Emilio López <emilio.lopez@collabora.co.uk> - 2015-09-09 15:20 +0200
                Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Guenter Roeck <linux@roeck-us.net> - 2015-09-09 15:40 +0200
                Re: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Greg KH <gregkh@linuxfoundation.org> - 2015-09-09 20:30 +0200

csiph-web