Skip to contentSkip to conversation

nes: handling failed allocation when creating workqueue

PATCH In review Insu Yun 3 participants 3 messages Feb 17, 2016 – Feb 18, 2016 InfiniBand

lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 nes: handling failed allocation when creating workqueue

Since create_singlethread_workqueue uses kzalloc internally, it can be failed in memory pressure, so need to handle it.

---
 drivers/infiniband/hw/nes/nes_cm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/infiniband/hw/nes/nes_cm.c +12 -1
index cb9f0f2..23afad6 100644
@@ -2833,7 +2833,7 @@ static struct nes_cm_core *nes_cm_alloc_core(void)
 	/* alloc top level core control structure */
 	cm_core = kzalloc(sizeof(*cm_core), GFP_KERNEL);
 	if (!cm_core)
-		return NULL;
+		goto enomem_3;
 
 	INIT_LIST_HEAD(&cm_core->connected_nodes);
 	init_timer(&cm_core->tcp_timer);
@@ -2856,12 +2856,23 @@ static struct nes_cm_core *nes_cm_alloc_core(void)
 
 	nes_debug(NES_DBG_CM, "Enable QUEUE EVENTS\n");
 	cm_core->event_wq = create_singlethread_workqueue("nesewq");
+	if (!cm_core->event_wq)
+		goto enomem_2;
 	cm_core->post_event = nes_cm_post_event;
 	nes_debug(NES_DBG_CM, "Enable QUEUE DISCONNECTS\n");
 	cm_core->disconn_wq = create_singlethread_workqueue("nesdwq");
+	if (!cm_core->disconn_wq)
+		goto enomem_1;
 
 	print_core(cm_core);
 	return cm_core;
+
+enomem_1:
+	destroy_workqueue(cm_core->event_wq);
+enomem_2:
+	kfree(cm_core);
+enomem_3:
+	return NULL;
 }
 
 
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw

Please see my minor comments below.

Quoted 2 lines · Insu Yun

Since create_singlethread_workqueue uses kzalloc internally, it can be failed in memory pressure, so need to handle it.

s/can be failed/can fail/

Quoted 11 lines
---
 drivers/infiniband/hw/nes/nes_cm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/infiniband/hw/nes/nes_cm.c +0 -0
index cb9f0f2..23afad6 100644

drivers/infiniband/hw/nes/nes_cm.c static struct nes_cm_core *nes_cm_alloc_core(void) · line 2836

Quoted 5 lines
drivers/infiniband/hw/nes/nes_cm.c +1 -1
@@ -2833,7 +2833,7 @@ static struct nes_cm_core *nes_cm_alloc_core(void)
 	/* alloc top level core control structure */
 	cm_core = kzalloc(sizeof(*cm_core), GFP_KERNEL);
 	if (!cm_core)
-		return NULL;
+		goto enomem_3;

IMHO, there is no need to define goto label for one return.

Quoted 34 lines
drivers/infiniband/hw/nes/nes_cm.c +11 -0
 	INIT_LIST_HEAD(&cm_core->connected_nodes);
 	init_timer(&cm_core->tcp_timer);
@@ -2856,12 +2856,23 @@ static struct nes_cm_core *nes_cm_alloc_core(void)
 
 	nes_debug(NES_DBG_CM, "Enable QUEUE EVENTS\n");
 	cm_core->event_wq = create_singlethread_workqueue("nesewq");
+	if (!cm_core->event_wq)
+		goto enomem_2;
 	cm_core->post_event = nes_cm_post_event;
 	nes_debug(NES_DBG_CM, "Enable QUEUE DISCONNECTS\n");
 	cm_core->disconn_wq = create_singlethread_workqueue("nesdwq");
+	if (!cm_core->disconn_wq)
+		goto enomem_1;
 
 	print_core(cm_core);
 	return cm_core;
+
+enomem_1:
+	destroy_workqueue(cm_core->event_wq);
+enomem_2:
+	kfree(cm_core);
+enomem_3:
+	return NULL;
 }
 
 
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 15 lines · Leon Romanovsky

Please see my minor comments below.

Quoted 2 lines · Insu Yun

Since create_singlethread_workqueue uses kzalloc internally, it can be failed in memory pressure, so need to handle it.

s/can be failed/can fail/

Quoted 6 lines
---
 drivers/infiniband/hw/nes/nes_cm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
Quoted 12 lines

drivers/infiniband/hw/nes/nes_cm.c static struct nes_cm_core *nes_cm_alloc_core(void) · line 2836

Quoted 10 lines
drivers/infiniband/hw/nes/nes_cm.c +1 -1
index cb9f0f2..23afad6 100644
@@ -2833,7 +2833,7 @@ static struct nes_cm_core *nes_cm_alloc_core(void)
 	/* alloc top level core control structure */
 	cm_core = kzalloc(sizeof(*cm_core), GFP_KERNEL);
 	if (!cm_core)
-		return NULL;
+		goto enomem_3;

IMHO, there is no need to define goto label for one return.

I made the touchups Leon suggested, and a touchup of my own, but it is now applied, thanks.