All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@sandisk.com>
To: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>,
	Roland Dreier <roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Hal Rosenstock
	<hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 12/16] ib_srpt: fix error return code
Date: Sun, 05 Apr 2015 16:27:14 +0000	[thread overview]
Message-ID: <55216262.7000601@sandisk.com> (raw)
In-Reply-To: <1428235596-4757-13-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>

On 04/05/15 14:06, Julia Lawall wrote:
> Return a negative error code on failure.
>
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> identifier ret; expression e1,e2;
> @@
> (
> if (\(ret < 0\|ret != 0\))
>   { ... return ret; }
> |
> ret = 0
> )
> ... when != ret = e1
>      when != &ret
> *if(...)
> {
>    ... when != ret = e2
>        when forall
>   return ret;
> }
> // </smpl>
>
> In the first case, the printk is changed to use the ret value, rather
> than duplicating PTR_ERR(ch->thread).  This requires changing the format
> from %ld to %d, to account for the type of ret.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
>   drivers/infiniband/ulp/srpt/ib_srpt.c |    6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> index 6e0a477..5ec98f5 100644
> --- a/drivers/infiniband/ulp/srpt/ib_srpt.c
> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> @@ -2143,8 +2143,8 @@ retry:
>
>   	ch->thread = kthread_run(srpt_compl_thread, ch, "ib_srpt_compl");
>   	if (IS_ERR(ch->thread)) {
> -		printk(KERN_ERR "failed to create kernel thread %ld\n",
> -		       PTR_ERR(ch->thread));
> +		ret = PTR_ERR(ch->thread);
> +		printk(KERN_ERR "failed to create kernel thread %d\n", ret);
>   		ch->thread = NULL;
>   		goto err_destroy_qp;
>   	}
> @@ -2590,6 +2590,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
>   		       " configured yet for initiator %s.\n", ch->sess_name);
>   		rej->reason = __constant_cpu_to_be32(
>   				SRP_LOGIN_REJ_CHANNEL_LIMIT_REACHED);
> +		ret = -EINVAL;
>   		goto destroy_ib;
>   	}
>
> @@ -2598,6 +2599,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
>   		rej->reason = __constant_cpu_to_be32(
>   				SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES);
>   		pr_debug("Failed to create session\n");
> +		ret = PTR_ERR(ch->sess);
>   		goto deregister_session;
>   	}
>   	ch->sess->se_node_acl = &nacl->nacl;

This is not the proper way to fix srpt_cm_req_recv(). The kthread_run() 
call must be moved from srpt_create_ch_ib() to after the session 
registration code in srpt_cm_req_recv(), and the session registration 
call + the kthread_run() call must be protected via a mutex against 
concurrent HCA hot-plug removal events (see also srpt_remove_one() and 
srpt_remove_sdev()).

Bart.

WARNING: multiple messages have this Message-ID (diff)
From: Bart Van Assche <bart.vanassche-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
To: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>,
	Roland Dreier <roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Hal Rosenstock
	<hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 12/16] ib_srpt: fix error return code
Date: Sun, 5 Apr 2015 18:27:14 +0200	[thread overview]
Message-ID: <55216262.7000601@sandisk.com> (raw)
In-Reply-To: <1428235596-4757-13-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>

On 04/05/15 14:06, Julia Lawall wrote:
> Return a negative error code on failure.
>
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> identifier ret; expression e1,e2;
> @@
> (
> if (\(ret < 0\|ret != 0\))
>   { ... return ret; }
> |
> ret = 0
> )
> ... when != ret = e1
>      when != &ret
> *if(...)
> {
>    ... when != ret = e2
>        when forall
>   return ret;
> }
> // </smpl>
>
> In the first case, the printk is changed to use the ret value, rather
> than duplicating PTR_ERR(ch->thread).  This requires changing the format
> from %ld to %d, to account for the type of ret.
>
> Signed-off-by: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
>
> ---
>   drivers/infiniband/ulp/srpt/ib_srpt.c |    6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> index 6e0a477..5ec98f5 100644
> --- a/drivers/infiniband/ulp/srpt/ib_srpt.c
> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> @@ -2143,8 +2143,8 @@ retry:
>
>   	ch->thread = kthread_run(srpt_compl_thread, ch, "ib_srpt_compl");
>   	if (IS_ERR(ch->thread)) {
> -		printk(KERN_ERR "failed to create kernel thread %ld\n",
> -		       PTR_ERR(ch->thread));
> +		ret = PTR_ERR(ch->thread);
> +		printk(KERN_ERR "failed to create kernel thread %d\n", ret);
>   		ch->thread = NULL;
>   		goto err_destroy_qp;
>   	}
> @@ -2590,6 +2590,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
>   		       " configured yet for initiator %s.\n", ch->sess_name);
>   		rej->reason = __constant_cpu_to_be32(
>   				SRP_LOGIN_REJ_CHANNEL_LIMIT_REACHED);
> +		ret = -EINVAL;
>   		goto destroy_ib;
>   	}
>
> @@ -2598,6 +2599,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
>   		rej->reason = __constant_cpu_to_be32(
>   				SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES);
>   		pr_debug("Failed to create session\n");
> +		ret = PTR_ERR(ch->sess);
>   		goto deregister_session;
>   	}
>   	ch->sess->se_node_acl = &nacl->nacl;

This is not the proper way to fix srpt_cm_req_recv(). The kthread_run() 
call must be moved from srpt_create_ch_ib() to after the session 
registration code in srpt_cm_req_recv(), and the session registration 
call + the kthread_run() call must be protected via a mutex against 
concurrent HCA hot-plug removal events (see also srpt_remove_one() and 
srpt_remove_sdev()).

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Bart Van Assche <bart.vanassche@sandisk.com>
To: Julia Lawall <Julia.Lawall@lip6.fr>, Roland Dreier <roland@kernel.org>
Cc: <kernel-janitors@vger.kernel.org>,
	Sean Hefty <sean.hefty@intel.com>,
	"Hal Rosenstock" <hal.rosenstock@gmail.com>,
	<linux-rdma@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 12/16] ib_srpt: fix error return code
Date: Sun, 5 Apr 2015 18:27:14 +0200	[thread overview]
Message-ID: <55216262.7000601@sandisk.com> (raw)
In-Reply-To: <1428235596-4757-13-git-send-email-Julia.Lawall@lip6.fr>

On 04/05/15 14:06, Julia Lawall wrote:
> Return a negative error code on failure.
>
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> identifier ret; expression e1,e2;
> @@
> (
> if (\(ret < 0\|ret != 0\))
>   { ... return ret; }
> |
> ret = 0
> )
> ... when != ret = e1
>      when != &ret
> *if(...)
> {
>    ... when != ret = e2
>        when forall
>   return ret;
> }
> // </smpl>
>
> In the first case, the printk is changed to use the ret value, rather
> than duplicating PTR_ERR(ch->thread).  This requires changing the format
> from %ld to %d, to account for the type of ret.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
>   drivers/infiniband/ulp/srpt/ib_srpt.c |    6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> index 6e0a477..5ec98f5 100644
> --- a/drivers/infiniband/ulp/srpt/ib_srpt.c
> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> @@ -2143,8 +2143,8 @@ retry:
>
>   	ch->thread = kthread_run(srpt_compl_thread, ch, "ib_srpt_compl");
>   	if (IS_ERR(ch->thread)) {
> -		printk(KERN_ERR "failed to create kernel thread %ld\n",
> -		       PTR_ERR(ch->thread));
> +		ret = PTR_ERR(ch->thread);
> +		printk(KERN_ERR "failed to create kernel thread %d\n", ret);
>   		ch->thread = NULL;
>   		goto err_destroy_qp;
>   	}
> @@ -2590,6 +2590,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
>   		       " configured yet for initiator %s.\n", ch->sess_name);
>   		rej->reason = __constant_cpu_to_be32(
>   				SRP_LOGIN_REJ_CHANNEL_LIMIT_REACHED);
> +		ret = -EINVAL;
>   		goto destroy_ib;
>   	}
>
> @@ -2598,6 +2599,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
>   		rej->reason = __constant_cpu_to_be32(
>   				SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES);
>   		pr_debug("Failed to create session\n");
> +		ret = PTR_ERR(ch->sess);
>   		goto deregister_session;
>   	}
>   	ch->sess->se_node_acl = &nacl->nacl;

