diff mbox

[1/2] rsocket: Fix removing rsocket from service thread

Message ID 1404425324-20201-1-git-send-email-sean.hefty@intel.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Hefty, Sean July 3, 2014, 10:08 p.m. UTC
From: Sean Hefty <sean.hefty@intel.com>

When removing an rsocket from a service thread, we replace
the removed service with the one at the end of the service list.
This keeps the array tightly packed.  However, rs_svc_rm_rs
decrements the rsocket count before doing the swap.  The result
is that the entry at the end of the list gets dropped off.
Defer decrementing the count until the swap has been made.

In this case, the cnt value is a valid index into the array,
because we start at index 1.  Index 0 is used internally by
the service thread.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
---
 src/rsocket.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Hal Rosenstock July 7, 2014, 10:08 a.m. UTC | #1
On 7/3/2014 6:08 PM, sean.hefty@intel.com wrote:
> From: Sean Hefty <sean.hefty@intel.com>
> 
> When removing an rsocket from a service thread, we replace
> the removed service with the one at the end of the service list.
> This keeps the array tightly packed.  However, rs_svc_rm_rs
> decrements the rsocket count before doing the swap.  The result
> is that the entry at the end of the list gets dropped off.
> Defer decrementing the count until the swap has been made.
> 
> In this case, the cnt value is a valid index into the array,
> because we start at index 1.  Index 0 is used internally by
> the service thread.
> 
> Signed-off-by: Sean Hefty <sean.hefty@intel.com>

Tested-by: Hal Rosenstock <hal@mellanox.com>
--
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
diff mbox

Patch

diff --git a/src/rsocket.c b/src/rsocket.c
index f81fb1b..e9d12c7 100644
--- a/src/rsocket.c
+++ b/src/rsocket.c
@@ -3947,11 +3947,11 @@  static int rs_svc_rm_rs(struct rs_svc *svc, struct rsocket *rs)
 
 	for (i = 1; i <= svc->cnt; i++) {
 		if (svc->rss[i] == rs) {
-			svc->cnt--;
 			svc->rss[i] = svc->rss[svc->cnt];
 			memcpy(svc->contexts + i * svc->context_size,
 			       svc->contexts + svc->cnt * svc->context_size,
 			       svc->context_size);
+			svc->cnt--;
 			return 0;
 		}
 	}