All of lore.kernel.org
 help / color / mirror / Atom feed
* ib_qib: Allow writes to the diag_counters to be able to clear them
@ 2010-07-08  0:33 Ira Weiny
       [not found] ` <20100707173313.675cd665.weiny2-i2BcT+NCU+M@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Ira Weiny @ 2010-07-08  0:33 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA; +Cc: Roland Dreier, Ralph Campbell

>From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
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


Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
---
 drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
index dab4d9f..91cd1b8 100644
--- a/drivers/infiniband/hw/qib/qib_sysfs.c
+++ b/drivers/infiniband/hw/qib/qib_sysfs.c
@@ -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 = {
-- 
1.5.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found] ` <20100707173313.675cd665.weiny2-i2BcT+NCU+M@public.gmane.org>
@ 2010-07-08 17:37   ` Bart Van Assche
       [not found]     ` <AANLkTin_OHC8r__FDXPY6QhCaXDYgNFDY9SeE8ffdc35-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Van Assche @ 2010-07-08 17:37 UTC (permalink / raw)
  To: Ira Weiny
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Roland Dreier, Ralph Campbell

On Thu, Jul 8, 2010 at 2:33 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
> From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> 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
>
>
> Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> ---
>  drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
>  1 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
> index dab4d9f..91cd1b8 100644
> --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> @@ -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;

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.

> +}
> +
>  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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found]     ` <AANLkTin_OHC8r__FDXPY6QhCaXDYgNFDY9SeE8ffdc35-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2010-07-08 18:04       ` Ira Weiny
       [not found]         ` <20100708110446.97317098.weiny2-i2BcT+NCU+M@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Ira Weiny @ 2010-07-08 18:04 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Roland Dreier, Ralph Campbell

On Thu, 8 Jul 2010 10:37:26 -0700
Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:

> On Thu, Jul 8, 2010 at 2:33 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
> > From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > 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
> >
> >
> > Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > ---
> >  drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
> >  1 files changed, 15 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
> > index dab4d9f..91cd1b8 100644
> > --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> > +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> > @@ -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;
> 
> 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

> 
> > +}
> > +
> >  static const struct sysfs_ops qib_diagc_ops = {
> >        .show = diagc_attr_show,
> > +       .store = diagc_attr_store,
> >  };
> >
> >  static struct kobj_type qib_diagc_ktype = {
> 


-- 
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
weiny2-i2BcT+NCU+M@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH V2] ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found]         ` <20100708110446.97317098.weiny2-i2BcT+NCU+M@public.gmane.org>
@ 2010-07-08 20:11           ` Ira Weiny
       [not found]             ` <20100708131105.4103a6e3.weiny2-i2BcT+NCU+M@public.gmane.org>
  2010-07-09 19:33           ` Bart Van Assche
  1 sibling, 1 reply; 10+ messages in thread
From: Ira Weiny @ 2010-07-08 20:11 UTC (permalink / raw)
  To: Bart Van Assche, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	Roland Dreier, Ralph Campbell


From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
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

Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
---
 drivers/infiniband/hw/qib/qib_sysfs.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
index dab4d9f..e4ec50e 100644
--- a/drivers/infiniband/hw/qib/qib_sysfs.c
+++ b/drivers/infiniband/hw/qib/qib_sysfs.c
@@ -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 = {
-- 
1.5.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found]         ` <20100708110446.97317098.weiny2-i2BcT+NCU+M@public.gmane.org>
  2010-07-08 20:11           ` [PATCH V2] " Ira Weiny
@ 2010-07-09 19:33           ` Bart Van Assche
       [not found]             ` <AANLkTik07Zp9uONyzBTAH4UnviviS-lopUJ42rZ5iQ_m-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  1 sibling, 1 reply; 10+ messages in thread
From: Bart Van Assche @ 2010-07-09 19:33 UTC (permalink / raw)
  To: Ira Weiny
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Roland Dreier, Ralph Campbell

On Thu, Jul 8, 2010 at 8:04 PM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
>
> On Thu, 8 Jul 2010 10:37:26 -0700
> Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
>
> > On Thu, Jul 8, 2010 at 2:33 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > > From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
> > > From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > 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
> > >
> > >
> > > Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > ---
> > >  drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
> > >  1 files changed, 15 insertions(+), 1 deletions(-)
> > >
> > > diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > index dab4d9f..91cd1b8 100644
> > > --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> > > +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > @@ -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;
> >
> > 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.

(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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found]             ` <AANLkTik07Zp9uONyzBTAH4UnviviS-lopUJ42rZ5iQ_m-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2010-07-10  0:56               ` Ira Weiny
       [not found]                 ` <20100709175615.2e093989.weiny2-i2BcT+NCU+M@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Ira Weiny @ 2010-07-10  0:56 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Roland Dreier, Ralph Campbell

On Fri, 9 Jul 2010 12:33:14 -0700
Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:

> On Thu, Jul 8, 2010 at 8:04 PM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> >
> > On Thu, 8 Jul 2010 10:37:26 -0700
> > Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
> >
> > > On Thu, Jul 8, 2010 at 2:33 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > > > From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
> > > > From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > > 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
> > > >
> > > >
> > > > Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > > ---
> > > >  drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
> > > >  1 files changed, 15 insertions(+), 1 deletions(-)
> > > >
> > > > diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > index dab4d9f..91cd1b8 100644
> > > > --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > @@ -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;
> > >
> > > 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.
> 
> (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?

> 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

> 
> Bart.
> 



-- 
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
weiny2-i2BcT+NCU+M@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found]                 ` <20100709175615.2e093989.weiny2-i2BcT+NCU+M@public.gmane.org>
@ 2010-07-10 15:25                   ` Bart Van Assche
       [not found]                     ` <AANLkTik7MnJGL3Hlz1vqkmyruK7pRwyBWgKfTd0Lknpe-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Van Assche @ 2010-07-10 15:25 UTC (permalink / raw)
  To: Ira Weiny
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Roland Dreier, Ralph Campbell

On Sat, Jul 10, 2010 at 2:56 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
>
> On Fri, 9 Jul 2010 12:33:14 -0700
> Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
>
> > On Thu, Jul 8, 2010 at 8:04 PM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > >
> > > On Thu, 8 Jul 2010 10:37:26 -0700
> > > Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
> > >
> > > > On Thu, Jul 8, 2010 at 2:33 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > > > > From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
> > > > > From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > > > 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
> > > > >
> > > > >
> > > > > Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > > > ---
> > > > >  drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
> > > > >  1 files changed, 15 insertions(+), 1 deletions(-)
> > > > >
> > > > > diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > index dab4d9f..91cd1b8 100644
> > > > > --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > @@ -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;
> > > >
> > > > 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.
> >
> > (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?
>
> > 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).

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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found]                     ` <AANLkTik7MnJGL3Hlz1vqkmyruK7pRwyBWgKfTd0Lknpe-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2010-07-13 10:31                       ` Bart Van Assche
       [not found]                         ` <AANLkTil_p-lJmUGMzzPPj6Dx52jh_xbhN2Zt5uLZM53E-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Van Assche @ 2010-07-13 10:31 UTC (permalink / raw)
  To: Ira Weiny
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Roland Dreier, Ralph Campbell

On Sat, Jul 10, 2010 at 5:25 PM, Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
>
> On Sat, Jul 10, 2010 at 2:56 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> >
> > On Fri, 9 Jul 2010 12:33:14 -0700
> > Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
> >
> > > On Thu, Jul 8, 2010 at 8:04 PM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > > >
> > > > On Thu, 8 Jul 2010 10:37:26 -0700
> > > > Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
> > > >
> > > > > On Thu, Jul 8, 2010 at 2:33 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > > > > > From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
> > > > > > From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > > > > 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
> > > > > >
> > > > > >
> > > > > > Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > > > > ---
> > > > > >  drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
> > > > > >  1 files changed, 15 insertions(+), 1 deletions(-)
> > > > > >
> > > > > > diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > > index dab4d9f..91cd1b8 100644
> > > > > > --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > > +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > > @@ -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;
> > > > >
> > > > > 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.
> > >
> > > (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?
> >
> > > 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).
>
> 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found]                         ` <AANLkTil_p-lJmUGMzzPPj6Dx52jh_xbhN2Zt5uLZM53E-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2010-07-14  1:50                           ` Ira Weiny
  0 siblings, 0 replies; 10+ messages in thread
