diff options
author | Zhen Lei <thunder.leizhen@huawei.com> | 2020-12-19 16:18:40 +0800 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2020-12-24 10:06:57 -0800 |
commit | ff8da37d3d8d438ded5a4841d979899269b94d0d (patch) | |
tree | 2befe2f7e2644a83c0b8a8721e909e282f60efdd /drivers/dax | |
parent | 6268d7da4d192af339f4d688942b9ccb45a65e04 (diff) | |
download | linux-ff8da37d3d8d438ded5a4841d979899269b94d0d.tar.gz linux-ff8da37d3d8d438ded5a4841d979899269b94d0d.tar.bz2 linux-ff8da37d3d8d438ded5a4841d979899269b94d0d.zip |
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: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20201219081840.1149-2-thunder.leizhen@huawei.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/dax')
-rw-r--r-- | drivers/dax/bus.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 720cd140209f..737b207c9e30 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -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; } |