Commit ff8da37d authored by Zhen Lei's avatar Zhen Lei Committed by Dan Williams

device-dax: Avoid an unnecessary check in alloc_dev_dax_range()

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: default avatarZhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20201219081840.1149-2-thunder.leizhen@huawei.comSigned-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 6268d7da
...@@ -772,22 +772,14 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, ...@@ -772,22 +772,14 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start,
return 0; return 0;
} }
ranges = krealloc(dev_dax->ranges, sizeof(*ranges) alloc = __request_region(res, start, size, dev_name(dev), 0);
* (dev_dax->nr_range + 1), GFP_KERNEL); if (!alloc)
if (!ranges)
return -ENOMEM; return -ENOMEM;
alloc = __request_region(res, start, size, dev_name(dev), 0); ranges = krealloc(dev_dax->ranges, sizeof(*ranges)
if (!alloc) { * (dev_dax->nr_range + 1), GFP_KERNEL);
/* if (!ranges) {
* If this was an empty set of ranges nothing else __release_region(res, alloc->start, resource_size(alloc));
* will release @ranges, so do it now.
*/
if (!dev_dax->nr_range) {
kfree(ranges);
ranges = NULL;
}
dev_dax->ranges = ranges;
return -ENOMEM; return -ENOMEM;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment