From patchwork Wed Oct 11 15:30:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9999933 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 10E7D602BF for ; Wed, 11 Oct 2017 15:30:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F17EB28A86 for ; Wed, 11 Oct 2017 15:30:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E626C28A88; Wed, 11 Oct 2017 15:30:50 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 6205728A86 for ; Wed, 11 Oct 2017 15:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751554AbdJKPat (ORCPT ); Wed, 11 Oct 2017 11:30:49 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:34421 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751459AbdJKPan (ORCPT ); Wed, 11 Oct 2017 11:30:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1507735843; x=1539271843; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=kdLmtT60Zge4VD3bpR82jmXM2jEQEDNnL6h1jM6O+tE=; b=d8y/nHhNesuTvEIC0jA+CqmOfG8N4ZLMyMwEf5zbej0YQt3VN6eZORMf u9lUq5SStKZXDU4C3XGCntn1VVTFMXqyarV+SHUT8GqHdZrlgpoI5XjOL wEnlGXtoV746s2LUi7T7jaHCJgH8mqgytg4iLk2vxzr/LvDJMisnBKtgj LNBa8qSTA0NInkdRgWlJi86PN2mlt6TcjJni/FrMZ/CyoUrStNXJeAmgN d0m7en7SSUOJQ0OCK3fVpcFZnNxRaSUiYrX+Sv0t7H8ILyvk5EMg6NwxV SP/zZF2sN6C3a05s5JY5P8SfP6GWQHr/9KsGPXvuRkggP6LNcL4ZFSe2w A==; X-IronPort-AV: E=Sophos;i="5.43,361,1503331200"; d="scan'208";a="159967407" Received: from mail-sn1nam01lp0118.outbound.protection.outlook.com (HELO NAM01-SN1-obe.outbound.protection.outlook.com) ([207.46.163.118]) by ob1.hgst.iphmx.com with ESMTP; 11 Oct 2017 23:30:42 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kdLmtT60Zge4VD3bpR82jmXM2jEQEDNnL6h1jM6O+tE=; b=OkLsxRXlB3uoEze64zQPg1NVy2YCX06MU/poV4Ijzt9kQzz5GUbkdDiccpxcKgQo7co1Hg6RI3jd2glzAF8+1RXRyPrd3DeS+aVFbLz0ZsNjz5HpS/u2p3h7KKI8PVAPtt65BdtTKvO8nPqs+VBmi2p51O+B5reBe15ZG1+0/vU= Received: from CY1PR0401MB1536.namprd04.prod.outlook.com (10.163.19.154) by CY1PR0401MB1535.namprd04.prod.outlook.com (10.163.19.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 11 Oct 2017 15:30:41 +0000 Received: from CY1PR0401MB1536.namprd04.prod.outlook.com ([10.163.19.154]) by CY1PR0401MB1536.namprd04.prod.outlook.com ([10.163.19.154]) with mapi id 15.20.0077.019; Wed, 11 Oct 2017 15:30:41 +0000 From: Bart Van Assche To: "matanb@mellanox.com" CC: "linux-rdma@vger.kernel.org" , "yishaih@mellanox.com" , "dledford@redhat.com" Subject: Re: [PATCH 05/47] RDMA/uverbs: Make the code in ib_uverbs_cmd_verbs() less confusing Thread-Topic: [PATCH 05/47] RDMA/uverbs: Make the code in ib_uverbs_cmd_verbs() less confusing Thread-Index: AQHTPurGnnFW0bpxX0etz2FtdxIccqLbJeMAgACkCQCAAllDAIAAqsUA Date: Wed, 11 Oct 2017 15:30:41 +0000 Message-ID: <1507735840.2477.8.camel@wdc.com> References: <20171006213333.6721-1-bart.vanassche@wdc.com> <20171006213333.6721-6-bart.vanassche@wdc.com> <64b5f415-7d56-3f17-0c8c-5d80ba89582c@mellanox.com> <1507570048.2674.17.camel@wdc.com> <3a6adf24-3e60-7fd1-a119-37586793d374@mellanox.com> In-Reply-To: <3a6adf24-3e60-7fd1-a119-37586793d374@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@wdc.com; x-originating-ip: [63.163.107.100] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY1PR0401MB1535; 20:DMIZPI3Znx8PfBWImohp8WpCmYR4ZssESlQp7AgSVWzDytA9+LINzhqV11wMU0SpRUEdQnG4fuEtw6J8nX7pvl7xeV1NvzBn4Lo8RfRT9cYTieHYgnDSKfHljYDEath7RnZEzk4gt1L+NJ42CxZmfrTwARwDuiqgrdjwVLQiq7s= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 60252114-63cb-4597-3010-08d510bd084f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:CY1PR0401MB1535; x-ms-traffictypediagnostic: CY1PR0401MB1535: wdcipoutbound: EOP-TRUE x-exchange-antispam-report-test: UriScan:(20558992708506); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY1PR0401MB1535; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY1PR0401MB1535; x-forefront-prvs: 0457F11EAF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(376002)(346002)(39860400002)(377424004)(24454002)(189002)(199003)(305945005)(6512007)(8676002)(2351001)(1730700003)(53936002)(2501003)(72206003)(99286003)(2906002)(81166006)(6916009)(93886005)(101416001)(5640700003)(2900100001)(6246003)(54906003)(4001150100001)(33646002)(14454004)(36756003)(81156014)(86362001)(189998001)(316002)(97736004)(66066001)(77096006)(229853002)(3846002)(6486002)(5660300001)(25786009)(4326008)(103116003)(6116002)(102836003)(3280700002)(105586002)(478600001)(2950100002)(68736007)(50986999)(8936002)(3660700001)(76176999)(106356001)(7736002)(6436002)(6506006)(54356999); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0401MB1535; H:CY1PR0401MB1536.namprd04.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Oct 2017 15:30:41.6126 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0401MB1535 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 On Wed, 2017-10-11 at 08:19 +0300, Matan Barak wrote: > But what about cases where UVERBS_OPTIMIZE_USING_STACK_SZ is defined but > is insufficient in size? Sorry. How about the patch below? The most significant change compared to the current code is that UVERBS_OPTIMIZE_USING_STACK_SZ has to be defined as 0 instead of not defining that macro to disable the optimization. A new change is that this version uses gcc's support for zero-length arrays (which is an extension of the C standard and is already used elsewhere in the kernel). Subject: [PATCH] RDMA/uverbs: Make the code in ib_uverbs_cmd_verbs() less confusing This patch reduces the number of #ifdefs and also avoids that smatch reports the following: drivers/infiniband/core/uverbs_ioctl.c:276: ib_uverbs_cmd_verbs() warn: if statement not indented drivers/infiniband/core/uverbs_ioctl.c:280: ib_uverbs_cmd_verbs() warn: possible memory leak of 'ctx' drivers/infiniband/core/uverbs_ioctl.c:315: ib_uverbs_cmd_verbs() warn: if statement not indented References: commit fac9658cabb9 ("IB/core: Add new ioctl interface") Signed-off-by: Bart Van Assche Cc: Matan Barak Cc: Yishai Hadas --- drivers/infiniband/core/uverbs_ioctl.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) -- 2.14.2 Acked-by: Matan Barak diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c index 5286ad57d903..71ff2644e053 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -241,9 +241,7 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, struct uverbs_attr *curr_attr; unsigned long *curr_bitmap; size_t ctx_size; -#ifdef UVERBS_OPTIMIZE_USING_STACK_SZ uintptr_t data[UVERBS_OPTIMIZE_USING_STACK_SZ / sizeof(uintptr_t)]; -#endif if (hdr->reserved) return -EINVAL; @@ -269,13 +267,10 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, (method_spec->num_child_attrs / BITS_PER_LONG + method_spec->num_buckets); -#ifdef UVERBS_OPTIMIZE_USING_STACK_SZ if (ctx_size <= UVERBS_OPTIMIZE_USING_STACK_SZ) ctx = (void *)data; - if (!ctx) -#endif - ctx = kmalloc(ctx_size, GFP_KERNEL); + ctx = kmalloc(ctx_size, GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -311,10 +306,8 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, err = uverbs_handle_method(buf, ctx->uattrs, hdr->num_attrs, ib_dev, file, method_spec, ctx->uverbs_attr_bundle); out: -#ifdef UVERBS_OPTIMIZE_USING_STACK_SZ - if (ctx_size > UVERBS_OPTIMIZE_USING_STACK_SZ) -#endif - kfree(ctx); + if (ctx != (void *)data) + kfree(ctx); return err; }