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 511C7C4360F for ; Tue, 26 Feb 2019 09:04:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E31B213A2 for ; Tue, 26 Feb 2019 09:04:22 +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="fqu0GlMQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727343AbfBZJES (ORCPT ); Tue, 26 Feb 2019 04:04:18 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52728 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726240AbfBZJES (ORCPT ); Tue, 26 Feb 2019 04:04:18 -0500 Received: by mail-wm1-f67.google.com with SMTP id m1so1567277wml.2 for ; Tue, 26 Feb 2019 01:04:17 -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=pgopdYdTTPUq7eXB2PZD/NhiRK6Z81r5jUjaaQ5mpdg=; b=fqu0GlMQl/JJ59Zn4rRd6PbgCso4/MMd8XK21j3MfijS+3q5sTBEFdATmL/dQKZblY JtMisvj35DiVtnuh4ZZstdnU06P6UNS7viqwtrKIaSJK8IbtJ4OWIH2xj7rNItfkysEf oale4R1/+hySE5UjKbOaKfHJsXrtwp6b1CJve1JxpZUtKCsDNqa+uiP901k39cQkByAw qdC5csbtKaNiYNt4Ps7MeATFFur8bLTi8H3k2fXGIQAchWM1AuUwLsb8oPELviENBFCB AzvUsM0FDtqa+sHs8f3RaFfVfC0ywbPgwn+o1sq3/Il0jtYhbMk3xZtFExxB5cyZ7p7U yHpQ== 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=pgopdYdTTPUq7eXB2PZD/NhiRK6Z81r5jUjaaQ5mpdg=; b=c79ZkFzwJChQCtDUlq858AYpNASzi/OUYJm6QETYHG/9LrAId223ae7sAmbHEAQZ8M TJERNF+0dUMjHdl/uRBfEFOXwKiMaSAb0nUZsQrJ1wU8IYvUZvw1qlQnYpxpbbOlg66I 6xzC5CmP6ZxHG+xqR0XiSI3DNTDqepByaEI7Lq8oNTV887sSMoLMn9DThpKnD1gmDFCz SijLpzY1ENLZBOIQEuW5u5cRZxlcdWc28qhfjh21Lq/RAkFumT7CwCMhZAYyL8WXGFi9 W+sD6IkAtByPt3UO7eQIP6qNXW7abrfuiQhfy7L9M4nf4RlgLsMjzXmZJtFrVq8RHeSf Eu8A== X-Gm-Message-State: AHQUAub88UYCpVSsi/CTYnKatFELww6q6X1vhW+zdjC5KoLK7466kbo7 6rAXQy3ebA0QkFc8dkvEPiXRyg== X-Google-Smtp-Source: AHgI3IZSKvDP+X0tuPQiNM7o2RRSyU1qPXI0nhgRBx/RJSyi6yOcIUBHSe7W4J6Vp22ljEbDpq5udQ== X-Received: by 2002:a1c:30b:: with SMTP id 11mr1864878wmd.110.1551171856408; Tue, 26 Feb 2019 01:04:16 -0800 (PST) Received: from localhost ([2001:718:603:100a:93d:1bfc:765a:ba68]) by smtp.gmail.com with ESMTPSA id d24sm28634176wrb.47.2019.02.26.01.04.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Feb 2019 01:04:16 -0800 (PST) Date: Tue, 26 Feb 2019 09:54:25 +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: acl: Use struct_size() in kzalloc() Message-ID: <20190226085425.GA5451@nanopsycho> References: <20190225190132.GA23478@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190225190132.GA23478@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 Mon, Feb 25, 2019 at 08:01:32PM 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