Skip to contentSkip to conversation

ib_qib: Allow writes to the diag_counters to be able to clear them

PATCH Superseded Ira Weiny 3 participants 10 messages Jul 8, 2010 – Jul 21, 2010 8 messages not in the archive

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ira Weiny

author
#0 lore raw
Quoted 1 line

From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001

From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +15 -1
index dab4d9f..91cd1b8 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
 #define QIB_DIAGC_ATTR(N) \
 	static struct qib_diagc_attr qib_diagc_attr_##N = { \
-		.attr = { .name = __stringify(N), .mode = 0444 }, \
+		.attr = { .name = __stringify(N), .mode = 0664 }, \
 		.counter = offsetof(struct qib_ibport, n_##N) \
 	}
 
@@ -403,8 +403,22 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
 	return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
 }
 
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
+				const char *buf, size_t size)
+{
+	struct qib_diagc_attr *dattr =
+		container_of(attr, struct qib_diagc_attr, attr);
+	struct qib_pportdata *ppd =
+		container_of(kobj, struct qib_pportdata, diagc_kobj);
+	struct qib_ibport *qibp = &ppd->ibport_data;
+
+	*(u32 *)((char *)qibp + dattr->counter) = simple_strtol(buf, NULL, 0);
+	return 4;
+}
+
 static const struct sysfs_ops qib_diagc_ops = {
 	.show = diagc_attr_show,
+	.store = diagc_attr_store,
 };
 
 static struct kobj_type qib_diagc_ktype = {
Signature · 6 lines
1.5.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to a message not in the archive
Quoted 29 lines · Ira Weiny

From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-

 1 files changed, 15 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +2 -1
index dab4d9f..91cd1b8 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
  #define QIB_DIAGC_ATTR(N) \
        static struct qib_diagc_attr qib_diagc_attr_##N = { \
-               .attr = { .name = __stringify(N), .mode = 0444 }, \
+               .attr = { .name = __stringify(N), .mode = 0664 }, \
                .counter = offsetof(struct qib_ibport, n_##N) \
        }
 
@@ -403,8 +403,22 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
        return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  }
 
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,

drivers/infiniband/hw/qib/qib_sysfs.c static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, · line 416

Quoted 10 lines
drivers/infiniband/hw/qib/qib_sysfs.c +10 -0
+                               const char *buf, size_t size)
+{
+       struct qib_diagc_attr *dattr =
+               container_of(attr, struct qib_diagc_attr, attr);
+       struct qib_pportdata *ppd =
+               container_of(kobj, struct qib_pportdata, diagc_kobj);
+       struct qib_ibport *qibp = &ppd->ibport_data;
+
+       *(u32 *)((char *)qibp + dattr->counter) = simple_strtol(buf, NULL, 0);
+       return 4;

The above line is not correct -- it should probably be something like "return size;". See also
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/sysfs.txt.

drivers/infiniband/hw/qib/qib_sysfs.c static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, · line 424

Quoted 8 lines
drivers/infiniband/hw/qib/qib_sysfs.c +3 -0
+}
+
  static const struct sysfs_ops qib_diagc_ops = {
        .show = diagc_attr_show,
+       .store = diagc_attr_store,
  };
 
  static struct kobj_type qib_diagc_ktype = {

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw
In reply to a message not in the archive
Quoted 29 lines · On Thu, 8 Jul 2010 10:37:26 -0700 Bart Van Assche…
Quoted 28 lines · Ira Weiny

From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-

 1 files changed, 15 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +1 -1
index dab4d9f..91cd1b8 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
  #define QIB_DIAGC_ATTR(N) \
        static struct qib_diagc_attr qib_diagc_attr_##N = { \
-               .attr = { .name = __stringify(N), .mode = 0444 }, \
+               .attr = { .name = __stringify(N), .mode = 0664 }, \
                .counter = offsetof(struct qib_ibport, n_##N) \
        }
 
@@ -403,8 +403,22 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
        return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  }
 
Quoted 15 lines

drivers/infiniband/hw/qib/qib_sysfs.c static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, · line 416

Quoted 11 lines
drivers/infiniband/hw/qib/qib_sysfs.c +11 -0
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buf, size_t size)
+{
+       struct qib_diagc_attr *dattr =
+               container_of(attr, struct qib_diagc_attr, attr);
+       struct qib_pportdata *ppd =
+               container_of(kobj, struct qib_pportdata, diagc_kobj);
+       struct qib_ibport *qibp = &ppd->ibport_data;
+
+       *(u32 *)((char *)qibp + dattr->counter) = simple_strtol(buf, NULL, 0);
+       return 4;

The above line is not correct -- it should probably be something like "return size;". See also
http://*git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/sysfs.txt.

My mistake. From the document above the return should be:

return strnlen(buf, PAGE_SIZE);

Correct?

Also I think I should check for invalid values as well.

Ira

Quoted 10 lines
Quoted 9 lines
drivers/infiniband/hw/qib/qib_sysfs.c +3 -0
+}
+
  static const struct sysfs_ops qib_diagc_ops = {
        .show = diagc_attr_show,
+       .store = diagc_attr_store,
  };
 
  static struct kobj_type qib_diagc_ktype = {
Signature · 9 lines
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#6 lore raw

PATCH v2 1/1 ib_qib: Allow writes to the diag_counters to be able to clear them

In reply to a message not in the archive

From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

Changes in V2:
Add check for negative values
Return proper length

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +19 -1
index dab4d9f..e4ec50e 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
 #define QIB_DIAGC_ATTR(N) \
 	static struct qib_diagc_attr qib_diagc_attr_##N = { \
-		.attr = { .name = __stringify(N), .mode = 0444 }, \
+		.attr = { .name = __stringify(N), .mode = 0664 }, \
 		.counter = offsetof(struct qib_ibport, n_##N) \
 	}
 
@@ -403,8 +403,26 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
 	return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
 }
 
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
+				const char *buf, size_t size)
+{
+	struct qib_diagc_attr *dattr =
+		container_of(attr, struct qib_diagc_attr, attr);
+	struct qib_pportdata *ppd =
+		container_of(kobj, struct qib_pportdata, diagc_kobj);
+	struct qib_ibport *qibp = &ppd->ibport_data;
+	long val = simple_strtol(buf, NULL, 0);
+
+	if (val < 0)
+		return -EINVAL;
+
+	*(u32 *)((char *)qibp + dattr->counter) = (u32)val;
+	return strnlen(buf, PAGE_SIZE);
+}
+
 static const struct sysfs_ops qib_diagc_ops = {
 	.show = diagc_attr_show,
+	.store = diagc_attr_store,
 };
 
 static struct kobj_type qib_diagc_ktype = {
Signature · 6 lines
1.5.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw
In reply to a message not in the archive
Quoted 49 lines · Ira Weiny
Quoted 29 lines · On Thu, 8 Jul 2010 10:37:26 -0700 Bart Van Assche…
Quoted 28 lines · Ira Weiny

From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-

 1 files changed, 15 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +1 -1
index dab4d9f..91cd1b8 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
  #define QIB_DIAGC_ATTR(N) \
        static struct qib_diagc_attr qib_diagc_attr_##N = { \
-               .attr = { .name = __stringify(N), .mode = 0444 }, \
+               .attr = { .name = __stringify(N), .mode = 0664 }, \
                .counter = offsetof(struct qib_ibport, n_##N) \
        }
 
@@ -403,8 +403,22 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
        return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  }
 
Quoted 15 lines

drivers/infiniband/hw/qib/qib_sysfs.c static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, · line 416

Quoted 11 lines
drivers/infiniband/hw/qib/qib_sysfs.c +11 -0
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buf, size_t size)
+{
+       struct qib_diagc_attr *dattr =
+               container_of(attr, struct qib_diagc_attr, attr);
+       struct qib_pportdata *ppd =
+               container_of(kobj, struct qib_pportdata, diagc_kobj);
+       struct qib_ibport *qibp = &ppd->ibport_data;
+
+       *(u32 *)((char *)qibp + dattr->counter) = simple_strtol(buf, NULL, 0);
+       return 4;

The above line is not correct -- it should probably be something like "return size;". See also
http://*git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/sysfs.txt.

Quoted 7 lines

My mistake.  From the document above the return should be:

return strnlen(buf, PAGE_SIZE);

Correct?

Also I think I should check for invalid values as well.

(resending as plain text)

The documented I referred to was written before the "size" argument was added to sysfs store methods. I'm not sure it is still required that the "buf" argument that is passed to store methods is '\0'-terminated. So both "return 4" and "return strnlen(buf, PAGE_SIZE)" can potentially return a value that is larger than the "size" argument, which I think is incorrect.

Sorry that I pointed you to misleading documentation.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#11 lore raw
In reply to a message not in the archive
Quoted 54 lines · On Fri, 9 Jul 2010 12:33:14 -0700 Bart Van Assche…
Quoted 53 lines · Ira Weiny
Quoted 29 lines · On Thu, 8 Jul 2010 10:37:26 -0700 Bart Van Assche…
Quoted 28 lines · Ira Weiny

From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-

 1 files changed, 15 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +1 -1
index dab4d9f..91cd1b8 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
  #define QIB_DIAGC_ATTR(N) \
        static struct qib_diagc_attr qib_diagc_attr_##N = { \
-               .attr = { .name = __stringify(N), .mode = 0444 }, \
+               .attr = { .name = __stringify(N), .mode = 0664 }, \
                .counter = offsetof(struct qib_ibport, n_##N) \
        }
 
@@ -403,8 +403,22 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
        return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  }
 
Quoted 15 lines

drivers/infiniband/hw/qib/qib_sysfs.c static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, · line 416

Quoted 11 lines
drivers/infiniband/hw/qib/qib_sysfs.c +11 -0
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buf, size_t size)
+{
+       struct qib_diagc_attr *dattr =
+               container_of(attr, struct qib_diagc_attr, attr);
+       struct qib_pportdata *ppd =
+               container_of(kobj, struct qib_pportdata, diagc_kobj);
+       struct qib_ibport *qibp = &ppd->ibport_data;
+
+       *(u32 *)((char *)qibp + dattr->counter) = simple_strtol(buf, NULL, 0);
+       return 4;

The above line is not correct -- it should probably be something like "return size;". See also
http://**git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/sysfs.txt.

My mistake.  From the document above the return should be:

return strnlen(buf, PAGE_SIZE);

Quoted 8 lines
Quoted 3 lines

Correct?

Also I think I should check for invalid values as well.

(resending as plain text)

The documented I referred to was written before the "size" argument was added to sysfs store methods.

Are you sure? The document's signature for store methods includes the size argument?

Quoted 7 lines

I'm not sure it is still required
that the "buf" argument that is passed to store methods is '\0'-terminated. So both "return 4" and "return strnlen(buf, PAGE_SIZE)" can potentially return a value that is larger than the "size" argument, which I think is incorrect.

Sorry that I pointed you to misleading documentation.

Also, the document is the same as the one in Roland's latest master. Is the document wrong? I have not found anything newer (22 February 2009).

Ira

Quoted 3 lines

Bart.

Signature · 9 lines
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw
In reply to a message not in the archive
Quoted 76 lines · Ira Weiny
Quoted 54 lines · On Fri, 9 Jul 2010 12:33:14 -0700 Bart Van Assche…
Quoted 53 lines · Ira Weiny
Quoted 29 lines · On Thu, 8 Jul 2010 10:37:26 -0700 Bart Van Assche…
Quoted 28 lines · Ira Weiny

From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-

 1 files changed, 15 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +1 -1
index dab4d9f..91cd1b8 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
  #define QIB_DIAGC_ATTR(N) \
        static struct qib_diagc_attr qib_diagc_attr_##N = { \
-               .attr = { .name = __stringify(N), .mode = 0444 }, \
+               .attr = { .name = __stringify(N), .mode = 0664 }, \
                .counter = offsetof(struct qib_ibport, n_##N) \
        }
 
@@ -403,8 +403,22 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
        return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  }
 
Quoted 15 lines

drivers/infiniband/hw/qib/qib_sysfs.c static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, · line 416

Quoted 11 lines
drivers/infiniband/hw/qib/qib_sysfs.c +11 -0
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buf, size_t size)
+{
+       struct qib_diagc_attr *dattr =
+               container_of(attr, struct qib_diagc_attr, attr);
+       struct qib_pportdata *ppd =
+               container_of(kobj, struct qib_pportdata, diagc_kobj);
+       struct qib_ibport *qibp = &ppd->ibport_data;
+
+       *(u32 *)((char *)qibp + dattr->counter) = simple_strtol(buf, NULL, 0);
+       return 4;

The above line is not correct -- it should probably be something like "return size;". See also
http://**git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/sysfs.txt.

My mistake.  From the document above the return should be:

return strnlen(buf, PAGE_SIZE);

Quoted 8 lines
Quoted 3 lines

Correct?

Also I think I should check for invalid values as well.

(resending as plain text)

The documented I referred to was written before the "size" argument was added to sysfs store methods.

Are you sure?  The document's signature for store methods includes the size argument?

Quoted 6 lines

I'm not sure it is still required
that the "buf" argument that is passed to store methods is '\0'-terminated. So both "return 4" and "return strnlen(buf, PAGE_SIZE)" can potentially return a value that is larger than the "size" argument, which I think is incorrect.

Quoted 4 lines
Quoted 1 line

Sorry that I pointed you to misleading documentation.

Also, the document is the same as the one in Roland's latest master.  Is the document wrong?  I have not found anything newer (22 February 2009).

Let's ask the experts. The feedback on the sysfs documentation patch that I just submitted will tell us whether or not the sysfs documentation is correct (http://lkml.org/lkml/2010/7/10/72).

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw
In reply to a message not in the archive
Quoted 78 lines · Bart Van Assche
Quoted 76 lines · Ira Weiny
Quoted 54 lines · On Fri, 9 Jul 2010 12:33:14 -0700 Bart Van Assche…
Quoted 53 lines · Ira Weiny
Quoted 29 lines · On Thu, 8 Jul 2010 10:37:26 -0700 Bart Van Assche…
Quoted 28 lines · Ira Weiny

From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-

 1 files changed, 15 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +1 -1
index dab4d9f..91cd1b8 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
  #define QIB_DIAGC_ATTR(N) \
        static struct qib_diagc_attr qib_diagc_attr_##N = { \
-               .attr = { .name = __stringify(N), .mode = 0444 }, \
+               .attr = { .name = __stringify(N), .mode = 0664 }, \
                .counter = offsetof(struct qib_ibport, n_##N) \
        }
 
@@ -403,8 +403,22 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
        return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  }
 
Quoted 15 lines

drivers/infiniband/hw/qib/qib_sysfs.c static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, · line 416

