Skip to content

Commit

Permalink
device-dax: Avoid an unnecessary check in alloc_dev_dax_range()
Browse files Browse the repository at this point in the history
Swap the calling sequence of krealloc() and __request_region(), call the
latter first. In this way, the value of dev_dax->nr_range does not need to
be considered when __request_region() failed.

Signed-off-by: Zhen Lei <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Dan Williams <[email protected]>
  • Loading branch information
Zhen Lei authored and djbw committed Dec 24, 2020
1 parent 6268d7d commit ff8da37
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions drivers/dax/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,22 +772,14 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start,
return 0;
}

ranges = krealloc(dev_dax->ranges, sizeof(*ranges)
* (dev_dax->nr_range + 1), GFP_KERNEL);
if (!ranges)
alloc = __request_region(res, start, size, dev_name(dev), 0);
if (!alloc)
return -ENOMEM;

alloc = __request_region(res, start, size, dev_name(dev), 0);
if (!alloc) {
/*
* If this was an empty set of ranges nothing else
* will release @ranges, so do it now.
*/
if (!dev_dax->nr_range) {
kfree(ranges);
ranges = NULL;
}
dev_dax->ranges = ranges;
ranges = krealloc(dev_dax->ranges, sizeof(*ranges)
* (dev_dax->nr_range + 1), GFP_KERNEL);
if (!ranges) {
__release_region(res, alloc->start, resource_size(alloc));
return -ENOMEM;
}

Expand Down

0 comments on commit ff8da37

Please sign in to comment.