From patchwork Fri Jul 13 10:26:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Heib X-Patchwork-Id: 10522997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 611B5602A0 for ; Fri, 13 Jul 2018 10:26:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5091C29665 for ; Fri, 13 Jul 2018 10:26:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44A9C2969B; Fri, 13 Jul 2018 10:26:51 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 DDFE229665 for ; Fri, 13 Jul 2018 10:26:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727040AbeGMKkv (ORCPT ); Fri, 13 Jul 2018 06:40:51 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45844 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727147AbeGMKkv (ORCPT ); Fri, 13 Jul 2018 06:40:51 -0400 Received: by mail-wr1-f68.google.com with SMTP id c4-v6so11923669wrs.12 for ; Fri, 13 Jul 2018 03:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S8m1bJaym3jspWfcaUj/lW83s4A5fbfCvA+ZaxqbHtY=; b=CTi8pQJYphehNilG3ptZht91Y12Ed1CCyUqNh2W/gdY7lnU6w99zNMfhFXVgtwQ3bo 6As8rzi+SJ8M7/MjMSuNYe6fY5PVKR3BXtMoULmwVo7YMMgphhaoHkMQxjjZKz0zj7II tm9PGz2SHT1ZHcOWzu5mtXzY15pHgqWbsgR4LKtp/fSsy4QeId/8C1SOk7w3RPScCoWB KQTdBP63CV9qgeBi7yiNBfwDCnDQjUm/R817nQaDT8O++TBMOUMI5tLABFL6VmvMU2ar awGJQq+lzyVIRrKOdiKjiSlzxfZFMErJroq9WCA9uk12uKEvlSwSkzmlCs/qWdzaZdZU dK4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S8m1bJaym3jspWfcaUj/lW83s4A5fbfCvA+ZaxqbHtY=; b=fW3aceBcpl/SNSonQxpGPGsdb9Ovdh6xXOGe06KmfTUl5s8CMDv73JlUN/UEhnFJkS QkSZBkjXF7oLzCrfAyhUO+DvI5omIi6kEMf9QIHG0jFhTkhyb6mydmDWSAlAdbIdhN4a I0+i2Sm0UKhW4rnmmcAyWFRwmVapxDv5AMOmTjbfuoMwnKerB1a18kW86oc9QFvhK6ge 1xmgmFzTOjH7q7kL2wPSGT/YOwBPOrvIdJ09q9KPuuzz1LwP1YDJjStbxRipElrTR9ab C2n0+Fkuur0P0Hqjnc8KSIgCqTRWLp1D5BOxuDh96vIBgFrQvNNlXDh3+AhYFBsaEEQK vOyw== X-Gm-Message-State: AOUpUlE1GWFdPcM2I5oJKCM7o2xE94N2gxbGrYocIxMYGjJRjQgk7Kts yFdczdQcgN44nlDy0m1QwfA= X-Google-Smtp-Source: AAOMgpeqzFVZRSqaT9c53/hKsVJ+bryonmZJ6fedaZlZcfQEBwz7+WGgayxZPU55mD24nUTMNnoOnA== X-Received: by 2002:adf:8062:: with SMTP id 89-v6mr4146987wrk.221.1531477608321; Fri, 13 Jul 2018 03:26:48 -0700 (PDT) Received: from localhost.localdomain (bzq-109-67-23-64.red.bezeqint.net. [109.67.23.64]) by smtp.gmail.com with ESMTPSA id 6-v6sm8920277wmi.26.2018.07.13.03.26.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jul 2018 03:26:47 -0700 (PDT) From: Kamal Heib To: Doug Ledford , Jason Gunthorpe Cc: linux-rdma@vger.kernel.org, Kamal Heib Subject: [PATCH rdma-next 1/2] RDMA/core: Check for verbs callbacks before using them Date: Fri, 13 Jul 2018 13:26:29 +0300 Message-Id: <20180713102630.22193-2-kamalheib1@gmail.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180713102630.22193-1-kamalheib1@gmail.com> References: <20180713102630.22193-1-kamalheib1@gmail.com> 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 Make sure the providers implement the verbs callbacks before calling them, otherwise return -EOPNOTSUPP. Signed-off-by: Kamal Heib --- drivers/infiniband/core/mad.c | 10 ++++++---- drivers/infiniband/core/uverbs_cmd.c | 3 ++- drivers/infiniband/core/verbs.c | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c index 34e9b2768324..e528387605c8 100644 --- a/drivers/infiniband/core/mad.c +++ b/drivers/infiniband/core/mad.c @@ -882,10 +882,12 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv, } /* No GRH for DR SMP */ - ret = device->process_mad(device, 0, port_num, &mad_wc, NULL, - (const struct ib_mad_hdr *)smp, mad_size, - (struct ib_mad_hdr *)mad_priv->mad, - &mad_size, &out_mad_pkey_index); + ret = device->process_mad ? + device->process_mad(device, 0, port_num, &mad_wc, NULL, + (const struct ib_mad_hdr *)smp, mad_size, + (struct ib_mad_hdr *)mad_priv->mad, + &mad_size, &out_mad_pkey_index) : + -EOPNOTSUPP; switch (ret) { case IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY: diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index bd6eefaecbd6..6ab00f322b62 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -2507,7 +2507,8 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, goto out; resp.bad_wr = 0; - ret = srq->device->post_srq_recv(srq, wr, &bad_wr); + ret = srq->device->post_srq_recv ? + srq->device->post_srq_recv(srq, wr, &bad_wr) : -EOPNOTSUPP; uobj_put_obj_read(srq); diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index b6ceb6fd6a67..03b8c5448303 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -479,6 +479,9 @@ static struct ib_ah *_rdma_create_ah(struct ib_pd *pd, { struct ib_ah *ah; + if (!pd->device->create_ah) + return ERR_PTR(-EOPNOTSUPP); + ah = pd->device->create_ah(pd, ah_attr, udata); if (!IS_ERR(ah)) { @@ -911,6 +914,9 @@ int rdma_destroy_ah(struct ib_ah *ah) struct ib_pd *pd; int ret; + if (!ah->device->destroy_ah) + return -EOPNOTSUPP; + pd = ah->pd; ret = ah->device->destroy_ah(ah); if (!ret) {