Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5624111rwb; Wed, 7 Sep 2022 05:51:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR54vsLHTiQmij+1CDl9XwLO+vk8JUm8OozDM2t8ljdNlJkXJ0itXQ2ep/CYWUCCpb/RkfYd X-Received: by 2002:a17:907:c23:b0:770:8564:8637 with SMTP id ga35-20020a1709070c2300b0077085648637mr1403719ejc.295.1662555067852; Wed, 07 Sep 2022 05:51:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662555067; cv=none; d=google.com; s=arc-20160816; b=lj5ld4rPrdAndiOcht3fCxlWXj3hO3yrqK/kCgsfQsGGPPJHFd1TKbwWOhU8Bx0KjF 73nSrjDbSmxeRTYUPh72aMtpEogsnjpgRdiWlYYaYc8G9I6CWlb2qSJPPsfILmxkf/bp t45cD8OLzvCwE1ULBIyteveRsblFg9JQrlI2L4jkB2tmCtHimDaT+bTMnBoFCmhFdSQN B2bDetWh8UXk1ABMtcQ9gK+lgVSkomyBnEHFh1Bh+TrSWBWksu6VHaWn8ey0i59o1up+ 0YzO4LSOQArUgs2iiBjpx9iH7eM8rsKJTt+sUWeR2w89iOclPntGpLsRfub8Rje4RWIl FmEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=a/5a5hL/Q2+oXyEAdftIQXflIGPRq0ohtlq19P1Fp78=; b=Cb9XMmNgiZrJgUrE4tCu7gEnsx6Y7x5jDn1latOSoChaQG49yQP76SVHDQKq65E3kw 8+5921GYinDk0wrQV6Z4EhGfBDEA4pny7cOciBN3VMj7zbmImOq3Fi/aAD7+5HiIqkvw QrnBuBHmJA4izsBgmBEGXffO5bkQ7J5xGZc6lGDpNxGGP2rIa3CFUsb82HAMnCh0pLRK An6tuFv6uPk1Y97VW5MMyq3ag0T4eW3DtLReFELtPaNZFWtV6dEtKtyaN50SN+iux22o weckJtX2EUquf+LXeUNUmLch20pWF9y248GaqQj9YLorRjA/ch7hQDPyIJcXQiD+m8Bo Vs2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MlKwNDn3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 h6-20020a05640250c600b0044f2e3fa418si44200edb.348.2022.09.07.05.50.42; Wed, 07 Sep 2022 05:51:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=MlKwNDn3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S229727AbiIGMhV (ORCPT + 99 others); Wed, 7 Sep 2022 08:37:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbiIGMhT (ORCPT ); Wed, 7 Sep 2022 08:37:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1EC8AF4A5; Wed, 7 Sep 2022 05:37:18 -0700 (PDT) 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 641BEB81C29; Wed, 7 Sep 2022 12:37:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A510EC433D6; Wed, 7 Sep 2022 12:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662554236; bh=WIHwNbc9S0mBJ0PzSmdjD+CvPdr06HeB66MNOQMDFlc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MlKwNDn3XuQDr8wwMcEZ0F3zU2+TlkRs5xCS5yei0ErirUkCnO61JIJWETVDV1uKR t8wXNmA+M5iD6RbhqEG4UoWQ8a1Qu9trgl1oByGnjvjnX41uGpgHIEAqyJYHBzyZli sj6ycG+/BWbWe91JIUy4xQ1n04teXc9XY05NqQ9qazXsCE+0FVPYz5UL8QxTEqBWFY 4B9kh7CnjWNaEq0Gr2JNW973Jn5OAiPmVDhE5G03TuAgxrjLk6txoYDJXJ/uTxBbCk JdWbA1GrOa1jbPTz5l7yNYng3NCytp4jDibUZgZc28Vy278ZNevATVoce8/lMXVkWQ 3BmKyRGLqmrpg== Date: Wed, 7 Sep 2022 15:37:11 +0300 From: Leon Romanovsky To: Li zeming Cc: jgg@ziepe.ca, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rdma/rdmavt_qp: Remove unnecessary 'NULL' values from qp Message-ID: References: <20220907033604.4637-1-zeming@nfschina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220907033604.4637-1-zeming@nfschina.com> 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,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org On Wed, Sep 07, 2022 at 11:36:04AM +0800, Li zeming wrote: > The pointer qp is assigned before it is used, it does not need to be > initialized and assigned. > > Signed-off-by: Li zeming > --- > include/rdma/rdmavt_qp.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/rdma/rdmavt_qp.h b/include/rdma/rdmavt_qp.h > index 2e58d5e6ac0e..2afc3300d618 100644 > --- a/include/rdma/rdmavt_qp.h > +++ b/include/rdma/rdmavt_qp.h > @@ -699,7 +699,7 @@ static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi, > struct rvt_ibport *rvp, > u32 qpn) __must_hold(RCU) > { > - struct rvt_qp *qp = NULL; > + struct rvt_qp *qp; > > if (unlikely(qpn <= 1)) { > qp = rcu_dereference(rvp->qp[qpn]); This function is completely wrong, most likely it never returns NULL otherwise, we would crash in "if (qp->ibqp.qp_num == qpn)" line. The proper change will be something like this: diff --git a/include/rdma/rdmavt_qp.h b/include/rdma/rdmavt_qp.h index 2e58d5e6ac0e..883c328e06b6 100644 --- a/include/rdma/rdmavt_qp.h +++ b/include/rdma/rdmavt_qp.h @@ -699,19 +699,19 @@ static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi, struct rvt_ibport *rvp, u32 qpn) __must_hold(RCU) { - struct rvt_qp *qp = NULL; + struct rvt_qp *qp; + u32 n; - if (unlikely(qpn <= 1)) { - qp = rcu_dereference(rvp->qp[qpn]); - } else { - u32 n = hash_32(qpn, rdi->qp_dev->qp_table_bits); + if (unlikely(qpn <= 1)) + return rcu_dereference(rvp->qp[qpn]); - for (qp = rcu_dereference(rdi->qp_dev->qp_table[n]); qp; - qp = rcu_dereference(qp->next)) - if (qp->ibqp.qp_num == qpn) - break; - } - return qp; + n = hash_32(qpn, rdi->qp_dev->qp_table_bits); + + for (qp = rcu_dereference(rdi->qp_dev->qp_table[n]); qp; + qp = rcu_dereference(qp->next)) + if (qp->ibqp.qp_num == qpn) + return qp; + return NULL; } /** > -- > 2.18.2 >