From patchwork Mon Oct 21 17:10:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weston Andros Adamson X-Patchwork-Id: 3079011 Return-Path: X-Original-To: patchwork-linux-nfs@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 62E239F396 for ; Mon, 21 Oct 2013 17:10:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C56992041B for ; Mon, 21 Oct 2013 17:10:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A10E203ED for ; Mon, 21 Oct 2013 17:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751444Ab3JURK0 (ORCPT ); Mon, 21 Oct 2013 13:10:26 -0400 Received: from mx12.netapp.com ([216.240.18.77]:58418 "EHLO mx12.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751516Ab3JURKX (ORCPT ); Mon, 21 Oct 2013 13:10:23 -0400 X-IronPort-AV: E=Sophos;i="4.93,540,1378882800"; d="scan'208";a="103330191" Received: from vmwexceht04-prd.hq.netapp.com ([10.106.77.34]) by mx12-out.netapp.com with ESMTP; 21 Oct 2013 10:10:23 -0700 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCEHT04-PRD.hq.netapp.com (10.106.77.34) with Microsoft SMTP Server id 14.3.123.3; Mon, 21 Oct 2013 10:10:22 -0700 Received: from vpn2ntap-70169.vpn.netapp.com (vpn2ntap-70169.vpn.netapp.com [10.55.70.159]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id r9LHAI09029712; Mon, 21 Oct 2013 10:10:22 -0700 (PDT) From: Weston Andros Adamson To: CC: , Weston Andros Adamson Subject: [PATCH 5/5] NFSv4: clean up nfs4_state reference counting Date: Mon, 21 Oct 2013 13:10:14 -0400 Message-ID: <1382375414-5854-6-git-send-email-dros@netapp.com> X-Mailer: git-send-email 1.7.12.4 (Apple Git-37) In-Reply-To: <1382375414-5854-1-git-send-email-dros@netapp.com> References: <1382375414-5854-1-git-send-email-dros@netapp.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Use atomic_inc_not_zero() to avoid referencing a state that is currently being freed. Signed-off-by: Weston Andros Adamson --- fs/nfs/nfs4proc.c | 8 ++++++-- fs/nfs/nfs4state.c | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index a3b78df..005543d 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1275,7 +1275,8 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) out: return ERR_PTR(ret); out_return_state: - atomic_inc(&state->count); + if (!atomic_inc_not_zero(&state->count)) + return ERR_PTR(-EINVAL); return state; } @@ -1429,7 +1430,10 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context if (opendata == NULL) return ERR_PTR(-ENOMEM); opendata->state = state; - atomic_inc(&state->count); + if (!atomic_inc_not_zero(&state->count)) { + nfs4_opendata_put(opendata); + return ERR_PTR(-EINVAL); + } return opendata; } diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index cc14cbb..1c71907 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1416,7 +1416,8 @@ restart: continue; if (state->state == 0) continue; - atomic_inc(&state->count); + if (!atomic_inc_not_zero(&state->count)) + continue; spin_unlock(&sp->so_lock); status = ops->recover_open(sp, state); if (status >= 0) {