From patchwork Thu Dec 6 11:09:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Shaia X-Patchwork-Id: 10715611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32F4F1932 for ; Thu, 6 Dec 2018 11:10:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22A7E2DBBB for ; Thu, 6 Dec 2018 11:10:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 159502DC27; Thu, 6 Dec 2018 11:10:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEC2B2DBBB for ; Thu, 6 Dec 2018 11:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729522AbeLFLKH (ORCPT ); Thu, 6 Dec 2018 06:10:07 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:54480 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727575AbeLFLKH (ORCPT ); Thu, 6 Dec 2018 06:10:07 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wB6B9Fsg035641; Thu, 6 Dec 2018 11:10:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=hVIXlU1Z9jLSachVbNmKNci6lADkTTJdtl9EOMdvBhU=; b=Q1PvK48hV5fXBEjEfpj0GbhKRT3PR+KJzHzXKBMbO08fb6TYqsNPes9ezWA+836YCDWV Smqi8/RMuLv4MyemVRL1pqmIkiHMi38EM+iKqQt/tNMw0ICOzVOLPkUQ0KicftuGsXL8 xq5xtRndwpeuRMBvJEOJolpGzIMRC2ijsDTanN8uglwtHfnqjbJyi5hYfz9maTDTXIBo D90mF7fos4xosDpZ8jvWffOKmldfX2I0j99vcPPNhIZDW1eFaNcJfOt+eC4h2cA8SKdk 8J7TIouqpUnKyxEdeV7n9kBcpDr4cvKlOcegqJcAxsfybZI9Wtgta0UjRgtVSvoZ5DU0 5w== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2p3ftfbhn1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 06 Dec 2018 11:10:00 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wB6B9s20008392 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Dec 2018 11:09:55 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wB6B9seW032128; Thu, 6 Dec 2018 11:09:54 GMT Received: from localhost.localdomain (/77.138.186.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 06 Dec 2018 03:09:53 -0800 From: Yuval Shaia To: monis@mellanox.com, dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org Cc: Yuval Shaia Subject: [PATCH] IB/rxe: Warn when objects are invalid Date: Thu, 6 Dec 2018 13:09:45 +0200 Message-Id: <20181206110945.9732-1-yuval.shaia@oracle.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9098 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=766 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812060101 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since callers never validates return value let's make sure objects are valid here and do not return NULL. Signed-off-by: Yuval Shaia --- drivers/infiniband/sw/rxe/rxe_verbs.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index 831381b7788d..540e79aebd6b 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -423,47 +423,56 @@ static inline void rxe_counter_inc(struct rxe_dev *rxe, enum rxe_counters cnt) static inline struct rxe_dev *to_rdev(struct ib_device *dev) { - return dev ? container_of(dev, struct rxe_dev, ib_dev) : NULL; + WARN_ONCE(!dev, "Invalid ib_device\n"); + return container_of(dev, struct rxe_dev, ib_dev); } static inline struct rxe_ucontext *to_ruc(struct ib_ucontext *uc) { - return uc ? container_of(uc, struct rxe_ucontext, ibuc) : NULL; + WARN_ONCE(!uc, "Invalid ib_ucontext\n"); + return container_of(uc, struct rxe_ucontext, ibuc); } static inline struct rxe_pd *to_rpd(struct ib_pd *pd) { - return pd ? container_of(pd, struct rxe_pd, ibpd) : NULL; + WARN_ONCE(!pd, "Invalid ib_PD\n"); + return container_of(pd, struct rxe_pd, ibpd); } static inline struct rxe_ah *to_rah(struct ib_ah *ah) { - return ah ? container_of(ah, struct rxe_ah, ibah) : NULL; + WARN_ONCE(!ah, "Invalid ib_AH\n"); + return container_of(ah, struct rxe_ah, ibah); } static inline struct rxe_srq *to_rsrq(struct ib_srq *srq) { - return srq ? container_of(srq, struct rxe_srq, ibsrq) : NULL; + WARN_ONCE(!srq, "Invalid ib_SRQ\n"); + return container_of(srq, struct rxe_srq, ibsrq); } static inline struct rxe_qp *to_rqp(struct ib_qp *qp) { - return qp ? container_of(qp, struct rxe_qp, ibqp) : NULL; + WARN_ONCE(!qp, "Invalid ib_QP\n"); + return container_of(qp, struct rxe_qp, ibqp); } static inline struct rxe_cq *to_rcq(struct ib_cq *cq) { - return cq ? container_of(cq, struct rxe_cq, ibcq) : NULL; + WARN_ONCE(!cq, "Invalid ib_CQ\n"); + return container_of(cq, struct rxe_cq, ibcq); } static inline struct rxe_mem *to_rmr(struct ib_mr *mr) { - return mr ? container_of(mr, struct rxe_mem, ibmr) : NULL; + WARN_ONCE(!mr, "Invalid ib_MR\n"); + return container_of(mr, struct rxe_mem, ibmr); } static inline struct rxe_mem *to_rmw(struct ib_mw *mw) { - return mw ? container_of(mw, struct rxe_mem, ibmw) : NULL; + WARN_ONCE(!mw, "Invalid ib_MW\n"); + return container_of(mw, struct rxe_mem, ibmw); } int rxe_register_device(struct rxe_dev *rxe);