From patchwork Thu Jul 3 22:08:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 4477501 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BA2B29F26C for ; Thu, 3 Jul 2014 22:09:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6D08020295 for ; Thu, 3 Jul 2014 22:09:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89B75203B6 for ; Thu, 3 Jul 2014 22:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965154AbaGCWJA (ORCPT ); Thu, 3 Jul 2014 18:09:00 -0400 Received: from mga11.intel.com ([192.55.52.93]:26632 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964867AbaGCWI6 (ORCPT ); Thu, 3 Jul 2014 18:08:58 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 03 Jul 2014 15:08:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,597,1400050800"; d="scan'208";a="564987427" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by fmsmga002.fm.intel.com with ESMTP; 03 Jul 2014 15:08:57 -0700 From: sean.hefty@intel.com To: linux-rdma@vger.kernel.org Cc: Sean Hefty Subject: [PATCH 1/2] rsocket: Fix removing rsocket from service thread Date: Thu, 3 Jul 2014 15:08:43 -0700 Message-Id: <1404425324-20201-1-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Hefty 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 Tested-by: Hal Rosenstock --- src/rsocket.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) 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; } }