From patchwork Mon Nov 28 10:58:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhang.songyi@zte.com.cn X-Patchwork-Id: 26629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5579114wrr; Mon, 28 Nov 2022 03:04:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf7beY8OJEoTm0tzL89ijXq7QsFLuVji2NGG86Qb4oWyRSFzKYw1G2IJUD8CV0K/lDQBGDHV X-Received: by 2002:a17:902:ee82:b0:189:6ed3:95ea with SMTP id a2-20020a170902ee8200b001896ed395eamr13372361pld.164.1669633463682; Mon, 28 Nov 2022 03:04:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669633463; cv=none; d=google.com; s=arc-20160816; b=GoDZK1pwSiUb1Z5YZbyjjvlG7C5xv9kPf0Wnt4WAoMHSbhbuGItqJznR6dZWTwsl26 yY7yC1fOyR17HY5C1v8PLSOD1HP8nPeRG6ZYVwPBSOhEsY2IwprbiZcCuqdVdXcl3N+Y TtX7+VjOUB80eXtQc57BmvgsvAMNVOal54BXXXumxc40H3z6mSUwHB6PzW6rWnngTj99 tz4PnJJe4ftgR41P3c/wPMbIUO7oeyE33WDS4E2zEY0uR9bsWpJ6PdAOnD1YPDx7jjPU LepMQ7lLKHtEu5sxIclnQAag5Wj8TGnXg0AHuvcu/OCEzVTAfEuKqIn8i4q/bJv4Gzmi xxUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=7g+CvPXiuXiW6+OP++MD2m1ILt36c6yIwsDV36+U9Fw=; b=Sa4dLPFnd8RyWisALvaKJsPE0SHx2JaCMgcTmIFPPgXYsM1iA5E88M/UWjS3gBoaie /RxkQKLmG+bxBLVje57JnuM8SpQKgwtgZ/3r1V7siMFTEcceky6QD8q2PMLJiODHlGhr I+JU45EgyQYru08CrlQtarh9JJGteZilC/NRzWo/WhmWNh6FhSeoNUV1eiT/HlayuSZl DW925wDpwSmFELl7/i1CBXnRRIdRJo7AH9aJ5byzDgufkrpOdkG5AlffVvX6W0CeVwFj w44O9ZIFYQFilgIR2L8NRppTb76r8LZGxLRsf4VY97+8NrMqLbroCrf1yn0PSf6G1OdG gsYg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i35-20020a632223000000b004609faa2dbesi12816563pgi.285.2022.11.28.03.04.04; Mon, 28 Nov 2022 03:04:23 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230365AbiK1K6r (ORCPT + 99 others); Mon, 28 Nov 2022 05:58:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiK1K6p (ORCPT ); Mon, 28 Nov 2022 05:58:45 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 915B5B84F; Mon, 28 Nov 2022 02:58:43 -0800 (PST) Received: from mxct.zte.com.cn (unknown [192.168.251.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NLMsF620Zz8QrkZ; Mon, 28 Nov 2022 18:58:41 +0800 (CST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4NLMsC1fcRz4y0tv; Mon, 28 Nov 2022 18:58:39 +0800 (CST) Received: from xaxapp01.zte.com.cn ([10.88.40.50]) by mse-fl2.zte.com.cn with SMTP id 2ASAwWDJ034165; Mon, 28 Nov 2022 18:58:32 +0800 (+08) (envelope-from zhang.songyi@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid31; Mon, 28 Nov 2022 18:58:35 +0800 (CST) Date: Mon, 28 Nov 2022 18:58:35 +0800 (CST) X-Zmail-TransId: 2afa6384945b07c86c35 X-Mailer: Zmail v1.0 Message-ID: <202211281858353531369@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , , , Subject: =?utf-8?q?=5BPATCH_linux-next=5D_RDMA/mlx4=3A_NULL_check_before_dev?= =?utf-8?q?=5F=7Bput=2C_hold=7D_functions_is_not?= =?utf-8?q?_needed?= X-MAIL: mse-fl2.zte.com.cn 2ASAwWDJ034165 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 63849461.000 by FangMail milter! X-FangMail-Envelope: 1669633121/4NLMsF620Zz8QrkZ/63849461.000/192.168.251.13/[192.168.251.13]/mxct.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63849461.000/4NLMsF620Zz8QrkZ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750737578763195591?= X-GMAIL-MSGID: =?utf-8?q?1750737578763195591?= From: zhang songyi The call netdev_{put, hold} of dev_{put, hold} will check NULL, so there is no need to check before using dev_{put, hold}. Fix the following coccicheck warnings: /drivers/infiniband/hw/mlx4/main.c:1311:2-10: WARNING: WARNING NULL check before dev_{put, hold} functions is not needed. /drivers/infiniband/hw/mlx4/main.c:148:2-10: WARNING: WARNING NULL check before dev_{put, hold} functions is not needed. /drivers/infiniband/hw/mlx4/main.c:1959:3-11: WARNING: WARNING NULL check before dev_{put, hold} functions is not needed. /drivers/infiniband/hw/mlx4/main.c:1962:3-10: WARNING: WARNING NULL check before dev_{put, hold} functions is not needed. Signed-off-by: zhang songyi --- drivers/infiniband/hw/mlx4/main.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) -- 2.15.2 diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index ba47874f90d3..dceebcd885bb 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -144,8 +144,7 @@ static struct net_device *mlx4_ib_get_netdev(struct ib_device *device, } } } - if (dev) - dev_hold(dev); + dev_hold(dev); rcu_read_unlock(); return dev; @@ -1307,8 +1306,7 @@ int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp, spin_lock_bh(&mdev->iboe.lock); ndev = mdev->iboe.netdevs[mqp->port - 1]; - if (ndev) - dev_hold(ndev); + dev_hold(ndev); spin_unlock_bh(&mdev->iboe.lock); if (ndev) { @@ -1955,11 +1953,9 @@ static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) if (ge) { spin_lock_bh(&mdev->iboe.lock); ndev = ge->added ? mdev->iboe.netdevs[ge->port - 1] : NULL; - if (ndev) - dev_hold(ndev); + dev_hold(ndev); spin_unlock_bh(&mdev->iboe.lock); - if (ndev) - dev_put(ndev); + dev_put(ndev); list_del(&ge->list); kfree(ge); } else