Skip to contentSkip to conversation

off by one in sysfs

DISCUSSION Jon Smirl 2 participants 6 messages Jun 12, 2005 – Jun 14, 2005 Driver core

lore
Share & tools
lore

Jon Smirl

author
#0 lore raw

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.

Signature · 2 lines
Jon Smirl
[email protected]
author
#1 lore raw

Patch to fix the off by one.

fs/sysfs/file.c +1 -1
@@ -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;
#2 lore raw
Quoted 1 line · Jon Smirl

Patch to fix the off by one.

Looks good, thanks.

greg k-h

#3 lore raw
In reply to Jon Smirl
Quoted 1 line · Jon Smirl

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

author
#4 lore raw
Quoted 5 lines · Greg KH
Quoted 1 line · Jon Smirl

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.

Quoted 5 lines

thanks,

greg k-h

Signature · 2 lines
Jon Smirl
[email protected]
#5 lore raw
Quoted 9 lines · Jon Smirl
Quoted 5 lines · Greg KH
Quoted 1 line · Jon Smirl

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