From patchwork Wed Jun 17 17:56:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 11610345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C310892A for ; Wed, 17 Jun 2020 17:51:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F28E21556 for ; Wed, 17 Jun 2020 17:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592416289; bh=U94GeFraD01aVQEM8vl0Oh3vdf1LW+6sHme4vUAVTcs=; h=Date:From:To:Cc:Subject:List-ID:From; b=bPFYwL3vdv5/dQ69Qk/TBnWbhPkUUvxvMXylmlyURs5gURr0ERVEmMYHQygnsxb3i JF+vSe5l6QFmcUY4QPJ7b8git90YIUQEGiX4UKxd5yYj8VUdY+Qzo9TCSPLoHMTy6Q m2bMK1cxJ/xqeGsRiQmys+j2f3nWPZSDzObja8VM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726496AbgFQRv2 (ORCPT ); Wed, 17 Jun 2020 13:51:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:37388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726594AbgFQRv2 (ORCPT ); Wed, 17 Jun 2020 13:51:28 -0400 Received: from embeddedor (unknown [189.207.59.248]) (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 6562421527; Wed, 17 Jun 2020 17:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592416287; bh=U94GeFraD01aVQEM8vl0Oh3vdf1LW+6sHme4vUAVTcs=; h=Date:From:To:Cc:Subject:From; b=HgiE+iQsxkKj1piB7LAgU1JiiOlZZ49+RlrRCXfbLUMEwSBpXPuZRtHNKTgCfLq3k xLikeI01z5XBmS4nX02fm0hjslVKjpOWS8xFwuiLE7tr/UXhSC+DtI6QZN4f3+MmH+ mmuivD/x1ZkhF5iR0tCF+LK8sp+V/LjFmh8o6U5o= Date: Wed, 17 Jun 2020 12:56:47 -0500 From: "Gustavo A. R. Silva" To: Bartlomiej Zolnierkiewicz Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] fbdev/fb.h: Use struct_size() helper in kzalloc() Message-ID: <20200617175647.GA26370@embeddedor> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org 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 --- 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;