History

dm stripe: use struct_size() in kmalloc()

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 stripe_c { ... struct stripe stripe[0]; }; In this case alloc_context() and dm_array_too_big() are removed and replaced by the direct use of the struct_size() helper in kmalloc(). Notice that open-coded form is prone to type mistakes. This code was detected with the help of Coccinelle.

Gustavo A. R. Silva committed 7 years ago

Commit 8adeac31 parent 53be73a2 files · +1 −17Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/device-mapper.h+0−3
@@ -594,9 +594,6 @@ void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size); · 593 unmodified lines
594594 */
595595 #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
596596
597−#define dm_array_too_big(fixed, obj, num) \
598− ((num) > (UINT_MAX - (fixed)) / (obj))
599−
600597 /*
601598 * Sector offset taken relative to the start of the target instead of
602599 * relative to the start of the device.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t