This is not the proper way to fix srpt_cm_req_recv(). The kthread_run() 
call must be moved from srpt_create_ch_ib() to after the session 
registration code in srpt_cm_req_recv(), and the session registration 
call + the kthread_run() call must be protected via a mutex against 
concurrent HCA hot-plug removal events (see also srpt_remove_one() and 
srpt_remove_sdev()).

Bart.

  parent reply	other threads:[~2015-04-05 16:27 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-05 12:06 [PATCH 0/16] fix error return code Julia Lawall
2015-04-05 12:06 ` Julia Lawall
2015-04-05 12:06 ` Julia Lawall
2015-04-05 12:06 ` Julia Lawall
2015-04-05 12:06 ` Julia Lawall
2015-04-05 12:06 ` [PATCH 1/16] wan: lmc: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-07 19:26   ` David Miller
2015-04-07 19:26     ` David Miller
2015-04-05 12:06 ` [PATCH 2/16] [media] si4713: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:06 ` [PATCH 4/16] [media] as102: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:06 ` [PATCH 3/16] [media] radio: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:06 ` [PATCH 5/16] ufs: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:06 ` [PATCH 6/16] HSI: cmt_speech: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:47   ` Sebastian Reichel
2015-04-05 12:47     ` Sebastian Reichel
2015-04-05 12:06 ` [PATCH 7/16] parport_sunbpp: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:06 ` [PATCH 8/16] cosa: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-07 19:26   ` David Miller
2015-04-07 19:26     ` David Miller
2015-04-05 12:06 ` [PATCH 9/16] HID: logitech-hidpp: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 14:38   ` Benjamin Tissoires
2015-04-05 14:38     ` Benjamin Tissoires
2015-04-05 20:57   ` Jiri Kosina
2015-04-05 20:57     ` Jiri Kosina
2015-04-05 12:06 ` [PATCH 10/16] zram: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:06 ` [PATCH 11/16] drm/msm/dp: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:06 ` [PATCH 12/16] ib_srpt: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
     [not found]   ` <1428235596-4757-13-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2015-04-05 16:27     ` Bart Van Assche [this message]
2015-04-05 16:27       ` Bart Van Assche
2015-04-05 16:27       ` Bart Van Assche
2015-04-05 12:06 ` [PATCH 13/16] ALSA: au1x00: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 16:06   ` [alsa-devel] " Takashi Iwai
2015-04-05 16:06     ` Takashi Iwai
2015-04-05 12:06 ` [PATCH 14/16] soc: ti: knav_qmss_queue: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-06  2:03   ` santosh.shilimkar
2015-04-06  2:03     ` santosh.shilimkar
2015-04-06  2:03     ` santosh.shilimkar at oracle.com
2015-04-05 12:06 ` [PATCH 15/16] staging: lustre: lnet: lnet: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-06  6:41   ` [HPDD-discuss] " Zhen, Liang
2015-04-06  6:41     ` Zhen, Liang
2015-04-05 12:06 ` [PATCH 16/16] NFC: pn533: " Julia Lawall
2015-04-05 12:06   ` Julia Lawall
2015-04-05 23:23   ` Samuel Ortiz
2015-04-05 23:23     ` Samuel Ortiz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55216262.7000601@sandisk.com \
    --to=bart.vanassche@sandisk.com \
    --cc=Julia.Lawall-L2FTfq7BK8M@public.gmane.org \
    --cc=hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.