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=-5.5 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_MUTT 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 3AAB2C282CB for ; Fri, 8 Feb 2019 07:15:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 096AD2147C for ; Fri, 8 Feb 2019 07:15:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="Uj+REvV9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727178AbfBHHP2 (ORCPT ); Fri, 8 Feb 2019 02:15:28 -0500 Received: from mail-wr1-f45.google.com ([209.85.221.45]:45805 "EHLO mail-wr1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726004AbfBHHP2 (ORCPT ); Fri, 8 Feb 2019 02:15:28 -0500 Received: by mail-wr1-f45.google.com with SMTP id q15so2359468wro.12 for ; Thu, 07 Feb 2019 23:15:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=X0L4g3VUuayFs/6/ha69STEWrslF9n1Poh3M7az5XkM=; b=Uj+REvV9Y234NA//xQL2cORScAXgdV/YXcqF/M/ulxfHSGvKhQC/l/uvHu/uRV1z8A Af5NPD1Hk816Hrq2jcKil71bR4rwuUMjUn30QZQu9QpV6UbiD153jpdAfQWJSUS0Eo+y ErB9kfV2vT3rX/GINSKA+gt3dlum9HPcn7HQwuny3EnyK5+jhmwVoMThu8hcuCJSCnHb m6cnV+LsYRJ47wZIWxXcqexBLFWgRrddfcVdGHlE8Byr2e5el0xOfoZf8uwBKooQ5VXn ew2J8sVQwzjW+XA9+aWy59jXDT1BHWoBxbdArjCeaFA7wrG3J8RDkXkaAICkafvVc+Ac Mtlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=X0L4g3VUuayFs/6/ha69STEWrslF9n1Poh3M7az5XkM=; b=QHpLFFix4sh1tbkqGhLh5JWyFxKmDqMbOC204ARUTvkuquSriqIrVyPcj3tioN8q+K 8aB+vk2V0yC0SMJsZ0rzrVJPGOnyb80AEl6O5UmK84svqDcBhDuhnhU3SN0igFa7bjXl n1Yx1sLnNWdinJ7TwdIeFsqGXukaoj2p523Qnhr5RLZBa+8YSK7PensSsJKy1CdQdZW6 B8QYIyqEAZ/ztAiMqwvySCXr4QqtMcKTdb+GtJD6fO3ZKt0qPbAnpKQUj4sNY5cL8evY Pt4L7udRNTm/nGd+Jz42qeA3ROcpwH0tJjsEJtHlJAFOMdtsvj6XRGmlkHq/y1DWy+JU QArw== X-Gm-Message-State: AHQUAuZulxKRlUFObAVGU5pt6qZ8z/rRjghTmFCPH2IGcV51QMtlCuD3 FBMPV4Ukx0tTHQKPhEmluGzgLA== X-Google-Smtp-Source: AHgI3IZCjGKj4VarqeqX8xUf6q9OJ6oKxJTmlEaY7MkcO8i1nOMcA0/1U6/U237+frvaXXXgloHIPg== X-Received: by 2002:a5d:4349:: with SMTP id u9mr15906539wrr.223.1549610126089; Thu, 07 Feb 2019 23:15:26 -0800 (PST) Received: from localhost (ip-94-113-219-55.net.upcbroadband.cz. [94.113.219.55]) by smtp.gmail.com with ESMTPSA id r12sm1740662wrt.76.2019.02.07.23.15.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Feb 2019 23:15:25 -0800 (PST) Date: Fri, 8 Feb 2019 08:06:12 +0100 From: Jiri Pirko To: "Gustavo A. R. Silva" Cc: Jiri Pirko , Ido Schimmel , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] mlxsw: spectrum_router: Use struct_size() in kzalloc() Message-ID: <20190208070612.GB2353@nanopsycho> References: <20190208034241.GA11858@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190208034241.GA11858@embeddedor> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Fri, Feb 08, 2019 at 04:42:41AM CET, gustavo@embeddedor.com 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; > struct boo entry[]; >}; > >size = sizeof(struct foo) + count * sizeof(struct boo); >instance = kzalloc(size, 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) > >Notice that, in this case, variable alloc_size is not necessary, hence >it is removed. > >This code was detected with the help of Coccinelle. > >Signed-off-by: Gustavo A. R. Silva Acked-by: Jiri Pirko