Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp973935imu; Wed, 16 Jan 2019 10:30:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN7J3Tr+UF/GVWzDEQqAqk5X0Lz/Tkzrx/sK9SdAKysaXahrza86JzT0LfhKUVEJmqwr6Z0k X-Received: by 2002:a17:902:f20d:: with SMTP id gn13mr10924172plb.11.1547663438308; Wed, 16 Jan 2019 10:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547663438; cv=none; d=google.com; s=arc-20160816; b=PKuHIyw8c8qnKilXVTxUcvPXbOzGZ1vQ2fvxDbr3ThZmKrqoxYrfje7loOdJzJUXf6 Zs/oI7UyOpMLXwFO4MHOdbscFLcFiSgALfKco8UOpJKJ9bR/tJZ+tDK+S9A6C2h+w9kw 2g7DuenmyHEwTMfNxQUpWX/lEgUsKFUC/ODTV/Sxq0KkyTz9v8UMQzHUmiFaiD5Ktcha nS4r/okXFXjmH9f0XK1aSmHBXSpUthoTpC5Tl+NdJw1SE3p8CD2nKrURHxEwxXDhSYBj kWZ5XECUOSBWWRmmtDLB4XejELJfMtExV+/oNIYIrWnj3fnBnI1PyTdjr/tKitdTVKvC gkSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XVchoDy75cvBXzLr9Z+aOYv9+E/m3yCoBAi2GO9lQX0=; b=nHENZIEn4MXk5vdvBieHVFhh79Glol73Q4FmDh8QvOrx1qy/IcN0UFd2C2CMl6F/9P BzrcxUe6VHNqnGBhEFCYvaUMeQLYDF7kovj53MrbBvMir/oCE3qIcL3IFmX5h3X55ET3 xmeabSqwXiXfZuC5XPB8umJKhd3dd6waluiyamF7yMEu87MvVvFgf3Ql/n31LE7cIMi7 +rlgCN+Hpzwuc3WhS5kYDGmRe2hmR7bEFecsbOL2cVAEXkWHsCX2eoDnDMplgehuFYyp +Vn5cqat/5XSwVLI+zjhaVZQbru9a9ll6LX5CMhRu0+7id2iAYbFMwJac1RHP+Rmlr47 Dgyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kxtq3FD8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si7001212pgn.243.2019.01.16.10.30.18; Wed, 16 Jan 2019 10:30:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kxtq3FD8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389282AbfAPIlB (ORCPT + 99 others); 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