[4/5] libnvdimm, namespace: extract __init_active_labels to initialize labels for one nd_mapping
diff mbox series

Message ID 20190128003018.4087-4-richardw.yang@linux.intel.com
State New
Headers show
Series
  • [1/5] libnvdimm, namespace: release labels properly on error
Related show

Commit Message

Wei Yang Jan. 28, 2019, 12:30 a.m. UTC
This is a preparation for next patch, so that init_active_labels not too
huge.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
 drivers/nvdimm/namespace_devs.c | 41 ++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 16 deletions(-)

Patch
diff mbox series

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 0d64c4b38a56..cdf3049bd2b9 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2449,6 +2449,29 @@  static struct device **create_namespaces(struct nd_region *nd_region)
 	return devs;
 }
 
+static int __init_active_labels(struct nd_mapping *nd_mapping, int count)
+{
+	struct nvdimm_drvdata *ndd = nd_mapping->ndd;
+	struct nd_label_ent *label_ent;
+	int j;
+
+	for (j = 0; j < count; j++) {
+		struct nd_namespace_label *label;
+
+		label_ent = kzalloc(sizeof(*label_ent), GFP_KERNEL);
+		if (!label_ent)
+			break;
+		label = nd_label_active(ndd, j);
+		label_ent->label = label;
+
+		mutex_lock(&nd_mapping->lock);
+		list_add_tail(&label_ent->list, &nd_mapping->labels);
+		mutex_unlock(&nd_mapping->lock);
+	}
+
+	return j;
+}
+
 static int init_active_labels(struct nd_region *nd_region)
 {
 	int i, errno = -ENOMEM;
@@ -2457,8 +2480,7 @@  static int init_active_labels(struct nd_region *nd_region)
 		struct nd_mapping *nd_mapping = &nd_region->mapping[i];
 		struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
 		struct nvdimm *nvdimm = nd_mapping->nvdimm;
-		struct nd_label_ent *label_ent;
-		int count, j;
+		int count;
 
 		/*
 		 * If the dimm is disabled then we may need to prevent
@@ -2485,21 +2507,8 @@  static int init_active_labels(struct nd_region *nd_region)
 
 		count = nd_label_active_count(ndd);
 		dev_dbg(ndd->dev, "count: %d\n", count);
-		for (j = 0; j < count; j++) {
-			struct nd_namespace_label *label;
-
-			label_ent = kzalloc(sizeof(*label_ent), GFP_KERNEL);
-			if (!label_ent)
-				break;
-			label = nd_label_active(ndd, j);
-			label_ent->label = label;
-
-			mutex_lock(&nd_mapping->lock);
-			list_add_tail(&label_ent->list, &nd_mapping->labels);
-			mutex_unlock(&nd_mapping->lock);
-		}
 
-		if (j < count)
+		if (__init_active_labels(nd_mapping, count) < count)
 			goto error;
 	}