Quoted 11 lines
drivers/infiniband/hw/qib/qib_sysfs.c +11 -0
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buf, size_t size)
+{
+       struct qib_diagc_attr *dattr =
+               container_of(attr, struct qib_diagc_attr, attr);
+       struct qib_pportdata *ppd =
+               container_of(kobj, struct qib_pportdata, diagc_kobj);
+       struct qib_ibport *qibp = &ppd->ibport_data;
+
+       *(u32 *)((char *)qibp + dattr->counter) = simple_strtol(buf, NULL, 0);
+       return 4;

The above line is not correct -- it should probably be something like "return size;". See also
http://**git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/sysfs.txt.

My mistake.  From the document above the return should be:

return strnlen(buf, PAGE_SIZE);

Quoted 8 lines
Quoted 3 lines

Correct?

Also I think I should check for invalid values as well.

(resending as plain text)

The documented I referred to was written before the "size" argument was added to sysfs store methods.

Are you sure?  The document's signature for store methods includes the size argument?

Quoted 6 lines

I'm not sure it is still required
that the "buf" argument that is passed to store methods is '\0'-terminated. So both "return 4" and "return strnlen(buf, PAGE_SIZE)" can potentially return a value that is larger than the "size" argument, which I think is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Sorry that I pointed you to misleading documentation.

Also, the document is the same as the one in Roland's latest master.  Is the document wrong?  I have not found anything newer (22 February 2009).

Let's ask the experts. The feedback on the sysfs documentation patch that I just submitted will tell us whether or not the sysfs documentation is correct (http://lkml.org/lkml/2010/7/10/72).

I have just received a private e-mail that informed me that Andrew Morton was so kind to sign off that sysfs documentation patch and to add it to his -mm tree. So if nobody complains about that patch within the next few days, that patch will be integrated in a future version of the Linux kernel.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#17 lore raw
In reply to a message not in the archive
Quoted 88 lines · On Tue, 13 Jul 2010 03:31:09 -0700 Bart Van Assche…
Quoted 78 lines · Bart Van Assche
Quoted 76 lines · Ira Weiny
Quoted 54 lines · On Fri, 9 Jul 2010 12:33:14 -0700 Bart Van Assche…
Quoted 53 lines · Ira Weiny
Quoted 29 lines · On Thu, 8 Jul 2010 10:37:26 -0700 Bart Van Assche…
Quoted 28 lines · Ira Weiny

From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Wed, 7 Jul 2010 17:35:34 -0700
Subject: [PATCH] ib_qib: Allow writes to the diag_counters to be able to clear them

---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-

 1 files changed, 15 insertions(+), 1 deletions(-)
drivers/infiniband/hw/qib/qib_sysfs.c +1 -1
index dab4d9f..91cd1b8 100644
@@ -347,7 +347,7 @@ static struct kobj_type qib_sl2vl_ktype = {
 
  #define QIB_DIAGC_ATTR(N) \
        static struct qib_diagc_attr qib_diagc_attr_##N = { \
-               .attr = { .name = __stringify(N), .mode = 0444 }, \
+               .attr = { .name = __stringify(N), .mode = 0664 }, \
                .counter = offsetof(struct qib_ibport, n_##N) \
        }
 
@@ -403,8 +403,22 @@ static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
        return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  }
 
Quoted 15 lines

drivers/infiniband/hw/qib/qib_sysfs.c static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, · line 416

Quoted 11 lines
drivers/infiniband/hw/qib/qib_sysfs.c +11 -0
+static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buf, size_t size)
+{
+       struct qib_diagc_attr *dattr =
+               container_of(attr, struct qib_diagc_attr, attr);
+       struct qib_pportdata *ppd =
+               container_of(kobj, struct qib_pportdata, diagc_kobj);
+       struct qib_ibport *qibp = &ppd->ibport_data;
+
+       *(u32 *)((char *)qibp + dattr->counter) = simple_strtol(buf, NULL, 0);
+       return 4;

The above line is not correct -- it should probably be something like "return size;". See also
http://***git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/sysfs.txt.

My mistake.  From the document above the return should be:

return strnlen(buf, PAGE_SIZE);

Quoted 8 lines
Quoted 3 lines

Correct?

Also I think I should check for invalid values as well.

(resending as plain text)

The documented I referred to was written before the "size" argument was added to sysfs store methods.

Are you sure?  The document's signature for store methods includes the size argument?

Quoted 6 lines

I'm not sure it is still required
that the "buf" argument that is passed to store methods is '\0'-terminated. So both "return 4" and "return strnlen(buf, PAGE_SIZE)" can potentially return a value that is larger than the "size" argument, which I think is incorrect.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Sorry that I pointed you to misleading documentation.

Also, the document is the same as the one in Roland's latest master.  Is the document wrong?  I have not found anything newer (22 February 2009).

Let's ask the experts. The feedback on the sysfs documentation patch that I just submitted will tell us whether or not the sysfs documentation is correct (http://*lkml.org/lkml/2010/7/10/72).

Quoted 5 lines

I have just received a private e-mail that informed me that Andrew Morton was so kind to sign off that sysfs documentation patch and to add it to his -mm tree. So if nobody complains about that patch within the next few days, that patch will be integrated in a future version of the Linux kernel.

Sorry, I see where my mistake was. Some of the store methods did have a count parameter and others (more importantly the sysfs_ops structure) did not. :-)

I will send out V3 shortly. There was one more place the count parameter was missing:

Documentation/filesystems/sysfs.txt +1 -1
index d78ed0b..c853eee 100644
@@ -333,7 +333,7 @@ Structure:
 struct bus_attribute {
         struct attribute        attr;
         ssize_t (*show)(struct bus_type *, char * buf);
-        ssize_t (*store)(struct bus_type *, const char * buf);
+        ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
 };
 
 Declaring:

I can send a patch if you like.

Thanks for the help,
Ira

Quoted 3 lines

Bart.

Signature · 9 lines
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw
In reply to a message not in the archive

So Ralph, I'm relying on you to decide if this makes sense...

Signature · 6 lines
Roland Dreier <[email protected]> || For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/index.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html