Linux-NVDIMM Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range()
@ 2020-12-19  8:18 Zhen Lei
  2020-12-19  8:18 ` [PATCH v2 1/1] " Zhen Lei
  0 siblings, 1 reply; 2+ messages in thread
From: Zhen Lei @ 2020-12-19  8:18 UTC (permalink / raw)
  To: Dan Williams, Vishal Verma, Dave Jiang, linux-nvdimm,
	linux-kernel; +Cc: Zhen Lei

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(-)

-- 
2.26.0.106.g9fadedd

_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2 1/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range()
  2020-12-19  8:18 [PATCH v2 0/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range() Zhen Lei
@ 2020-12-19  8:18 ` Zhen Lei
  0 siblings, 0 replies; 2+ messages in thread
From: Zhen Lei @ 2020-12-19  8:18 UTC (permalink / raw)
  To: Dan Williams, Vishal Verma, Dave Jiang, linux-nvdimm,
	linux-kernel; +Cc: Zhen Lei

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>
---
 drivers/dax/bus.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index de7b74505e75e72..359e22ece425ad2 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;
 	}
 
-- 
2.26.0.106.g9fadedd

_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-19  8:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-19  8:18 [PATCH v2 0/1] device-dax: avoid an unnecessary check in alloc_dev_dax_range() Zhen Lei
2020-12-19  8:18 ` [PATCH v2 1/1] " Zhen Lei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox