From patchwork Wed Sep 6 21:34:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9941327 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 CD17B60216 for ; Wed, 6 Sep 2017 21:37:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4E5426E54 for ; Wed, 6 Sep 2017 21:37:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE18B2623C; Wed, 6 Sep 2017 21:37:06 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 19EA427F17 for ; Wed, 6 Sep 2017 21:36:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752513AbdIFVgO (ORCPT ); Wed, 6 Sep 2017 17:36:14 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:52484 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752313AbdIFVgN (ORCPT ); Wed, 6 Sep 2017 17:36:13 -0400 Received: from wuerfel.lan ([95.208.190.237]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0MQcnt-1e1ybr1oB3-00U0t5; Wed, 06 Sep 2017 23:35:26 +0200 From: Arnd Bergmann To: Doug Ledford , Sean Hefty , Hal Rosenstock Cc: Christoph Hellwig , Arnd Bergmann , Matan Barak , Yishai Hadas , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] [v2] IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage Date: Wed, 6 Sep 2017 23:34:25 +0200 Message-Id: <20170906213521.1845893-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:M3+f9vDsE8sfuvpnVFWcpvBtbkH+USMjA/TwRQruJWdJMxSMU9P zEWShRO5nj1FtyTm8rRIj+dUmd8Ye5vQMCUK+N1E0NaMM0TOGhMGVOpdoYdtOwZiVnNNp61 H4kan/Rn5p6X6dnufHEJSkD0NCk3uZQA4awTOypHRe2p821/dN/l8tPmbU7ti98bIhQ1y/8 ziHgc630HhdzzoHWoBWlQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Ok7b4MQePvc=:VIAp48ufGmANCe0p4qyK0/ 6+fmK90PuAL7YxQ+mwyb7uBHNBlhTafobt7thhVPfuYwDKGYzrP7HUKpSSqYDy4xUH7ytd7Ww wVLBR+pQ5IGmrPkIVLQnp3G03Sk2YGInQ6Z68zpV+z+YPd/vnrEHfDqUm7nLJboksLAvhtRj2 ndXDDXGPCBSDkvm+qbiIbxdpQ0RrG1WBgsRRU7a/7dNeML77qV+OdRlxmSxSSiM7QDSmYZ54o 0zGRX9DjtFYADqMfBwC9aZj+hw1IfFcSAOtNnpfXmBmGuPHtxSQm+oXhvPCRGF4YSJrgl1g9B M7L32qYkv1PnVS368FwLHOsVGry50UhdruBnjg0vQ3/FwQaR2yXw+54HYzltj7Gfhl6bwVeN9 /tGxNUrbRRdf2jHKu+r5Ic+A6kZxHWsmzSmJJtZXEQnPK0wwzJTXoWDFTpF1fHRRpNbagN/+n WnkeiDByGqIKbkxKN55Lv9r9dCAdUGFuc3AdhL//MmKS8F1NmHGKzkXNDEwAUTf8qNFsTlpr+ R8H97/BuS3bJXCD3j/uplz1GNbG1QgWDl+o/UQJ8FRaTjM5bTgjxZ58MrWZlWJ852L6S3D56U bIzdCz15PQM1XRzkxPL39rXscJSuxJOCrXuKY3tYf85CYe+XpDXQBL/wmiDDl9MhpCsPcZWIi 8f3ja01HYcwEIdomDq4E2f7n9tMZ3X9NpeVHuMgwptClK837dftkWF/YXB9NhFGweQKJLDSej b3lrHRCvjmBVplyc38qyc26RVNXkRPxBrY5JTw== 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 We get a harmless warning about the fact that we use the result of a multiplication as a condition: drivers/infiniband/core/uverbs_main.c: In function 'ib_uverbs_write': drivers/infiniband/core/uverbs_main.c:787:40: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] drivers/infiniband/core/uverbs_main.c:787:117: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] drivers/infiniband/core/uverbs_main.c:790:50: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] drivers/infiniband/core/uverbs_main.c:790:151: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] This avoids the problem by using an inline function in place of the macro. Fixes: a96e4e2ffe43 ("IB/uverbs: New macro to set pointers to NULL if length is 0 in INIT_UDATA()") Suggested-by: Christoph Hellwig Link: https://patchwork.kernel.org/patch/9940777/ Signed-off-by: Arnd Bergmann --- v2: completely rewrite the patch to a larger cleanup. --- drivers/infiniband/core/uverbs.h | 15 ++++++++------- drivers/infiniband/core/uverbs_main.c | 22 ++++++++++------------ drivers/infiniband/core/uverbs_std_types.c | 3 ++- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h index 37c8903e7fd0..a8f104a4a91b 100644 --- a/drivers/infiniband/core/uverbs.h +++ b/drivers/infiniband/core/uverbs.h @@ -55,13 +55,14 @@ (udata)->outlen = (olen); \ } while (0) -#define INIT_UDATA_BUF_OR_NULL(udata, ibuf, obuf, ilen, olen) \ - do { \ - (udata)->inbuf = (ilen) ? (const void __user *) (ibuf) : NULL; \ - (udata)->outbuf = (olen) ? (void __user *) (obuf) : NULL; \ - (udata)->inlen = (ilen); \ - (udata)->outlen = (olen); \ - } while (0) +static inline void +ib_uverbs_init_udata_buf_or_null(struct ib_udata *udata, + const void __user *ibuf, + void __user *obuf, + size_t ilen, size_t olen) +{ + INIT_UDATA(udata, ilen ? ibuf : NULL, olen ? obuf : NULL, ilen, olen); +} /* * Our lifetime rules for these structs are the following: diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index dc2aed6fb21b..b5febfd84ee5 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -763,7 +763,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, } if (!access_ok(VERIFY_WRITE, - (void __user *) (unsigned long) ex_hdr.response, + u64_to_user_ptr(ex_hdr.response), (hdr.out_words + ex_hdr.provider_out_words) * 8)) { ret = -EFAULT; goto out; @@ -775,19 +775,17 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, } } - INIT_UDATA_BUF_OR_NULL(&ucore, buf, (unsigned long) ex_hdr.response, - hdr.in_words * 8, hdr.out_words * 8); + ib_uverbs_init_udata_buf_or_null(&ucore, buf, + u64_to_user_ptr(ex_hdr.response), + hdr.in_words * 8, hdr.out_words * 8); - INIT_UDATA_BUF_OR_NULL(&uhw, - buf + ucore.inlen, - (unsigned long) ex_hdr.response + ucore.outlen, - ex_hdr.provider_in_words * 8, - ex_hdr.provider_out_words * 8); + ib_uverbs_init_udata_buf_or_null(&uhw, + buf + ucore.inlen, + u64_to_user_ptr(ex_hdr.response) + ucore.outlen, + ex_hdr.provider_in_words * 8, + ex_hdr.provider_out_words * 8); - ret = uverbs_ex_cmd_table[command](file, - ib_dev, - &ucore, - &uhw); + ret = uverbs_ex_cmd_table[command](file, ib_dev, &ucore, &uhw); if (!ret) ret = written_count; } else { diff --git a/drivers/infiniband/core/uverbs_std_types.c b/drivers/infiniband/core/uverbs_std_types.c index 0a98579700ec..b095bce7f238 100644 --- a/drivers/infiniband/core/uverbs_std_types.c +++ b/drivers/infiniband/core/uverbs_std_types.c @@ -246,7 +246,8 @@ static void create_udata(struct uverbs_attr_bundle *ctx, outbuf_len = uhw_out->ptr_attr.len; } - INIT_UDATA_BUF_OR_NULL(udata, inbuf, outbuf, inbuf_len, outbuf_len); + ib_uverbs_init_udata_buf_or_null(udata, inbuf, outbuf, inbuf_len, + outbuf_len); } static int uverbs_create_cq_handler(struct ib_device *ib_dev,