Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp623897imu; Fri, 11 Jan 2019 06:22:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN6twCx/8d8yKzkQ9IvyhcYBVYiZWZRx1wFypbwQieo1H1CBJ/To6CcMqPPnXipdd13ACHUF X-Received: by 2002:a63:e84c:: with SMTP id a12mr11260943pgk.241.1547216576628; Fri, 11 Jan 2019 06:22:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547216576; cv=none; d=google.com; s=arc-20160816; b=KziBpIV1MiZNrS58bwrsoK7+70vratj93RHcKXbhHnUFT/+i9OBMnhBLHW//crG8FX jTFnUkZTckhNlnADyYO1FW1l3ViAkPGNOc2HmHuWnGMhy0UTKUGh7yQjPIJwCbAKBgBP DJRiQj+jl2IylVed5z4yx14ldG9MtedFdneo9i1QEFj3OqFfnYpH7rLTKc2puIJiIqI2 QVhBOdgOtBVYft1kzYkDCmlxsocEssG7+F3L4iHSSFk7HnaH8VUbh1NBOICobALvF75T OqYQDfskiY8J6j56Bq8oeCLZfaCAdcjm4qcD4Mdc13+EYuP0/K8QWLNJ0hiwo+je1BtM hCMQ== 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:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=nE8Mto4xbZ7AO2X7x2z9Sl3MGX8gvtJ206MvO74t3YU=; b=JzaR6gMGf3iNmj2oIeI2/PZlHNXKqWAvWFreDklRRwR3HGYSSR7FOZ8HUR2TEa9LMJ vH2RiVdYeECrqdOgH5F6wXVj/8q4WoG+oQi565g9287A0Qi0XKQVNO0QGso65uE0eEeV IiPcs1fH3Yffp4DZGznTvwTfBY0fwY3no8mNwcXljxBTbwRy0EJ4Ub21fSXxQORyPPeF 5RqlJPOYxS8uXVhEOEVtZTuFKxwZsGw3DMWA+1dRJPCfVAsDSsKvLSY58DGc6sJQaIah Dm2/Yn35PGlQkgcjeZe4gAN4fpnvJxGFJwkcnfNxvZGg00BF+PXUeB6z40XYP7nhzSZB q+4A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s5si4196645pgl.481.2019.01.11.06.22.41; Fri, 11 Jan 2019 06:22:56 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732923AbfAKNxr (ORCPT + 99 others); Fri, 11 Jan 2019 08:53:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42990 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729744AbfAKNxq (ORCPT ); Fri, 11 Jan 2019 08:53:46 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF6241F56A; Fri, 11 Jan 2019 13:53:46 +0000 (UTC) Received: from flask (unknown [10.40.205.161]) by smtp.corp.redhat.com (Postfix) with SMTP id 8B1CF60BF6; Fri, 11 Jan 2019 13:53:44 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Fri, 11 Jan 2019 14:53:43 +0100 Date: Fri, 11 Jan 2019 14:53:43 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: "Gustavo A. R. Silva" Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kvm: Use struct_size() in kmalloc() Message-ID: <20190111135342.GH14852@flask> References: <20190104162910.GA25118@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190104162910.GA25118@embeddedor> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 11 Jan 2019 13:53:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2019-01-04 10:29-0600, Gustavo A. R. Silva: > 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 > --- Queued, thanks.