Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6241699ybi; Tue, 4 Jun 2019 21:32:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqywQS1J7QLz3N2gk4HVLreWdp7y2ckTvdiqr70UTqJv8W3Qo3KERf2fbzLfkwjI80VRvRBM X-Received: by 2002:a17:90a:31c:: with SMTP id 28mr25883pje.115.1559709128066; Tue, 04 Jun 2019 21:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559709128; cv=none; d=google.com; s=arc-20160816; b=eMDfexmriX9qsrV0nIg7rmGsCqbuGsWhGNINgM6kR4Pi/UWqIZHziUKak6+ZiinUw6 6c4pBmDBedazIgYfjAgY+7TKgcMahhpvm1an/pWjl7p6jsmTb/xdvIoTXcD87prSEqxj lJUTErtVLk1baCKqPu1hr6DsjS8p+Fii/x9tLbfle4smseAPMdN/s6rEuDI+3LHnY1Zw qI6//5Z9EkKGALhofZ4UoRn80wJXs3Hs4QcEv6Er1deD22OlyCtIgg4OmDSqidfScwx/ o3n+2mDOVOjMH3IlnKEnEfb+C3EzkqB/0G7IilEgOoyqNNUtzGSmSjLIxhIiJ9FV3tBF P/AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5jzDsJbomOBKbxZjHAM5xSy8scYmzTU6CO1Yhwn6y5c=; b=fHKnJT4TjDV0ASHrpr08r9MGqhSqvZ6YzlGRcav+fCgD/8uD83n85ZcJGHcgGDd6O6 pDJqmeUuh4YyUxsQlKUAMM3ISL32Fqx9nczzIEICwUT63U4K1cWtNfcUlGDZsiRbNRtG Jk5VL6stXTlkE7w0dudivjcBBc+jA9dH4igKO6D7W+H3LY9kh2A4OPmo5OwF+jxjgxFG CRTROSJwT1X66/iPXTvUR094r8jlX873416V/wqUzSfaQCk+lczNpnkj68CwWaxIofKp nn11ZBTqWWMluQRfEKeP3INrAiLK5haDjj5ytZX49mLq3zxcfVhD7CUccK66HiaONXmR TKBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rfP+t6Lw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6si26495114pla.84.2019.06.04.21.31.36; Tue, 04 Jun 2019 21:32:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rfP+t6Lw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726532AbfFEE3n (ORCPT + 99 others); Wed, 5 Jun 2019 00:29:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:56776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725268AbfFEE3n (ORCPT ); Wed, 5 Jun 2019 00:29:43 -0400 Received: from localhost (unknown [37.142.3.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 29F0520717; Wed, 5 Jun 2019 04:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559708982; bh=w2CzsgB03HnwH8N+KwXOYidngpX3ROt58BgSkWlBqH0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rfP+t6Lw6NIOhWUezyYpW9OtfeIfMo16FqjNrslR9zKUz295zUOUjDu+wYOzGiLUw LuiIGLxX3/shn+kM5wnt/KVV3WcbmRq7wyPasvGXMSQFfwNsdDU1P4UEFC6Oq+CWF1 a7GY6dvLO/3+7jN6qKx4z0iHDkITBZkgB4zgQjVc= Date: Wed, 5 Jun 2019 07:29:38 +0300 From: Leon Romanovsky To: "Gustavo A. R. Silva" Cc: Doug Ledford , Jason Gunthorpe , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] RDMA/ucma: Use struct_size() helper Message-ID: <20190605042938.GL5261@mtr-leonro.mtl.com> References: <20190604154222.GA8938@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190604154222.GA8938@embeddedor> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 04, 2019 at 10:42:22AM -0500, Gustavo A. R. Silva wrote: > Make use of the struct_size() helper instead of an open-coded version > in order to avoid any potential type mistakes, in particular in the > context in which this code is being used. What does "in particular in the context in which this code is being used" mean? > > So, replace the following form: > > sizeof(*resp) + (i * sizeof(struct ib_path_rec_data)) > > with: > > struct_size(resp, path_data, i) It is already written inside commit itself. > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva > --- > drivers/infiniband/core/ucma.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c > index 140a338a135f..cbe460076611 100644 > --- a/drivers/infiniband/core/ucma.c > +++ b/drivers/infiniband/core/ucma.c > @@ -951,8 +951,7 @@ static ssize_t ucma_query_path(struct ucma_context *ctx, > } > } > > - if (copy_to_user(response, resp, > - sizeof(*resp) + (i * sizeof(struct ib_path_rec_data)))) > + if (copy_to_user(response, resp, struct_size(resp, path_data, i))) > ret = -EFAULT; > > kfree(resp); > -- > 2.21.0 >