Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2038787imm; Mon, 16 Jul 2018 00:39:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdMEr3zvpGDYQ1O0UlNLhSQOQbifL0F6r5PZ9VFUO76XcY/j1FAQW4MMHmSFTvVH/rfaw5+ X-Received: by 2002:a65:498c:: with SMTP id r12-v6mr14880494pgs.112.1531726768103; Mon, 16 Jul 2018 00:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531726768; cv=none; d=google.com; s=arc-20160816; b=Eil40sJ8XmXqA06dfoQXHPTVXvzDLMOIgh7CRpGfuUWzzxPjrudkO2UyKrxLvtzTqD PAy3pijDRaeibnROytoCJp/TKSyD6iRnInWPPtOPXsqoy19VeOxsbB8Xn/0n66B1CYPX 8HPkiV7SkhbWAqmPMlGSeAjmUXzqgRm8FQB5180+NT+gwiMjWL0Skz1lx2pkZssuGvrm j3iOsxZzhKFtWh25GzZOkTr7UjQtXs9G92wTuGlqgNMY8agkfnUno3wTAlNqQuCqZeYD 2+u7TtUBqsd2R/6oqEDFR2ZimTKZYEPlKyeGJxdp+B/+oXvJwu/dHhbPBh3pJfs5GiO5 oXWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=drAZN01cqtiQS94Ceq6eU281uo49CRC7chWMHkVhT7M=; b=PIymhQ+oXzBWs/F8QnCFiHYVux/QNpUvBCVI9lBq8Fkzs6O5ghm3x7hChZ7lRS1K0w HIfq0qcW+8ah1ngkbMlqDUPu84/4P2cUgkmVbfGQjhQ9SjEaiMqYEb3ZTsJPV46Eslfb asYH3r53rXBy2i9CwwxB+pMOFvbQvYCoLkZGCn1HIJwNsd7eWggtzkpVt1QMG1QkQ+xg s3LPxYz9ReZqP0EiW96ra+K1Cgdk7ea0BcfkrLSUPvgiUX4zNTz/unMvqGst/d2A8GDy xddh6qvIG1QNwFACInn+AyrFZsJ1XMDsVUUaMjWOUwzFNwdEf3V71pJ1aySxna2dIKqC G0pQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w22-v6si28914727plp.294.2018.07.16.00.39.13; Mon, 16 Jul 2018 00:39:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732144AbeGPIER (ORCPT + 99 others); Mon, 16 Jul 2018 04:04:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46870 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729883AbeGPIEP (ORCPT ); Mon, 16 Jul 2018 04:04:15 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 20D47CA4; Mon, 16 Jul 2018 07:38:13 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Mike Marciniszyn , Kamenee Arumugam , "Michael J. Ruhl" , Dennis Dalessandro , Jason Gunthorpe Subject: [PATCH 4.17 45/67] IB/hfi1: Fix incorrect mixing of ERR_PTR and NULL return values Date: Mon, 16 Jul 2018 09:35:14 +0200 Message-Id: <20180716073450.280022308@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073443.294323458@linuxfoundation.org> References: <20180716073443.294323458@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael J. Ruhl commit b697d7d8c741f27b728a878fc55852b06d0f6f5e upstream. The __get_txreq() function can return a pointer, ERR_PTR(-EBUSY), or NULL. All of the relevant call sites look for IS_ERR, so the NULL return would lead to a NULL pointer exception. Do not use the ERR_PTR mechanism for this function. Update all call sites to handle the return value correctly. Clean up error paths to reflect return value. Fixes: 45842abbb292 ("staging/rdma/hfi1: move txreq header code") Cc: # 4.9.x+ Reported-by: Dan Carpenter Reviewed-by: Mike Marciniszyn Reviewed-by: Kamenee Arumugam Signed-off-by: Michael J. Ruhl Signed-off-by: Dennis Dalessandro Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/hfi1/rc.c | 2 +- drivers/infiniband/hw/hfi1/uc.c | 4 ++-- drivers/infiniband/hw/hfi1/ud.c | 4 ++-- drivers/infiniband/hw/hfi1/verbs_txreq.c | 4 ++-- drivers/infiniband/hw/hfi1/verbs_txreq.h | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) --- a/drivers/infiniband/hw/hfi1/rc.c +++ b/drivers/infiniband/hw/hfi1/rc.c @@ -271,7 +271,7 @@ int hfi1_make_rc_req(struct rvt_qp *qp, lockdep_assert_held(&qp->s_lock); ps->s_txreq = get_txreq(ps->dev, qp); - if (IS_ERR(ps->s_txreq)) + if (!ps->s_txreq) goto bail_no_tx; if (priv->hdr_type == HFI1_PKT_TYPE_9B) { --- a/drivers/infiniband/hw/hfi1/uc.c +++ b/drivers/infiniband/hw/hfi1/uc.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2015, 2016 Intel Corporation. + * Copyright(c) 2015 - 2018 Intel Corporation. * * This file is provided under a dual BSD/GPLv2 license. When using or * redistributing this file, you may do so under either license. @@ -72,7 +72,7 @@ int hfi1_make_uc_req(struct rvt_qp *qp, int middle = 0; ps->s_txreq = get_txreq(ps->dev, qp); - if (IS_ERR(ps->s_txreq)) + if (!ps->s_txreq) goto bail_no_tx; if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_SEND_OK)) { --- a/drivers/infiniband/hw/hfi1/ud.c +++ b/drivers/infiniband/hw/hfi1/ud.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2015, 2016 Intel Corporation. + * Copyright(c) 2015 - 2018 Intel Corporation. * * This file is provided under a dual BSD/GPLv2 license. When using or * redistributing this file, you may do so under either license. @@ -482,7 +482,7 @@ int hfi1_make_ud_req(struct rvt_qp *qp, u32 lid; ps->s_txreq = get_txreq(ps->dev, qp); - if (IS_ERR(ps->s_txreq)) + if (!ps->s_txreq) goto bail_no_tx; if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) { --- a/drivers/infiniband/hw/hfi1/verbs_txreq.c +++ b/drivers/infiniband/hw/hfi1/verbs_txreq.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2016 - 2017 Intel Corporation. + * Copyright(c) 2016 - 2018 Intel Corporation. * * This file is provided under a dual BSD/GPLv2 license. When using or * redistributing this file, you may do so under either license. @@ -94,7 +94,7 @@ struct verbs_txreq *__get_txreq(struct h struct rvt_qp *qp) __must_hold(&qp->s_lock) { - struct verbs_txreq *tx = ERR_PTR(-EBUSY); + struct verbs_txreq *tx = NULL; write_seqlock(&dev->txwait_lock); if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) { --- a/drivers/infiniband/hw/hfi1/verbs_txreq.h +++ b/drivers/infiniband/hw/hfi1/verbs_txreq.h @@ -1,5 +1,5 @@ /* - * Copyright(c) 2016 Intel Corporation. + * Copyright(c) 2016 - 2018 Intel Corporation. * * This file is provided under a dual BSD/GPLv2 license. When using or * redistributing this file, you may do so under either license. @@ -83,7 +83,7 @@ static inline struct verbs_txreq *get_tx if (unlikely(!tx)) { /* call slow path to get the lock */ tx = __get_txreq(dev, qp); - if (IS_ERR(tx)) + if (!tx) return tx; } tx->qp = qp;