Skip to contentSkip to conversation

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

PATCH New Zhen Lei 1 participant 2 messages Dec 19, 2020

Subsystems (2)
lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

v2 cover device-dax: avoid an unnecessary check in alloc_dev_dax_range()

v1 --> v2:
In v1, I use the "goto" statement to merge two identical __release_region() calls. However, the new patch https://lkml.org/lkml/2020/12/18/735 deletes one of them, the "goto" becomes worthless. So when krealloc() failed, directly call __release_region() and return error code.

Zhen Lei (1):
device-dax: avoid an unnecessary check in alloc_dev_dax_range()

 drivers/dax/bus.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
Signature · 5 lines
2.26.0.106.g9fadedd

_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
author
#1 lore raw

PATCH v2 1/1 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.

---
 drivers/dax/bus.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/dax/bus.c +6 -14
index de7b74505e75e72..359e22ece425ad2 100644
@@ -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;
 	}
 
Signature · 5 lines
2.26.0.106.g9fadedd

_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]