Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp992441imu; Fri, 11 Jan 2019 12:53:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN6rNl5MeGlcJDuWi/zmyA1HJmdpuGHTnum7DOqOaUOqCc8OFicbgTyb3/I+czgUAwlzbk+b X-Received: by 2002:a17:902:bd4a:: with SMTP id b10mr16221670plx.232.1547239995443; Fri, 11 Jan 2019 12:53:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547239995; cv=none; d=google.com; s=arc-20160816; b=bA/YmDNYd1p1cIMFiqvX5Y1jqNV6BHBsAgoJ+F1ZJ6V0tAmpNlHQkEiQ0/8Obx6Soj kIMcxUCgJXTVe0bKaeBUCyOO4ZIj2Ua1qM7Y5K1ffXbGc/gvTcJcGoS7sm1Gy3Ja0pEt 50cslayLLd2pCLXAESFO1oS8LNE/58aXWqj2ZAA0DlFKIfDYd51UFJ6NQblCCsOkgGA7 QMLlccQmkfK8uE7QjXoONQMxQ+VzdBNAjc2LxgQiGRbSzBA6CUyKojclXqIfbIhIPL49 y14z0k4nSg3gxrpPsnXs5FeBAQ6utmKVBXTLKk2oMWsR5IAlzauDihvFAJAwsIBtOnFL HoHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject; bh=DkZPd4HbQ5I8bk5ic/OQe7MScBC3EeMwqDn8xTbHFlw=; b=QW+9IXmbA3BkbZ+CGP4ubNdvo1uVo4ghfOtHxVsyBEex85k58IPzq8CZuy7QxN8GVA A2TOmZXq710fWJQ4jInq6v7MPzFpggmAZqjHmtHHZ9tLtKi5/80x2j7JrKFpDTmRKMCX MxroaROqcrJ2yL/GdMhbZcrGCAO70kkkR37ssK8/fI1h+vcZSOGhaVpKedm2psWAseLf EvjiCvyiSczcBfurBt+T3GhZvI9B92gLqB/SMilU+YilsLDKY5DiS/o23jpm+0d3HjG5 /QHEetDzbrJSMxfo9nMiu07LkeAwWZY1yD4zCzQv1tbch3xCrGDGmwx4z7z/ZBKcDJB5 xsxg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2si3849312plt.93.2019.01.11.12.53.00; Fri, 11 Jan 2019 12:53:15 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388119AbfAKQly (ORCPT + 99 others); Fri, 11 Jan 2019 11:41:54 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40522 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731998AbfAKQlx (ORCPT ); Fri, 11 Jan 2019 11:41:53 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id x0BGY4Gc041266 for ; Fri, 11 Jan 2019 11:41:51 -0500 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0b-001b2d01.pphosted.com with ESMTP id 2pxw27xkyk-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 11 Jan 2019 11:41:51 -0500 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 11 Jan 2019 16:41:50 -0000 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 11 Jan 2019 16:41:47 -0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x0BGfk4419726434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 11 Jan 2019 16:41:46 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 403C57805C; Fri, 11 Jan 2019 16:41:46 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A424478063; Fri, 11 Jan 2019 16:41:44 +0000 (GMT) Received: from [153.66.254.194] (unknown [9.85.186.19]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 11 Jan 2019 16:41:44 +0000 (GMT) Subject: Re: [PATCH] scsi: advansys: use struct_size() in kzalloc() From: James Bottomley To: Hannes Reinecke , "Gustavo A. R. Silva" , Matthew Wilcox , Hannes Reinecke , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 11 Jan 2019 08:41:43 -0800 In-Reply-To: <05420a5c-c268-b87d-9d75-f5d18a4b7f7a@suse.de> References: <20190104212209.GA15250@embeddedor> <05420a5c-c268-b87d-9d75-f5d18a4b7f7a@suse.de> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 19011116-0004-0000-0000-000014D15FB0 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010385; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000274; SDB=6.01144996; UDB=6.00596224; IPR=6.00925266; MB=3.00025086; MTD=3.00000008; XFM=3.00000015; UTC=2019-01-11 16:41:49 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19011116-0005-0000-0000-00008A2F4732 Message-Id: <1547224903.2793.10.camel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-01-11_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901110136 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-01-11 at 16:46 +0100, Hannes Reinecke wrote: > On 1/4/19 10:22 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: > > > > 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/scsi/advansys.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c > > index d37584403c33..6c274e6e1c33 100644 > > --- a/drivers/scsi/advansys.c > > +++ b/drivers/scsi/advansys.c > > @@ -7576,8 +7576,8 @@ static int asc_build_req(struct asc_board > > *boardp, struct scsi_cmnd *scp, > > return ASC_ERROR; > > } > > > > - asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) > > + > > - use_sg * sizeof(struct asc_sg_list), > > GFP_ATOMIC); > > + asc_sg_head = kzalloc(struct_size(asc_sg_head, > > sg_list, use_sg), > > + GFP_ATOMIC); > > if (!asc_sg_head) { > > scsi_dma_unmap(scp); > > scp->result = HOST_BYTE(DID_SOFT_ERROR); > > > > If you want ... Are we sure there's a benefit to this? It's obvious that the current code is correct but no-one's likely to test the new code for quite some time, so changing the code introduces risk. What's the benefit of making the change in legacy drivers? Just because we have a new, shiny macro doesn't mean we have to force its use everywhere. I would recommend we have a rational needs test: so run the coccinelle script over all the drivers to find out where this construct is used, but only update those that are actually buggy with the new macro. James