off by one in sysfs
sysfs/file.c
static intfill_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]
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;
Quoted 1 line · Jon Smirl
Patch to fix the off by one.
Looks good, thanks.
greg k-h
Quoted 1 line · Jon Smirl
My attribute is a
color_mapdescribed 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
Quoted 5 lines · Greg KH
Quoted 1 line · Jon Smirl
My attribute is a
color_mapdescribed 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]
Quoted 9 lines · Jon Smirl
Quoted 5 lines · Greg KH
Quoted 1 line · Jon Smirl
My attribute is a
color_mapdescribed 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