Skip to content

Commit db0ccc4

Browse files
committed
brd: return 0/-error from brd_insert_page()
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: [email protected] # 5.10+ Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 3ce6a11 commit db0ccc4

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

drivers/block/brd.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,17 @@ static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
7878
}
7979

8080
/*
81-
* Look up and return a brd's page for a given sector.
82-
* If one does not exist, allocate an empty page, and insert that. Then
83-
* return it.
81+
* Insert a new page for a given sector, if one does not already exist.
8482
*/
85-
static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
83+
static int brd_insert_page(struct brd_device *brd, sector_t sector)
8684
{
8785
pgoff_t idx;
8886
struct page *page;
8987
gfp_t gfp_flags;
9088

9189
page = brd_lookup_page(brd, sector);
9290
if (page)
93-
return page;
91+
return 0;
9492

9593
/*
9694
* 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)
9997
gfp_flags = GFP_NOIO | __GFP_ZERO | __GFP_HIGHMEM;
10098
page = alloc_page(gfp_flags);
10199
if (!page)
102-
return NULL;
100+
return -ENOMEM;
103101

104102
if (radix_tree_preload(GFP_NOIO)) {
105103
__free_page(page);
106-
return NULL;
104+
return -ENOMEM;
107105
}
108106

109107
spin_lock(&brd->brd_lock);
@@ -120,8 +118,7 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
120118
spin_unlock(&brd->brd_lock);
121119

122120
radix_tree_preload_end();
123-
124-
return page;
121+
return 0;
125122
}
126123

127124
/*
@@ -174,16 +171,17 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n)
174171
{
175172
unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
176173
size_t copy;
174+
int ret;
177175

178176
copy = min_t(size_t, n, PAGE_SIZE - offset);
179-
if (!brd_insert_page(brd, sector))
180-
return -ENOSPC;
177+
ret = brd_insert_page(brd, sector);
178+
if (ret)
179+
return ret;
181180
if (copy < n) {
182181
sector += copy >> SECTOR_SHIFT;
183-
if (!brd_insert_page(brd, sector))
184-
return -ENOSPC;
182+
ret = brd_insert_page(brd, sector);
185183
}
186-
return 0;
184+
return ret;
187185
}
188186

189187
/*

0 commit comments

Comments
 (0)