From: Gustavo A. R. Silva <hidden> Date: 2019-01-15 21:11:48
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);
This code was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <redacted>
---
net/sunrpc/xprtrdma/svc_rdma_rw.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Chuck Lever <hidden> Date: 2019-01-15 21:49:52
On Jan 15, 2019, at 4:11 PM, Gustavo A. R. Silva [off-list ref] 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);
This code was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <redacted>
From: Gustavo A. R. Silva <hidden> Date: 2019-01-15 22:16:57
On 1/15/19 3:49 PM, Chuck Lever wrote:
On Jan 15, 2019, at 4:11 PM, Gustavo A. R. Silva [off-list ref] wrote:
quoted
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);
This code was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <redacted>
From: Bruce Fields <hidden> Date: 2019-01-16 23:07:52
On Tue, Jan 15, 2019 at 04:49:16PM -0500, Chuck Lever wrote:
On Jan 15, 2019, at 4:11 PM, Gustavo A. R. Silva [off-list ref] wrote:
quoted
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);
This code was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <redacted>