Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp281745ybi; Sat, 15 Jun 2019 00:46:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqz15FBtklvRBpGpgNGMlt3A/tiXaO5PDrgr8beoZk3u1MXMRDcAgzXuFa/6on6y0PmhtbF0 X-Received: by 2002:a17:902:44f:: with SMTP id 73mr39392457ple.192.1560584790586; Sat, 15 Jun 2019 00:46:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560584790; cv=none; d=google.com; s=arc-20160816; b=dd0ru8Q5rKWKhCyGKBXtwPF0SWsaE0OtaOyW70cvGuLA/cGkeofndU7Xccq2vIdNbx 7MumrdQEgXvufu2GtwsJJrjKb8HndEItRs08GSYHzCBvVVo1ku5LCVLRzZGT/bShwJH5 bfb48KNkeyC21L6n+K9cNfXzRZ1hOGOw8m29wpsPgPOF1MvrD+kmb5DfqPYAWIzLG4x9 XSojmkodK+xBLyFWgKSlYKaRUksxO8ecjX6zYBpfRIMycUfnE/YPyn/j9LbI4Pdvgh1q VY5RfOkvtiCVo3BhrzHeRghlbHgOwYBNmI3qAHu6ZB0yxfZwVNMWwE1E+Vpe+DvoFwaj pvyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=+f+PTJpz5tE7MTiuxw63vEzsq4p7RBPfAvYGoJO4GcM=; b=n3+EL6HV9tu28GtmN1WHz98jD7HoLDLt6b5KOhM0mXRSw3z8bXTg4Gko28u84b8r8k i15569xN3/yFeevywr3ivsqql6lETt3kb9oSvORTwNt0SkWd4NmOrw/zvPXMxs0FoBmQ FPg/UKLFSgvi8EytJ8H4XlFFsFO+f29eMfB8J1kS4a+IQ8ucRvd9VCqdk9QszvU8+J6D nS0t4ttptzwWYOYH4mdtbjp0v8HvwNonVPf0JDlX+ipPI6+xlHrb6Ap0QUOckWk76uhQ dzU50EKBSgj5/oYeCgOUCq6jVn6UuKZt3wV/L1UbNy59lqA4fGhzYLauz4QhKZkU2l3m cv/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=uFMgaOjx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m10si4597559pgl.543.2019.06.15.00.46.15; Sat, 15 Jun 2019 00:46:30 -0700 (PDT) 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-dk.20150623.gappssmtp.com header.s=20150623 header.b=uFMgaOjx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726400AbfFOHps (ORCPT + 99 others); Sat, 15 Jun 2019 03:45:48 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39856 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726236AbfFOHps (ORCPT ); Sat, 15 Jun 2019 03:45:48 -0400 Received: by mail-wr1-f65.google.com with SMTP id x4so4742891wrt.6 for ; Sat, 15 Jun 2019 00:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=+f+PTJpz5tE7MTiuxw63vEzsq4p7RBPfAvYGoJO4GcM=; b=uFMgaOjx6acoGl+OiIjw06ga8uUa2fp2947047IohdtJLKaVKqBgwX53e3Vr0iviCP 1JZkuvbpMiCVmgPwMMAjTXT+8a3i0a2R+CnzPl752NiqC9j0/ZVvv7lEzLouXZXpbQJM d3Z7YDi5s4ZUBeIc8HjYB2EiFmf5VXZTVlas3uvqPsoKSx3ekdi3dJXeYAgJkxL9Sfp/ HPH79uSRVy8xRc6V5gwSXbBvf8zXsrKePZsM5TTfHYDPGcaL5x/7joF1Jcdfv2fndsUa h8rhAuPoFDzcM8JwvAfs7jJ5ylqCXWhRXBnQLMgLlLA9nNyWqLJcmxKmAcx/ttSz4mDf 34IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+f+PTJpz5tE7MTiuxw63vEzsq4p7RBPfAvYGoJO4GcM=; b=JzV2+8BlU0nKxw8MIFIfIAhbhR80N1nsZLHtj2K2/EIaMQAfuLWMWfZBF8qOUwuKJe +ocp2YTFKuZBRiL0+p3Z/RcIsn4X9BY/5VsbyQHBRbu1dULky958zo4nT5EqfdviIzrg NxeqlL2yjo/Ky4Ik6Rb89wWiUvTiODs10IY6eV9DEhppF+V/Thmb0LpDegIbp8Yn2mZ/ 5+BZzAk0mwyJwR5hT7SG45pxsW7W7e+ikAeb6pzrmLUkg5cJ4ybC0QPKhXZJgll3GxgR rXq4FTGBKBZvBtMNilEf6eWO9u8LNJgi7pd5yHCq7RzZPg4gSHx8dEsidbsU8r91BQwW O6jA== X-Gm-Message-State: APjAAAXTnjttg7Bo7oTl9l6wJLkvFR26zYQoNO5xT7+3UqIh+1SgedX+ zna451LCOC/WRY3Elif6Bdxp8A== X-Received: by 2002:a5d:5089:: with SMTP id a9mr10128020wrt.290.1560584745980; Sat, 15 Jun 2019 00:45:45 -0700 (PDT) Received: from [192.168.88.149] ([62.170.2.124]) by smtp.gmail.com with ESMTPSA id b203sm7859968wmd.41.2019.06.15.00.45.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jun 2019 00:45:45 -0700 (PDT) Subject: Re: [PATCH] block: bio: Use struct_size() in kmalloc() To: "Gustavo A. R. Silva" Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook References: <20190610150412.GA8430@embeddedor> From: Jens Axboe Message-ID: Date: Sat, 15 Jun 2019 01:45:43 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190610150412.GA8430@embeddedor> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/10/19 9:04 AM, 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 bio_map_data { > ... > struct iovec iov[]; > }; > > instance = kmalloc(sizeof(sizeof(struct bio_map_data) + sizeof(struct iovec) * > 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, iov, count), GFP_KERNEL); > > This code was detected with the help of Coccinelle. Applied, thanks. -- Jens Axboe