lkml.org 
[lkml]   [2019]   [May]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] block: bio: use struct_size() in kmalloc()
From
Date
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

\
 
 \ /
  Last update: 2019-05-18 01:00    [W:0.063 / U:29.892 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site