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=-12.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 6E5FEC43387 for ; Wed, 16 Jan 2019 08:41:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BB8D20859 for ; Wed, 16 Jan 2019 08:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547628063; bh=ZKnzUtIu6HSCQMGOj5zuOt2WoTBGvpo03n+L8Lxke+I=; h=From:To:Cc:Subject:Date:In-Reply-To:List-ID:From; b=N3lk9v1NtHGd5dCxqbMtGE4Kb69OT0SSggt/WMKf2yrCpwkBnSWtLi0ryQLL2d1lV 8SknhL6T34hCezFdHmKyNl5GRQ1T4KnAY/Vqy1O5rqFddxlKRxWaNyP6EuLK5bcohr mJ/8j6qlQgvjkG7EK+Kg3Mv/u+KIkMx+dNUlO6q0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389299AbfAPIlB (ORCPT ); Wed, 16 Jan 2019 03:41:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:34902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388686AbfAPIlB (ORCPT ); Wed, 16 Jan 2019 03:41:01 -0500 Received: from localhost.localdomain (91-160-177-164.subs.proxad.net [91.160.177.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 55B792082F; Wed, 16 Jan 2019 08:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547628060; bh=ZKnzUtIu6HSCQMGOj5zuOt2WoTBGvpo03n+L8Lxke+I=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=kxtq3FD8iifDxanMz3BzD0C7YMIOH4SqwTzXJ+UznilHU8lNozeAez32gSUENRp7K 8pTc4C2ydySw2T41tY2mBnDsF9o7Xiwczr2WtfRWc0RhXu79lM4WTqtRFcpUPAJLDB SjQGUuJ8ugK+UgzvNl5UjP1lU/jWy4qIH7pscWqY= From: Boris Brezillon To: "Gustavo A. R. Silva" , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger Cc: Boris Brezillon , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: mtd: gen_probe: Use struct_size() in kmalloc() Date: Wed, 16 Jan 2019 09:40:53 +0100 Message-Id: <20190116084053.29791-1-bbrezillon@kernel.org> X-Mailer: git-send-email 2.17.1 X-linux-mtd-patch-notification: thanks X-linux-mtd-patch-commit: 9cb76a6aa1a9524866ec1558f08d044506b707fa In-Reply-To: <20190108153601.GA11557@embeddedor> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boris Brezillon On Tue, 2019-01-08 at 15:36:01 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 http://git.infradead.org/linux-mtd.git mtd/next, thanks. Boris