Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1218224ybt; Sat, 20 Jun 2020 04:31:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy4Xny6bcuLtHdLlntIjlVmmrJ1gQujdMuh0LGLoiew/2Rt9z79SQbnOR8+dU+3ZNVVqZ6 X-Received: by 2002:a17:906:c10f:: with SMTP id do15mr7987461ejc.249.1592652700353; Sat, 20 Jun 2020 04:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592652700; cv=none; d=google.com; s=arc-20160816; b=JjVR5hr/WRVkiB1lyIo5okKL71lGlTjWGgb6xysVHqXr+0rKnqmytuEpmyKyGpOR9p hqSwsihyB5yXxSyG0Pxe1NTJod+03M5dJZ+YWkWGlyiskgsG7D8qq0EQThYnZEmLaB7L /N/Pj4vzYF+xYZvtS6pIrYcQVAROTNPrvecYOCV6095HoVn6plPM8CVVheEK9bqnxYjt wEB1KEO6BnpPjlvT4JUVr8Yw/z695bZF/1ykWpnWPJ/y8cvsF2VyIiOwIEDzZBmM2GTb 735a11noSM4SWuJXYH8xrjCIhEuY+aYN1+HIyqahumhUXoG2hqjZ2VcbwEx6/aB7+DVa GUvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=uXzFmHudKdglG1zHBLoxrnUEcsKBHsD7RzM/cdoypGE=; b=toOByk7xWBYg/oh8ffmT6Me0YRd5qtkG3Xfw3VOzE99VNT9gsmVxIfe5bzKvSUtfwO bu8AkFt1Wxm5xUEND2gc2EJP1vWxSFhXUFjV24IAzuRYuPf2hkt9X5Gwzlvjq86SzI2T Q4afa5YjXvb4aiif9UveEXRrOod+ikF3DFkt7moR2guecp8M8yrll/1dWtuUXh0k5tvI D6k8MxP9hk/3NmEOpPb76GrsYF9uh5hlTN5uxnCkr8ZtxPXfCWufo88Bx8zmz9VhCcZX leSUz0/WYS/KzXG3czp/ft5CIH9Bq15Ho6GFh86QWXHT1bGdSZqe7HVPrEGsfygdY+Rb +5Mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i1si5056703ejr.634.2020.06.20.04.31.18; Sat, 20 Jun 2020 04:31:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728072AbgFTL1Y (ORCPT + 99 others); Sat, 20 Jun 2020 07:27:24 -0400 Received: from asavdk3.altibox.net ([109.247.116.14]:50632 "EHLO asavdk3.altibox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728035AbgFTL1X (ORCPT ); Sat, 20 Jun 2020 07:27:23 -0400 Received: from ravnborg.org (unknown [188.228.123.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by asavdk3.altibox.net (Postfix) with ESMTPS id B4AC220020; Sat, 20 Jun 2020 13:27:20 +0200 (CEST) Date: Sat, 20 Jun 2020 13:27:19 +0200 From: Sam Ravnborg To: "Gustavo A. R. Silva" Cc: Bartlomiej Zolnierkiewicz , linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Gustavo A. R. Silva" Subject: Re: [PATCH][next] fbdev/fb.h: Use struct_size() helper in kzalloc() Message-ID: <20200620112719.GC16901@ravnborg.org> References: <20200617175647.GA26370@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200617175647.GA26370@embeddedor> X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=edQTgYMH c=1 sm=1 tr=0 a=S6zTFyMACwkrwXSdXUNehg==:117 a=S6zTFyMACwkrwXSdXUNehg==:17 a=kj9zAlcOel0A:10 a=VwQbUJbxAAAA:8 a=e5mUnYsNAAAA:8 a=eQAgsu64IDNOz3FtGqwA:9 a=KgSf4rBJBTyy23aL:21 a=eSvgJIpcUDpWB52b:21 a=CjuIK1q_8ugA:10 a=AjGcO6oz07-iQ99wixmX:22 a=Vxmtnl_E_bksehYqCbjh:22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Gustavo. On Wed, Jun 17, 2020 at 12:56:47PM -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. > > This code was detected with the help of Coccinelle and, audited and > fixed manually. > > Signed-off-by: Gustavo A. R. Silva struct_size is defined in overflow.h - which is not included by fs.h. So we rely on overflow.h being pulled in by some other header - maybe slab.h in this case. Seems fragile, should this patch add an include of overflow.h? Sam > --- > include/linux/fb.h | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/include/linux/fb.h b/include/linux/fb.h > index 3b4b2f0c6994..2b530e6d86e4 100644 > --- a/include/linux/fb.h > +++ b/include/linux/fb.h > @@ -506,8 +506,9 @@ struct fb_info { > }; > > static inline struct apertures_struct *alloc_apertures(unsigned int max_num) { > - struct apertures_struct *a = kzalloc(sizeof(struct apertures_struct) > - + max_num * sizeof(struct aperture), GFP_KERNEL); > + struct apertures_struct *a; > + > + a = kzalloc(struct_size(a, ranges, max_num), GFP_KERNEL); > if (!a) > return NULL; > a->count = max_num; > -- > 2.27.0 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel