Skip to content

Commit

Permalink
mm/filemap: fix readahead return types
Browse files Browse the repository at this point in the history
A readahead request will not allocate more memory than can be represented
by a size_t, even on systems that have HIGHMEM available.  Change the
length functions from returning an loff_t to a size_t.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 32c0a6b ("btrfs: add and use readahead_batch_length")
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Reported-by: Linus Torvalds <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) authored and torvalds committed May 15, 2021
1 parent f649dc0 commit 076171a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fs/iomap/buffered-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,15 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops)
{
struct inode *inode = rac->mapping->host;
loff_t pos = readahead_pos(rac);
loff_t length = readahead_length(rac);
size_t length = readahead_length(rac);
struct iomap_readpage_ctx ctx = {
.rac = rac,
};

trace_iomap_readahead(inode, readahead_count(rac));

while (length > 0) {
loff_t ret = iomap_apply(inode, pos, length, 0, ops,
ssize_t ret = iomap_apply(inode, pos, length, 0, ops,
&ctx, iomap_readahead_actor);
if (ret <= 0) {
WARN_ON_ONCE(ret == 0);
Expand Down
6 changes: 3 additions & 3 deletions include/linux/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,9 @@ static inline loff_t readahead_pos(struct readahead_control *rac)
* readahead_length - The number of bytes in this readahead request.
* @rac: The readahead request.
*/
static inline loff_t readahead_length(struct readahead_control *rac)
static inline size_t readahead_length(struct readahead_control *rac)
{
return (loff_t)rac->_nr_pages * PAGE_SIZE;
return rac->_nr_pages * PAGE_SIZE;
}

/**
Expand All @@ -1024,7 +1024,7 @@ static inline unsigned int readahead_count(struct readahead_control *rac)
* readahead_batch_length - The number of bytes in the current batch.
* @rac: The readahead request.
*/
static inline loff_t readahead_batch_length(struct readahead_control *rac)
static inline size_t readahead_batch_length(struct readahead_control *rac)
{
return rac->_batch_count * PAGE_SIZE;
}
Expand Down

0 comments on commit 076171a

Please sign in to comment.