public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* off by one in sysfs
@ 2005-06-12  3:00 Jon Smirl
  2005-06-12 15:41 ` Jon Smirl
  2005-06-14 21:07 ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Jon Smirl @ 2005-06-12  3:00 UTC (permalink / raw)
  To: lkml, Greg KH

sysfs/file.c

static int 
fill_write_buffer(struct sysfs_buffer * buffer, const char __user *
buf, size_t count)
{
	int error;

	if (!buffer->page)
		buffer->page = (char *)get_zeroed_page(GFP_KERNEL);
	if (!buffer->page)
		return -ENOMEM;

	if (count >= PAGE_SIZE)
		count = PAGE_SIZE - 1;
	error = copy_from_user(buffer->page,buf,count);
	buffer->needs_read_fill = 1;
	return error ? -EFAULT : count;
}

count = PAGE_SIZE - 1;
should be 
count = PAGE_SIZE;

Even if your are trying to zero terminate which is unneeded when there
is a count, the count still needs to include the zero otherwise it is
inconsistent when count is less than PAGE_SIZE. Why get a zero page
too?

My attribute is a color_map described by 255 lines of 15 chars plus \n.

-- 
Jon Smirl
jonsmirl@gmail.com

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

* Re: off by one in sysfs
  2005-06-12  3:00 off by one in sysfs Jon Smirl
@ 2005-06-12 15:41 ` Jon Smirl
  2005-06-14 21:06   ` Greg KH
  2005-06-14 21:07 ` Greg KH
  1 sibling, 1 reply; 6+ messages in thread
From: Jon Smirl @ 2005-06-12 15:41 UTC (permalink / raw)
  To: lkml, Greg KH

Patch to fix the off by one.

signed-off-by: jonsmirl@gmail.com <Jon Smirl>
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -182,7 +182,7 @@ fill_write_buffer(struct sysfs_buffer * 
 		return -ENOMEM;
 
 	if (count >= PAGE_SIZE)
-		count = PAGE_SIZE - 1;
+		count = PAGE_SIZE;
 	error = copy_from_user(buffer->page,buf,count);
 	buffer->needs_read_fill = 1;
 	return error ? -EFAULT : count;

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

* Re: off by one in sysfs
  2005-06-12 15:41 ` Jon Smirl
@ 2005-06-14 21:06   ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2005-06-14 21:06 UTC (permalink / raw)
  To: Jon Smirl; +Cc: lkml

On Sun, Jun 12, 2005 at 11:41:32AM -0400, Jon Smirl wrote:
> Patch to fix the off by one.

Looks good, thanks.

greg k-h

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

* Re: off by one in sysfs
  2005-06-12  3:00 off by one in sysfs Jon Smirl
  2005-06-12 15:41 ` Jon Smirl
@ 2005-06-14 21:07 ` Greg KH
  2005-06-14 21:21   ` Jon Smirl
  1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2005-06-14 21:07 UTC (permalink / raw)
  To: Jon Smirl; +Cc: lkml

On Sat, Jun 11, 2005 at 11:00:00PM -0400, Jon Smirl wrote:
> My attribute is a color_map described by 255 lines of 15 chars plus \n.

Heh, that's pretty big for a single attribute.  Would it be easier to
just use the binary sysfs file interface for this attribute?

thanks,

greg k-h

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

* Re: off by one in sysfs
  2005-06-14 21:07 ` Greg KH
@ 2005-06-14 21:21   ` Jon Smirl
  2005-06-14 21:27     ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Jon Smirl @ 2005-06-14 21:21 UTC (permalink / raw)
  To: Greg KH; +Cc: lkml

On 6/14/05, Greg KH <greg@kroah.com> wrote:
> On Sat, Jun 11, 2005 at 11:00:00PM -0400, Jon Smirl wrote:
> > My attribute is a color_map described by 255 lines of 15 chars plus \n.
> 
> Heh, that's pretty big for a single attribute.  Would it be easier to
> just use the binary sysfs file interface for this attribute?

The attribute is formatted in ascii. You can use a script to set it if
you want. It is the gamma correction table for the monitor.

> 
> thanks,
> 
> greg k-h
> 


-- 
Jon Smirl
jonsmirl@gmail.com

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

* Re: off by one in sysfs
  2005-06-14 21:21   ` Jon Smirl
@ 2005-06-14 21:27     ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2005-06-14 21:27 UTC (permalink / raw)
  To: Jon Smirl; +Cc: lkml

On Tue, Jun 14, 2005 at 05:21:54PM -0400, Jon Smirl wrote:
> On 6/14/05, Greg KH <greg@kroah.com> wrote:
> > On Sat, Jun 11, 2005 at 11:00:00PM -0400, Jon Smirl wrote:
> > > My attribute is a color_map described by 255 lines of 15 chars plus \n.
> > 
> > Heh, that's pretty big for a single attribute.  Would it be easier to
> > just use the binary sysfs file interface for this attribute?
> 
> The attribute is formatted in ascii. You can use a script to set it if
> you want. It is the gamma correction table for the monitor.

Ok, just curious, no big deal.

greg k-h

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

end of thread, other threads:[~2005-06-14 21:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-12  3:00 off by one in sysfs Jon Smirl
2005-06-12 15:41 ` Jon Smirl
2005-06-14 21:06   ` Greg KH
2005-06-14 21:07 ` Greg KH
2005-06-14 21:21   ` Jon Smirl
2005-06-14 21:27     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox