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 51DBDC282C4 for ; Tue, 22 Jan 2019 10:57:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F0F420879 for ; Tue, 22 Jan 2019 10:57:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727845AbfAVK5C (ORCPT ); Tue, 22 Jan 2019 05:57:02 -0500 Received: from mga03.intel.com ([134.134.136.65]:63161 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727199AbfAVK5B (ORCPT ); Tue, 22 Jan 2019 05:57:01 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2019 02:57:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,505,1539673200"; d="scan'208";a="313763808" Received: from cmicsa-mobl1.ti.intel.com ([10.252.18.12]) by fmsmga005.fm.intel.com with ESMTP; 22 Jan 2019 02:56:58 -0800 Message-ID: Subject: Re: [PATCH] iwlwifi: nvm-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:56:57 +0200 In-Reply-To: <20190108175519.GA8878@embeddedor> References: <20190108175519.GA8878@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:55 -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 > --- Thanks! I applied this to our internal tree and it will reach the mainline following our normal upstreaming process. -- Cheers, Luca.