From mboxrd@z Thu Jan 1 00:00:00 1970 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=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 5644AC282C4 for ; Tue, 22 Jan 2019 10:58:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2241321019 for ; Tue, 22 Jan 2019 10:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728068AbfAVK6K (ORCPT ); Tue, 22 Jan 2019 05:58:10 -0500 Received: from mga18.intel.com ([134.134.136.126]:14773 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726095AbfAVK6J (ORCPT ); Tue, 22 Jan 2019 05:58:09 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2019 02:58:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,505,1539673200"; d="scan'208";a="136681057" Received: from cmicsa-mobl1.ti.intel.com ([10.252.18.12]) by fmsmga002.fm.intel.com with ESMTP; 22 Jan 2019 02:58:06 -0800 Message-ID: Subject: Re: [PATCH] iwlwifi: eeprom-parse: use struct_size() in kzalloc() From: Luciano Coelho To: "Gustavo A. R. Silva" , Johannes Berg , Emmanuel Grumbach , Intel Linux Wireless , Kalle Valo , "David S. Miller" Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 22 Jan 2019 12:58:06 +0200 In-Reply-To: <20190108171738.GA32297@embeddedor> References: <20190108171738.GA32297@embeddedor> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.3-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, 2019-01-08 at 11:17 -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 > --- Applied to our internal tree, thanks! It will reach the mainline following our normal upstreaming process. -- Luca.