mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-30 22:26:55 +00:00
brd: return 0/-error from brd_insert_page()
commit db0ccc44a2
upstream.
It currently returns a page, but callers just check for NULL/page to
gauge success. Clean this up and return the appropriate error directly
instead.
Cc: stable@vger.kernel.org # 5.10+
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
95bb37e077
commit
f832bd2ee4
1 changed files with 12 additions and 14 deletions
|
@ -78,11 +78,9 @@ static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look up and return a brd's page for a given sector.
|
* Insert a new page for a given sector, if one does not already exist.
|
||||||
* If one does not exist, allocate an empty page, and insert that. Then
|
|
||||||
* return it.
|
|
||||||
*/
|
*/
|
||||||
static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
|
static int brd_insert_page(struct brd_device *brd, sector_t sector)
|
||||||
{
|
{
|
||||||
pgoff_t idx;
|
pgoff_t idx;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
|
@ -90,7 +88,7 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
|
||||||
|
|
||||||
page = brd_lookup_page(brd, sector);
|
page = brd_lookup_page(brd, sector);
|
||||||
if (page)
|
if (page)
|
||||||
return page;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Must use NOIO because we don't want to recurse back into the
|
* Must use NOIO because we don't want to recurse back into the
|
||||||
|
@ -99,11 +97,11 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
|
||||||
gfp_flags = GFP_NOIO | __GFP_ZERO | __GFP_HIGHMEM;
|
gfp_flags = GFP_NOIO | __GFP_ZERO | __GFP_HIGHMEM;
|
||||||
page = alloc_page(gfp_flags);
|
page = alloc_page(gfp_flags);
|
||||||
if (!page)
|
if (!page)
|
||||||
return NULL;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (radix_tree_preload(GFP_NOIO)) {
|
if (radix_tree_preload(GFP_NOIO)) {
|
||||||
__free_page(page);
|
__free_page(page);
|
||||||
return NULL;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock(&brd->brd_lock);
|
spin_lock(&brd->brd_lock);
|
||||||
|
@ -120,8 +118,7 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
|
||||||
spin_unlock(&brd->brd_lock);
|
spin_unlock(&brd->brd_lock);
|
||||||
|
|
||||||
radix_tree_preload_end();
|
radix_tree_preload_end();
|
||||||
|
return 0;
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -174,16 +171,17 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n)
|
||||||
{
|
{
|
||||||
unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
|
unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
|
||||||
size_t copy;
|
size_t copy;
|
||||||
|
int ret;
|
||||||
|
|
||||||
copy = min_t(size_t, n, PAGE_SIZE - offset);
|
copy = min_t(size_t, n, PAGE_SIZE - offset);
|
||||||
if (!brd_insert_page(brd, sector))
|
ret = brd_insert_page(brd, sector);
|
||||||
return -ENOSPC;
|
if (ret)
|
||||||
|
return ret;
|
||||||
if (copy < n) {
|
if (copy < n) {
|
||||||
sector += copy >> SECTOR_SHIFT;
|
sector += copy >> SECTOR_SHIFT;
|
||||||
if (!brd_insert_page(brd, sector))
|
ret = brd_insert_page(brd, sector);
|
||||||
return -ENOSPC;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue