Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2523265rwl; Fri, 6 Jan 2023 07:34:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXucyibRoHeehPt+J/kEjV2XrJHx+TgQ/f5U6lCU/oanNk7WNjKPYmU39tELxnnAh0Gx75YQ X-Received: by 2002:a05:6a20:8347:b0:b0:4f70:b2b2 with SMTP id z7-20020a056a20834700b000b04f70b2b2mr51592105pzc.46.1673019265973; Fri, 06 Jan 2023 07:34:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673019265; cv=none; d=google.com; s=arc-20160816; b=s57hpOZa4q5Gmvqi20+2TQbZuIGXtkSz0enJrE9C3h3O6XGAmdbqccEvi/YVEqduk0 yz8raNNYKJLcHekH6xhjJVb28kg8f46pCqphWLKA3cI+5YTHa4I3mVPma+I+HoO7P3kK y4SxKCBOYWcDvmamd6ZyLmCFP4q2pcHDnhNnp1yuwFW4RTKIcH+xzTCEeQ+f/SdQAawR nEaxSTdgT92cN7iNviyQfbIMPlF3fMybqp7KUS+1KIHxkW5/tHXVkATl4d8Il14Ulnl0 Z6vNN04KbODjHCu1kyOjvlq2Zjl8rMGt2nfDUMn4Sr+bJvO6u09oO1y3mgnQdCSUPt7M aXgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yosocUq+8TcWrHxM3J0qPq8gg+8D6HRE9sjXPhmZgto=; b=Jocr7d2fK1wCKeb796YvHSDUGs+mLbX2+tVnV3PPHRm7MNRqqBK7xlrCDFjpopCi/4 uVdOJumRUkwG/fi6sBJO4k4TqmZ7MoLXIZBs8TOsOeLRxCOGCbxuAPrdNlijBOnvuW6i bmkhivMKDqi28E3NQivPPFNxx30eM4VVusmuijI/sr+pa3mAVL1q1Oswv60s57DXcfFO Foak7/2iE+bDirbUwqU266WjDIa8c729mMQ3YV3edGIXo1LhnylrRgw6OPAbXWc67zds gn2rgIcML85UlSrmEjqN0rQ8jw0oC/0niC35CwyX2QLmsK6UQJIZgTEVkvsSl4I74P2Z Xztg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OAj9rqrE; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l71-20020a63884a000000b004783935de72si1979580pgd.45.2023.01.06.07.33.59; Fri, 06 Jan 2023 07:34:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OAj9rqrE; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235315AbjAFPd6 (ORCPT + 99 others); Fri, 6 Jan 2023 10:33:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235491AbjAFPd4 (ORCPT ); Fri, 6 Jan 2023 10:33:56 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C70435936 for ; Fri, 6 Jan 2023 07:33:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A663CB81D9F for ; Fri, 6 Jan 2023 15:33:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3EABC433EF; Fri, 6 Jan 2023 15:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673019230; bh=dEt2Nspqb40esxLCGIj5lmXJCX8tUhEZPxrDBvS4PYc=; h=From:To:Cc:Subject:Date:From; b=OAj9rqrEV674IpPPM/ePrnW8bP4KK7Dix6sW8aLE4Rz5Kj0GiyQLW7tQYg0cerCaw Ugz4L6ZJ5dgdHzkxgJNx8ZOFtu9+CYNxvu84yoSEH76+QR7QTylNsdaOUWB6ZuE0nq yQeVgUmwxioBdHuvS7v4qysf2H5RhySXL38bPuQKtKndjzS6JvtxKqOOR/+kyR175i yXwtzZ19QTTD5ALcOusfpe0oCSXZY0AW/kHbvaNZWwzxpuHAslwPYz6JzIrgKhjVzj 90xkaTW7+jhuq7k3lf7wo97qm9e3GDA5YI643DcgkePGETFit6p6to+yQ1KzSQhNCY AIzRFkaSPwVPA== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org, NeilBrown Subject: [PATCH v2 1/2] nfsd: allow nfsd_file_get to sanely handle a NULL pointer Date: Fri, 6 Jan 2023 10:33:47 -0500 Message-Id: <20230106153348.104214-1-jlayton@kernel.org> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org ...and remove some now-useless NULL pointer checks in its callers. Suggested-by: NeilBrown Signed-off-by: Jeff Layton --- fs/nfsd/filecache.c | 5 ++--- fs/nfsd/nfs4state.c | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 0ef070349014..58ac93e7e680 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -452,7 +452,7 @@ static bool nfsd_file_lru_remove(struct nfsd_file *nf) struct nfsd_file * nfsd_file_get(struct nfsd_file *nf) { - if (likely(refcount_inc_not_zero(&nf->nf_ref))) + if (nf && refcount_inc_not_zero(&nf->nf_ref)) return nf; return NULL; } @@ -1096,8 +1096,7 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, rcu_read_lock(); nf = rhashtable_lookup(&nfsd_file_rhash_tbl, &key, nfsd_file_rhash_params); - if (nf) - nf = nfsd_file_get(nf); + nf = nfsd_file_get(nf); rcu_read_unlock(); if (nf) { diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 4809ae0f0138..655fcfec0ace 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -602,9 +602,7 @@ put_nfs4_file(struct nfs4_file *fi) static struct nfsd_file * __nfs4_get_fd(struct nfs4_file *f, int oflag) { - if (f->fi_fds[oflag]) - return nfsd_file_get(f->fi_fds[oflag]); - return NULL; + return nfsd_file_get(f->fi_fds[oflag]); } static struct nfsd_file * -- 2.39.0