Skip to content

Commit

Permalink
cifs: Fix memory leak when using fscache
Browse files Browse the repository at this point in the history
If we hit the 'index == next_cached' case, we leak a refcount on the
struct page.  Fix this by using readahead_folio() which takes care of
the refcount for you.

Fixes: 0174ee9 ("cifs: Implement cache I/O by accessing the cache directly")
Cc: David Howells <dhowells@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Matthew Wilcox (Oracle) authored and Steve French committed Aug 1, 2022
1 parent 89e42f4 commit c6f62f8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -4459,18 +4459,18 @@ static void cifs_readahead(struct readahead_control *ractl)
* TODO: Send a whole batch of pages to be read
* by the cache.
*/
page = readahead_page(ractl);
last_batch_size = 1 << thp_order(page);
struct folio *folio = readahead_folio(ractl);
last_batch_size = folio_nr_pages(folio);
if (cifs_readpage_from_fscache(ractl->mapping->host,
page) < 0) {
&folio->page) < 0) {
/*
* TODO: Deal with cache read failure
* here, but for the moment, delegate
* that to readpage.
*/
caching = false;
}
unlock_page(page);
folio_unlock(folio);
next_cached++;
cache_nr_pages--;
if (cache_nr_pages == 0)
Expand Down

0 comments on commit c6f62f8

Please sign in to comment.