From: Ira Weiny @ 2010-07-14  1:50 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Roland Dreier, Ralph Campbell

On Tue, 13 Jul 2010 03:31:09 -0700
Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:

> On Sat, Jul 10, 2010 at 5:25 PM, Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
> >
> > On Sat, Jul 10, 2010 at 2:56 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > >
> > > On Fri, 9 Jul 2010 12:33:14 -0700
> > > Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
> > >
> > > > On Thu, Jul 8, 2010 at 8:04 PM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > > > >
> > > > > On Thu, 8 Jul 2010 10:37:26 -0700
> > > > > Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org> wrote:
> > > > >
> > > > > > On Thu, Jul 8, 2010 at 2:33 AM, Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org> wrote:
> > > > > > > From 80eecc4046455999254fb312c4ba229b3a52d4c6 Mon Sep 17 00:00:00 2001
> > > > > > > From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > > > > > 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
> > > > > > >
> > > > > > >
> > > > > > > Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> > > > > > > ---
> > > > > > >  drivers/infiniband/hw/qib/qib_sysfs.c |   16 +++++++++++++++-
> > > > > > >  1 files changed, 15 insertions(+), 1 deletions(-)
> > > > > > >
> > > > > > > diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > > > index dab4d9f..91cd1b8 100644
> > > > > > > --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > > > +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> > > > > > > @@ -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;
> > > > > >
> > > > > > 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.
> > > >
> > > > (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?
> > >
> > > > 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).
> >
> > 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.

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:

diff --git a/Documentation/filesystems/sysfs.txt b/Documentation/filesystems/sysfs.txt
index d78ed0b..c853eee 100644
--- a/Documentation/filesystems/sysfs.txt
+++ b/Documentation/filesystems/sysfs.txt
@@ -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

> 
> Bart.
> 


-- 
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
weiny2-i2BcT+NCU+M@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] ib_qib: Allow writes to the diag_counters to be able to clear them
       [not found]             ` <20100708131105.4103a6e3.weiny2-i2BcT+NCU+M@public.gmane.org>
@ 2010-07-21 18:40               ` Roland Dreier
  0 siblings, 0 replies; 10+ messages in thread
From: Roland Dreier @ 2010-07-21 18:40 UTC (permalink / raw)
  To: Ira Weiny; +Cc: Bart Van Assche, linux-rdma@vger.kernel.org, Ralph Campbell

So Ralph, I'm relying on you to decide if this makes sense...
-- 
Roland Dreier <rolandd-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org> || 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-07-21 18:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-08  0:33 ib_qib: Allow writes to the diag_counters to be able to clear them Ira Weiny
     [not found] ` <20100707173313.675cd665.weiny2-i2BcT+NCU+M@public.gmane.org>
2010-07-08 17:37   ` Bart Van Assche
     [not found]     ` <AANLkTin_OHC8r__FDXPY6QhCaXDYgNFDY9SeE8ffdc35-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-08 18:04       ` Ira Weiny
     [not found]         ` <20100708110446.97317098.weiny2-i2BcT+NCU+M@public.gmane.org>
2010-07-08 20:11           ` [PATCH V2] " Ira Weiny
     [not found]             ` <20100708131105.4103a6e3.weiny2-i2BcT+NCU+M@public.gmane.org>
2010-07-21 18:40               ` Roland Dreier
2010-07-09 19:33           ` Bart Van Assche
     [not found]             ` <AANLkTik07Zp9uONyzBTAH4UnviviS-lopUJ42rZ5iQ_m-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-10  0:56               ` Ira Weiny
     [not found]                 ` <20100709175615.2e093989.weiny2-i2BcT+NCU+M@public.gmane.org>
2010-07-10 15:25                   ` Bart Van Assche
     [not found]                     ` <AANLkTik7MnJGL3Hlz1vqkmyruK7pRwyBWgKfTd0Lknpe-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-13 10:31                       ` Bart Van Assche
     [not found]                         ` <AANLkTil_p-lJmUGMzzPPj6Dx52jh_xbhN2Zt5uLZM53E-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-14  1:50                           ` Ira Weiny

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.