Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1336619 > unrolled thread

[PATCH] nes: handling failed allocation when creating workqueue

Started byInsu Yun <wuninsu@gmail.com>
First post2016-02-17 19:10 +0100
Last post2016-02-18 18:50 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] nes: handling failed allocation when creating workqueue Insu Yun <wuninsu@gmail.com> - 2016-02-17 19:10 +0100
    Re: [PATCH] nes: handling failed allocation when creating workqueue Leon Romanovsky <leon@leon.nu> - 2016-02-18 06:10 +0100
      Re: [PATCH] nes: handling failed allocation when creating workqueue Doug Ledford <dledford@redhat.com> - 2016-02-18 18:50 +0100

#1336619 — [PATCH] nes: handling failed allocation when creating workqueue

FromInsu Yun <wuninsu@gmail.com>
Date2016-02-17 19:10 +0100
Subject[PATCH] nes: handling failed allocation when creating workqueue
Message-ID<r3eI2-1Fz-11@gated-at.bofh.it>
Since create_singlethread_workqueue uses kzalloc internally, 
it can be failed in memory pressure, so need to handle it.

Signed-off-by: Insu Yun <wuninsu@gmail.com>
---
 drivers/infiniband/hw/nes/nes_cm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
index cb9f0f2..23afad6 100644
--- a/drivers/infiniband/hw/nes/nes_cm.c
+++ b/drivers/infiniband/hw/nes/nes_cm.c
@@ -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;
 }
 
 
-- 
1.9.1

[toc] | [next] | [standalone]


#1337028

FromLeon Romanovsky <leon@leon.nu>
Date2016-02-18 06:10 +0100
Message-ID<r3p0J-Bk-3@gated-at.bofh.it>
In reply to#1336619
Please see my minor comments below.
Reviewed-by: Leon Romanovsky <leon@leon.nu>

On Wed, Feb 17, 2016 at 01:06:33PM -0500, Insu Yun wrote:
> 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/

> 
> Signed-off-by: Insu Yun <wuninsu@gmail.com>
> ---
>  drivers/infiniband/hw/nes/nes_cm.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
> index cb9f0f2..23afad6 100644
> --- a/drivers/infiniband/hw/nes/nes_cm.c
> +++ b/drivers/infiniband/hw/nes/nes_cm.c
> @@ -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.

>  
>  	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;
>  }
>  
>  
> -- 
> 1.9.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[toc] | [prev] | [next] | [standalone]


#1337587

FromDoug Ledford <dledford@redhat.com>
Date2016-02-18 18:50 +0100
Message-ID<r3ASf-CA-29@gated-at.bofh.it>
In reply to#1337028

[Multipart message — attachments visible in raw view] — view raw

On 2/17/2016 11:59 PM, Leon Romanovsky wrote:
> Please see my minor comments below.
> Reviewed-by: Leon Romanovsky <leon@leon.nu>
> 
> On Wed, Feb 17, 2016 at 01:06:33PM -0500, Insu Yun wrote:
>> 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/
> 
>>
>> Signed-off-by: Insu Yun <wuninsu@gmail.com>
>> ---
>>  drivers/infiniband/hw/nes/nes_cm.c | 13 ++++++++++++-
>>  1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
>> index cb9f0f2..23afad6 100644
>> --- a/drivers/infiniband/hw/nes/nes_cm.c
>> +++ b/drivers/infiniband/hw/nes/nes_cm.c
>> @@ -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.


[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web