From patchwork Mon Oct 9 17:27:29 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: 9993975 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 2BE3E60216 for ; Mon, 9 Oct 2017 17:27:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15DB2201B1 for ; Mon, 9 Oct 2017 17:27:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AACE20881; Mon, 9 Oct 2017 17:27:36 +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 45952201B1 for ; Mon, 9 Oct 2017 17:27:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754908AbdJIR1e (ORCPT ); Mon, 9 Oct 2017 13:27:34 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:58150 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754752AbdJIR1d (ORCPT ); Mon, 9 Oct 2017 13:27:33 -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=1507570052; x=1539106052; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=5jPtttc4GuZNjvhc3jls7z5WoDeSBhl7CHRS0QIYtr8=; b=NMjOh7/Y8fMy5IarCXn4kwRMEuIN6RYBr35YU9BQkCqVc9aB4pBtCsYo IugCJfw3jQCKb9Bwtz3AzD85GV9toGsbnEr/F1ohTSmYGei/YYbTiyQl6 dfMuqLwxBfjqSqeOtsQrCHfyfN5q3NnCa2ZVzuGYxBmv7q287ZjdAAPdj 9jYbNH0O3HH0GJS3t+xqpkxrb5CBZ513/E3In8bPRtk3XyaWUEtguXQXq QZWgvj6GUemD6CBOZftjLc2ZIzaorMlzzpBEK01j5Q3a44Ie9rLZP51jt uEsIY1BZxQrh3iIBQTKNcqTp7mc1OT4G8JKrnYU/tGmZWXk0NOiWZWeXD w==; X-IronPort-AV: E=Sophos;i="5.42,501,1500912000"; d="scan'208";a="159613322" Received: from mail-co1nam03lp0015.outbound.protection.outlook.com (HELO NAM03-CO1-obe.outbound.protection.outlook.com) ([216.32.181.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2017 01:27:31 +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=5jPtttc4GuZNjvhc3jls7z5WoDeSBhl7CHRS0QIYtr8=; b=Xg+UJgQnayvW0dFdHCbqyg6L9vacCKjhgGfT4BuK82DclQpSEGVrFWvHq6vg/bT1w8U+ZiwkV+Mj4lWfUpCjyAbqY5dhFhofiXSJ9DO6G9FGFBrE5U1+Ti1AiBONtvMfuldEpqmXTagd51iG9TzGERoNDDmpHEqvNfhm1LuduZE= Received: from CY1PR0401MB1536.namprd04.prod.outlook.com (10.163.19.154) by CY1PR0401MB1533.namprd04.prod.outlook.com (10.163.19.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Mon, 9 Oct 2017 17:27:30 +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; Mon, 9 Oct 2017 17:27:30 +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: AQHTPurGnnFW0bpxX0etz2FtdxIccqLbJeMAgACkCQA= Date: Mon, 9 Oct 2017 17:27:29 +0000 Message-ID: <1507570048.2674.17.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> In-Reply-To: <64b5f415-7d56-3f17-0c8c-5d80ba89582c@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; CY1PR0401MB1533; 20:DnINfKTcVb4tT9ZCLmhz/ujaXddtKAfrD7fRMzkKG4mPpah4EXSIx/gEMLmtHP7UQDVHlS3YClDaldw5P8eOsZGgoGUBS/XW222R9cix9BIGkfzZJwGTDWB5rksfAt4eOiwT8cAyl0Fv+2rzflCriL464dj/zKwbZYGEZ5Xse5Y= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 8a52cb3c-391b-428b-e775-08d50f3b04cf x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:CY1PR0401MB1533; x-ms-traffictypediagnostic: CY1PR0401MB1533: 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)(5005006)(8121501046)(100000703101)(100105400095)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY1PR0401MB1533; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY1PR0401MB1533; x-forefront-prvs: 045584D28C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(39860400002)(346002)(376002)(199003)(377424004)(24454002)(189002)(5660300001)(99286003)(5640700003)(53546010)(2501003)(7736002)(305945005)(4326008)(14454004)(81166006)(33646002)(66066001)(2906002)(2351001)(6246003)(6116002)(3846002)(316002)(102836003)(53936002)(97736004)(72206003)(6512007)(8676002)(1730700003)(8936002)(25786009)(105586002)(36756003)(86362001)(103116003)(2900100001)(50986999)(54906003)(3660700001)(3280700002)(101416001)(189998001)(6506006)(68736007)(81156014)(478600001)(6486002)(77096006)(106356001)(2950100002)(6916009)(76176999)(54356999)(229853002)(6436002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0401MB1533; H:CY1PR0401MB1536.namprd04.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <95D1399D4F45D047B64ED017A4E0DA6E@namprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Oct 2017 17:27:29.8670 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0401MB1533 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 Mon, 2017-10-09 at 10:40 +0300, Matan Barak (External) wrote: > On 07/10/2017 00:32, Bart Van Assche wrote: > > 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 | 20 +++++++++----------- > > 1 file changed, 9 insertions(+), 11 deletions(-) > > > > diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c > > index 5286ad57d903..53f780ea49fe 100644 > > --- a/drivers/infiniband/core/uverbs_ioctl.c > > +++ b/drivers/infiniband/core/uverbs_ioctl.c > > @@ -234,7 +234,7 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, > > const struct uverbs_method_spec *method_spec; > > long err = 0; > > unsigned int i; > > - struct { > > + struct attr_and_bundle { > > struct ib_uverbs_attr *uattrs; > > struct uverbs_attr_bundle *uverbs_attr_bundle; > > } *ctx = NULL; > > @@ -242,7 +242,10 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, > > 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)]; > > + uintptr_t __data[UVERBS_OPTIMIZE_USING_STACK_SZ / sizeof(uintptr_t)]; > > + struct attr_and_bundle *const data = (void *)__data; > > +#else > > + struct attr_and_bundle *const data = NULL; > > #endif > > > > if (hdr->reserved) > > @@ -269,13 +272,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) > > If UVERBS_OPTIMIZE_USING_STACK_SZ isn't defined, you'll get an error here. > Maybe we could define it as 0 in the else part of the local variables deceleration. Hello Matan, That's an interesting suggestion but that wouldn't work well with the "#ifdef UVERBS_OPTIMIZE_USING_STACK_SZ" code in the declaration section. How about changing "if (ctx_size <= UVERBS_OPTIMIZE_USING_STACK_SZ) ctx = data;" into "ctx = data;" such that it becomes again safe not to define UVERBS_OPTIMIZE_USING_STACK_SZ? With that change this patch looks as follows: diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c index 5286ad57d903..81c05ba2a58b 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -234,7 +234,7 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, const struct uverbs_method_spec *method_spec; long err = 0; unsigned int i; - struct { + struct attr_and_bundle { struct ib_uverbs_attr *uattrs; struct uverbs_attr_bundle *uverbs_attr_bundle; } *ctx = NULL; @@ -242,7 +242,10 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, 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)]; + uintptr_t __data[UVERBS_OPTIMIZE_USING_STACK_SZ / sizeof(uintptr_t)]; + struct attr_and_bundle *const data = (void *)__data; +#else + struct attr_and_bundle *const data = NULL; #endif if (hdr->reserved) @@ -269,13 +272,9 @@ 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; - + ctx = data; if (!ctx) -#endif - ctx = kmalloc(ctx_size, GFP_KERNEL); + ctx = kmalloc(ctx_size, GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -311,10 +310,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 != data) + kfree(ctx); return err; }