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=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 018C3C282C3 for ; Thu, 24 Jan 2019 03:40:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF18D2184B for ; Thu, 24 Jan 2019 03:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727416AbfAXDk3 (ORCPT ); Wed, 23 Jan 2019 22:40:29 -0500 Received: from ozlabs.org ([203.11.71.1]:38599 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbfAXDkW (ORCPT ); Wed, 23 Jan 2019 22:40:22 -0500 Received: by ozlabs.org (Postfix, from userid 1034) id 43lSbR6CTJz9s55; Thu, 24 Jan 2019 14:40:19 +1100 (AEDT) X-powerpc-patch-notification: thanks X-powerpc-patch-commit: 00def7130af8b3fad1bdef98429c94a67dbbd896 X-Patchwork-Hint: ignore In-Reply-To: <20190108183720.GA14238@embeddedor> To: "Gustavo A. R. Silva" , Jeremy Kerr , Arnd Bergmann , Benjamin Herrenschmidt , Paul Mackerras From: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: Re: powerpc/spufs: use struct_size() in kmalloc() Message-Id: <43lSbR6CTJz9s55@ozlabs.org> Date: Thu, 24 Jan 2019 14:40:19 +1100 (AEDT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2019-01-08 at 18:37:20 UTC, "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 = kmalloc(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 = kmalloc(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 powerpc next, thanks. https://git.kernel.org/powerpc/c/00def7130af8b3fad1bdef98429c94a6 cheers