From patchwork Mon Jan 28 10:12:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shamir Rabinovitch X-Patchwork-Id: 10783535 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 5E73113B5 for ; Mon, 28 Jan 2019 10:13:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43B592A798 for ; Mon, 28 Jan 2019 10:13:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3329C2A7D7; Mon, 28 Jan 2019 10:13:00 +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 10AAA2A798 for ; Mon, 28 Jan 2019 10:12:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726738AbfA1KM6 (ORCPT ); Mon, 28 Jan 2019 05:12:58 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:37970 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbfA1KM6 (ORCPT ); Mon, 28 Jan 2019 05:12:58 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0SA8gpO131721; Mon, 28 Jan 2019 10:12:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=sAFMipNH0Obq/Z0iwYFEd9BJ/35bYzGLx3T+rp8UzPo=; b=UOGxacbitvEJUnbq4KNNGm9VaE7qji+HiJGE9REN8L8IFVqnrL4fB9t6nK4QuJg5KyBr WAygRae72IPrHSsfbrb6tQigTAlfGAbj0iFbf84c2KaCVx7tCkSC/RK9SXjdwviBvNfB 4MSpNLN8BM4IV5pJIIfMZ0BvgbNX5O3udnQZuVprNH1ZSI+gXqHeBpqPhBXWz1lh0PJQ ZOikBSIaa/glu7ry51xQy/W3x/mBzab/AFOaJQFMon6IhjUIe5GFUww8wsUroopABOWo l/k3mU9Wmv2GGa5ucrOBv+Tt9/2Re3t9+RFAmhbsQYnoWGSG9NHJj6/OlUhRkbh3yWQI Og== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2q8g6qw54e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jan 2019 10:12:55 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0SACnx4030946 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jan 2019 10:12:50 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0SACner023449; Mon, 28 Jan 2019 10:12:49 GMT Received: from localhost.localdomain (/10.175.62.22) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Jan 2019 02:12:48 -0800 From: Shamir Rabinovitch To: linux-rdma@vger.kernel.org Cc: shamir.rabinovitch@oracle.com, jgg@ziepe.ca, dledford@redhat.com Subject: [PATCH for-next v2 2/3] IB/verbs: add helper function rdma_udata_to_drv_context Date: Mon, 28 Jan 2019 12:12:23 +0200 Message-Id: <20190128101236.8257-1-shamir.rabinovitch@oracle.com> X-Mailer: git-send-email 2.17.2 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9149 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901280083 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 Helper function to get driver's context out of ib_udata wrapped in uverbs_attr_bundle for uer objects or NULL for kernel objects. Signed-off-by: Shamir Rabinovitch --- include/rdma/ib_verbs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 94b6e1dd4dab..fb4d078d6db3 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -4264,4 +4264,18 @@ static inline struct ib_device *rdma_device_to_ibdev(struct device *device) */ #define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member) \ container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member) + +/** + * rdma_udata_to_drv_context - Helper macro to get the driver's context out of + * ib_udata which is embadded in uverbs_attr_bundle. + * + * NOTE: This macro return NULL for kernel objects and valid driver context for + * user objects. + */ +#define rdma_udata_to_drv_context(udata, drv_dev_struct, member) \ + ({ struct ib_ucontext *_ibctx = rdma_get_ucontext(udata); \ + IS_ERR(_ibctx) ? NULL : \ + container_of(_ibctx, drv_dev_struct, member); \ + }) + #endif /* IB_VERBS_H */