Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2863520imu; Sun, 6 Jan 2019 11:54:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN600w+6s06PGEfHMc2sBOjifueQwIfa2/pS7U/8fEyzdEC8jRoXMrDZQZX1efBd6sYSLZpV X-Received: by 2002:a63:3e05:: with SMTP id l5mr8040758pga.96.1546804480501; Sun, 06 Jan 2019 11:54:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546804480; cv=none; d=google.com; s=arc-20160816; b=ND2OLkmcHhBhre6WT4w7sBIayotanmpmPjZg4zM0g2V8kysu812+Z8c+BtHAhCy/lw SU6O/y5Viw843E9t1f3CYKOdF97QdcZLHzF3IytVFnrKfpXqTSVa6XzFv+/Y1J1jrTcO H/czMcdDtucvpgi/aYFAW4L/h+hNdXWc+P3JGrkEPmfljMELc8FrudeNyFIhG7C67N7H J2CeIXdzfssdqL4NztKSGeD/4W3vp1EUnbRiTYksb+Z2VO836UrtTM2cRM+20di7xP7C IM/Um+g7wjxZPcKkERYKKjgPeRorGHdCH/J0QgXlcrVk0FoQzlzJ8uo+F/Sy6c5Yv4X6 Z3tw== 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; bh=9qpKOvre6zefCHyYdWLt2MxC0DcEv9p8s+PKhc6/vbM=; b=ELnMVq/EVvKZ7barqYT5EUpABNn9T3Yo2UXj7ryiT2ni1DqrcLntzz7NDx4NPKdI9E UbzbcUhVypASdoG+hDy7xB6iMjoieZ0l5PT6ERxvQzy/9Fy+mp5+QOrxpTK9bw0nZvga lAmyKrKEDzb2cwTv6uFlIrg2oO034jAVnJlcCG0kDjyrss5gigVPLRCqZxocGjpvvUGW IfHC3RSCkh8teoZIyAbFmDBDN/7EKU1NqS+3JZZgJqDTV6icOPJEIPiNePF8Kjgz1HfS yLeXRovJaAB6OmLJ04uoalZcBZr3dNGMEoGS41Z5pJX68PxLAYie32RgLE1us39GJ3cB VI7w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n184si62002185pgn.95.2019.01.06.11.54.12; Sun, 06 Jan 2019 11:54:40 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726090AbfAFTu4 (ORCPT + 99 others); Sun, 6 Jan 2019 14:50:56 -0500 Received: from ec2-18-194-220-216.eu-central-1.compute.amazonaws.com ([18.194.220.216]:53986 "EHLO sysam.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726045AbfAFTu4 (ORCPT ); Sun, 6 Jan 2019 14:50:56 -0500 X-Greylist: delayed 592 seconds by postgrey-1.27 at vger.kernel.org; Sun, 06 Jan 2019 14:50:55 EST Received: from localhost (localhost [127.0.0.1]) by sysam.it (Postfix) with ESMTP id 2EF8521AB3; Sun, 6 Jan 2019 19:41:02 +0000 (UTC) Received: from sysam.it ([127.0.0.1]) by localhost (sysam.it [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h9d8cN4EJ3SV; Sun, 6 Jan 2019 19:41:00 +0000 (UTC) Received: from jerusalem (host15-234-dynamic.4-87-r.retail.telecomitalia.it [87.4.234.15]) by sysam.it (Postfix) with ESMTPSA id 6CB6921AA3; Sun, 6 Jan 2019 19:41:00 +0000 (UTC) Date: Sun, 6 Jan 2019 20:40:59 +0100 From: Angelo Dureghello To: "Gustavo A. R. Silva" Cc: Dan Williams , Vinod Koul , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] dmaengine: fsl-edma: use struct_size() in kzalloc() Message-ID: <20190106194059.GA2120@jerusalem> References: <20190104212545.GA16927@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190104212545.GA16927@embeddedor> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 04, 2019 at 03:25:45PM -0600, 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: > > struct foo { > int stuff; > void *entry[]; > }; > > instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL); > > Instead of leaving these open-coded and prone to type mistakes, we can now > use the new struct_size() helper: > > instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL); > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva > --- > drivers/dma/fsl-edma-common.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c > index 8876c4c1bb2c..fe529100674f 100644 > --- a/drivers/dma/fsl-edma-common.c > +++ b/drivers/dma/fsl-edma-common.c > @@ -339,9 +339,7 @@ static struct fsl_edma_desc *fsl_edma_alloc_desc(struct fsl_edma_chan *fsl_chan, > struct fsl_edma_desc *fsl_desc; > int i; > > - fsl_desc = kzalloc(sizeof(*fsl_desc) + > - sizeof(struct fsl_edma_sw_tcd) * > - sg_len, GFP_NOWAIT); > + fsl_desc = kzalloc(struct_size(fsl_desc, tcd, sg_len), GFP_NOWAIT); > if (!fsl_desc) > return NULL; > Tested-by: Angelo Dureghello > -- > 2.20.1 >