Linux-Block Archive on
 help / Atom feed
From: Jens Axboe <>
To: xiaolinkui <>
Subject: Re: [PATCH] block: bio: use struct_size() in kmalloc()
Date: Fri, 17 May 2019 16:59:47 -0600
Message-ID: <> (raw)
In-Reply-To: <>

On 5/17/19 3:17 PM, Jens Axboe wrote:
> On 5/17/19 3:12 AM, xiaolinkui 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;
>>     struct boo entry[];
>> };
>> instance = kmalloc(sizeof(struct foo) + count * sizeof(struct boo), 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);
> Applied, thanks.

I take that back, you obviously didn't even compile this patch. Never
send untested crap, without explicitly saying so.

Jens Axboe

      reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17  9:12 xiaolinkui
2019-05-17 17:18 ` Chaitanya Kulkarni
2019-05-17 21:17 ` Jens Axboe
2019-05-17 22:59   ` Jens Axboe [this message]

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Block Archive on

Archives are clonable:
	git clone --mirror linux-block/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-block linux-block/ \
	public-inbox-index linux-block

Newsgroup available over NNTP:

AGPL code for this site: git clone public-inbox