configfs fix for Linux 5.14
- fix the read and write iterators (Bart Van Assche) -----BEGIN PGP SIGNATURE----- iQI/BAABCgApFiEEgdbnc3r/njty3Iq9D55TZVIEUYMFAmDvEUkLHGhjaEBsc3Qu ZGUACgkQD55TZVIEUYNf8BAAwdXyOpuKOrcSn9jx1vk/feDLDB+aGeHUrV1KjRDM rEYLSQXoJAEvvrtG+IRXhBPKBhAKGl0ltESAgGe0VQcVlCad7c7cwS0XWd0TJJqQ GbylrtWMQTilHTw4HLKAAoenGD4KcZdSn4ty5go+W6hPTjv6w5+ArLWY2YFaeWHT /flOR+UbL9BAxNDwZVZCGym0p/Dth4SyMbPAH91MXJAiR5xYD3v+nKXlc5fPTvIE 7hCeLEYK5Jxjx3uUffdPOybYIRGSUSVAmFYpvZ8Z9HfXxZ3i4yjFZhUe+1jSuB5O 7f12D0Ak4tCvAMhnXnOvcsxi6ZXP2ry6lro3/fe+rq1EdQBOY6rFQUcYiPMRVyu7 iKHLy/rHTtrmiGJIy8IjoyVBSryDbW1I/KpjVo0Rgo2r+A8i6mEFkID77+BnJ1Zp sedxmPXcsAGkd57DZeRrWyegCaAKreuhQmvxCcenD6ZR2qj13K7olRzvoyAvM/zB HF/R/cqgoNIc3tS5UbLB2ObFphzFmvYWpbSw2XawI6HO4F4xZ9dHyOS2Kormh91i qqgRl61B5CpD3mek+hPz1uw701IRUOWM5KegE9e0w+GLF9s5oSf0UMWATP2KsPSi 9iluJj/FKIiP3Qdiz8+2o+BG+otmL86n8MrVISB86Jmr+q6YtUYeq1Q4ZXBJJ9kX zRc= =sDu1 -----END PGP SIGNATURE----- Merge tag 'configfs-5.13-1' of git://git.infradead.org/users/hch/configfs Pull configfs fix from Christoph Hellwig: - fix the read and write iterators (Bart Van Assche) * tag 'configfs-5.13-1' of git://git.infradead.org/users/hch/configfs: configfs: fix the read and write iterators
This commit is contained in:
commit
1013d4add2
@ -91,7 +91,10 @@ static ssize_t configfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
||||
}
|
||||
pr_debug("%s: count = %zd, pos = %lld, buf = %s\n",
|
||||
__func__, iov_iter_count(to), iocb->ki_pos, buffer->page);
|
||||
retval = copy_to_iter(buffer->page, buffer->count, to);
|
||||
if (iocb->ki_pos >= buffer->count)
|
||||
goto out;
|
||||
retval = copy_to_iter(buffer->page + iocb->ki_pos,
|
||||
buffer->count - iocb->ki_pos, to);
|
||||
iocb->ki_pos += retval;
|
||||
if (retval == 0)
|
||||
retval = -EFAULT;
|
||||
@ -162,7 +165,10 @@ static ssize_t configfs_bin_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
||||
buffer->needs_read_fill = 0;
|
||||
}
|
||||
|
||||
retval = copy_to_iter(buffer->bin_buffer, buffer->bin_buffer_size, to);
|
||||
if (iocb->ki_pos >= buffer->bin_buffer_size)
|
||||
goto out;
|
||||
retval = copy_to_iter(buffer->bin_buffer + iocb->ki_pos,
|
||||
buffer->bin_buffer_size - iocb->ki_pos, to);
|
||||
iocb->ki_pos += retval;
|
||||
if (retval == 0)
|
||||
retval = -EFAULT;
|
||||
@ -171,21 +177,28 @@ out:
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int fill_write_buffer(struct configfs_buffer *buffer,
|
||||
/* Fill [buffer, buffer + pos) with data coming from @from. */
|
||||
static int fill_write_buffer(struct configfs_buffer *buffer, loff_t pos,
|
||||
struct iov_iter *from)
|
||||
{
|
||||
loff_t to_copy;
|
||||
int copied;
|
||||
u8 *to;
|
||||
|
||||
if (!buffer->page)
|
||||
buffer->page = (char *)__get_free_pages(GFP_KERNEL, 0);
|
||||
if (!buffer->page)
|
||||
return -ENOMEM;
|
||||
|
||||
copied = copy_from_iter(buffer->page, SIMPLE_ATTR_SIZE - 1, from);
|
||||
to_copy = SIMPLE_ATTR_SIZE - 1 - pos;
|
||||
if (to_copy <= 0)
|
||||
return 0;
|
||||
to = buffer->page + pos;
|
||||
copied = copy_from_iter(to, to_copy, from);
|
||||
buffer->needs_read_fill = 1;
|
||||
/* if buf is assumed to contain a string, terminate it by \0,
|
||||
* so e.g. sscanf() can scan the string easily */
|
||||
buffer->page[copied] = 0;
|
||||
to[copied] = 0;
|
||||
return copied ? : -EFAULT;
|
||||
}
|
||||
|
||||
@ -217,7 +230,7 @@ static ssize_t configfs_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
||||
ssize_t len;
|
||||
|
||||
mutex_lock(&buffer->mutex);
|
||||
len = fill_write_buffer(buffer, from);
|
||||
len = fill_write_buffer(buffer, iocb->ki_pos, from);
|
||||
if (len > 0)
|
||||
len = flush_write_buffer(file, buffer, len);
|
||||
if (len > 0)
|
||||
@ -272,7 +285,9 @@ static ssize_t configfs_bin_write_iter(struct kiocb *iocb,
|
||||
buffer->bin_buffer_size = end_offset;
|
||||
}
|
||||
|
||||
len = copy_from_iter(buffer->bin_buffer, buffer->bin_buffer_size, from);
|
||||
len = copy_from_iter(buffer->bin_buffer + iocb->ki_pos,
|
||||
buffer->bin_buffer_size - iocb->ki_pos, from);
|
||||
iocb->ki_pos += len;
|
||||
out:
|
||||
mutex_unlock(&buffer->mutex);
|
||||
return len ? : -EFAULT;
|
||||
|
Loading…
Reference in New Issue
Block a user