Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 828DCC43387 for ; Tue, 15 Jan 2019 21:49:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48B912086D for ; Tue, 15 Jan 2019 21:49:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="fhuRoVoN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730798AbfAOVtu (ORCPT ); Tue, 15 Jan 2019 16:49:50 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:60110 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728421AbfAOVtu (ORCPT ); Tue, 15 Jan 2019 16:49:50 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0FLhbpp085677; Tue, 15 Jan 2019 21:49:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=content-type : mime-version : subject : from : in-reply-to : date : cc : content-transfer-encoding : message-id : references : to; s=corp-2018-07-02; bh=So4aQpKxn5AcekOBF97kodu8T+sAUHZ32duZfNiBY5o=; b=fhuRoVoNXgU1/atTfMZJM9IdmPCIhnwoW23MofQodCqzITJAXZZFy8t2/p9aSqcDeXKK eseD+F9BiFgjLUzp7onBegbQsLZoxgdJpmP5ECK15uKQw/ebDK25Tk9Glc/EG0sgFZcU LTxYpaarmnnkGwxf6tXBw25u/LU/sIfhwx/+7n5iyThHkS04lxXz0hgrQMSwaYbKIU4b E7ss2T4gHxHbaTk7eJWxR0DCfbqIiNDEFkDFX03MS1cIH80nlUQAFEqnfzXMwLPyI1Nz 5MNiA5v4D82qzPWJVrxpZIXQnUC95GqxGv9DEMm5zVZjF/+lbbDcNnA7wB+LX8sKCCRJ 7w== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2pybkcefvj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Jan 2019 21:49:28 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0FLnMou024365 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Jan 2019 21:49:22 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0FLnJxl027679; Tue, 15 Jan 2019 21:49:19 GMT Received: from anon-dhcp-171.1015granger.net (/68.61.232.219) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 15 Jan 2019 13:49:19 -0800 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: [PATCH net-next] svcrdma: Use struct_size() in kmalloc() From: Chuck Lever In-Reply-To: <20190115211140.GA16131@embeddedor> Date: Tue, 15 Jan 2019 16:49:16 -0500 Cc: Trond Myklebust , Anna Schumaker , Bruce Fields , Jeff Layton , "David S. Miller" , Linux NFS Mailing List , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190115211140.GA16131@embeddedor> To: "Gustavo A. R. Silva" X-Mailer: Apple Mail (2.3445.9.1) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9137 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1901150173 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Jan 15, 2019, at 4:11 PM, Gustavo A. R. Silva = wrote: > One of the more common cases of allocation size calculations is = finding > the size of a structure that has a zero-sized array at the end, along > with memory for some number of elements for that array. For example: >=20 > struct foo { > int stuff; > struct boo entry[]; > }; >=20 > instance =3D kmalloc(sizeof(struct foo) + count * sizeof(struct boo), = GFP_KERNEL); >=20 > Instead of leaving these open-coded and prone to type mistakes, we can > now use the new struct_size() helper: >=20 > instance =3D kmalloc(struct_size(instance, entry, count), GFP_KERNEL); >=20 > This code was detected with the help of Coccinelle. >=20 > Signed-off-by: Gustavo A. R. Silva Reviewed-by: Chuck Lever > --- > net/sunrpc/xprtrdma/svc_rdma_rw.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) >=20 > diff --git a/net/sunrpc/xprtrdma/svc_rdma_rw.c = b/net/sunrpc/xprtrdma/svc_rdma_rw.c > index dc1951759a8e..cad37c2122ab 100644 > --- a/net/sunrpc/xprtrdma/svc_rdma_rw.c > +++ b/net/sunrpc/xprtrdma/svc_rdma_rw.c > @@ -64,8 +64,7 @@ svc_rdma_get_rw_ctxt(struct svcxprt_rdma *rdma, = unsigned int sges) > spin_unlock(&rdma->sc_rw_ctxt_lock); > } else { > spin_unlock(&rdma->sc_rw_ctxt_lock); > - ctxt =3D kmalloc(sizeof(*ctxt) + > - SG_CHUNK_SIZE * sizeof(struct = scatterlist), > + ctxt =3D kmalloc(struct_size(ctxt, rw_first_sgl, = SG_CHUNK_SIZE), > GFP_KERNEL); > if (!ctxt) > goto out; > --=20 > 2.20.1 -- Chuck Lever