xprtrdma: Use struct_size() in kzalloc()
Subsystems (4)
PATCH 1/1 xprtrdma: Use struct_size() in kzalloc()
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 = kzalloc(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 = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
This code was detected with the help of Coccinelle.
--- net/sunrpc/xprtrdma/verbs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/sunrpc/xprtrdma/verbs.c +1 -2
@@ -811,8 +811,7 @@ static struct rpcrdma_sendctx *rpcrdma_sendctx_create(struct rpcrdma_ia *ia) {struct rpcrdma_sendctx *sc; - sc =kzalloc (sizeof (*sc) + - ia->ri_max_send_sges *sizeof (struct ib_sge ), + sc =kzalloc (struct_size (sc, sc_sges, ia->ri_max_send_sges),GFP_KERNEL );if (!sc)return NULL ;
Signature · 1 line
2.20.1
Quoted 15 lines · Gustavo A. R. Silva
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 =
kzalloc(sizeof(struct foo) + count * sizeof(struct boo), GFP_KERNEL);
Quoted 8 lines
Instead of leaving these open-coded and prone to type mistakes, we can now use the new
struct_size()helper:instance =
kzalloc(struct_size(instance, entry, count), GFP_KERNEL);This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>
Quoted 21 lines
---
net/sunrpc/xprtrdma/verbs.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)net/sunrpc/xprtrdma/verbs.c +1
-2@@ -811,8 +811,7 @@ static struct rpcrdma_sendctx *rpcrdma_sendctx_create(struct rpcrdma_ia *ia) {struct rpcrdma_sendctx *sc; - sc =kzalloc (sizeof (*sc) + - ia->ri_max_send_sges *sizeof (struct ib_sge ), + sc =kzalloc (struct_size (sc, sc_sges, ia->ri_max_send_sges),GFP_KERNEL );if (!sc)return NULL ;Signature · 1 line
2.20.1
--
Chuck Lever
Quoted 18 lines · Chuck Lever
Quoted 18 lines · Gustavo A. R. Silva
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 =
kzalloc(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:
Quoted 8 lines
Quoted 5 lines
instance =
kzalloc(struct_size(instance, entry, count), GFP_KERNEL);This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>Reviewed-by Chuck Lever <[email protected]>
Thanks, Chuck.
--
Gustavo
Hi all,
Friendly ping:
Who can take this?
Thanks
--
Gustavo
Quoted 54 lines · Chuck Lever
Quoted 15 lines · Gustavo A. R. Silva
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 =
kzalloc(sizeof(struct foo) + count * sizeof(struct boo), GFP_KERNEL);Quoted 8 lines
Instead of leaving these open-coded and prone to type mistakes, we can now use the new
struct_size()helper:instance =
kzalloc(struct_size(instance, entry, count), GFP_KERNEL);This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>Reviewed-by Chuck Lever <[email protected]>Quoted 21 lines
---
net/sunrpc/xprtrdma/verbs.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)net/sunrpc/xprtrdma/verbs.c +1
-2@@ -811,8 +811,7 @@ static struct rpcrdma_sendctx *rpcrdma_sendctx_create(struct rpcrdma_ia *ia) {struct rpcrdma_sendctx *sc; - sc =kzalloc (sizeof (*sc) + - ia->ri_max_send_sges *sizeof (struct ib_sge ), + sc =kzalloc (struct_size (sc, sc_sges, ia->ri_max_send_sges),GFP_KERNEL );if (!sc)return NULL ;Signature · 1 line
2.20.1--
Chuck Lever
Hi Dave,
I wonder if you can take this patch.
Thanks
--
Gustavo
Quoted 65 lines · Gustavo A. R. Silva
Hi all,
Friendly ping:
Who can take this?
Thanks
--
GustavoQuoted 54 lines · Chuck Lever
Quoted 15 lines · Gustavo A. R. Silva
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 =
kzalloc(sizeof(struct foo) + count * sizeof(struct boo), GFP_KERNEL);Quoted 8 lines
Instead of leaving these open-coded and prone to type mistakes, we can now use the new
struct_size()helper:instance =
kzalloc(struct_size(instance, entry, count), GFP_KERNEL);This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>Reviewed-by Chuck Lever <[email protected]>Quoted 21 lines
---
net/sunrpc/xprtrdma/verbs.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)net/sunrpc/xprtrdma/verbs.c +1
-2@@ -811,8 +811,7 @@ static struct rpcrdma_sendctx *rpcrdma_sendctx_create(struct rpcrdma_ia *ia) {struct rpcrdma_sendctx *sc; - sc =kzalloc (sizeof (*sc) + - ia->ri_max_send_sges *sizeof (struct ib_sge ), + sc =kzalloc (struct_size (sc, sc_sges, ia->ri_max_send_sges),GFP_KERNEL );if (!sc)return NULL ;Signature · 1 line
2.20.1--
Chuck Lever
Hi Gustavo-
Anna is supposed to take patches for xprtrdma/ .
Quoted 76 lines · Gustavo A. R. Silva
Hi Dave,
I wonder if you can take this patch.
Thanks
--
GustavoQuoted 65 lines · Gustavo A. R. Silva
Hi all,
Friendly ping:
Who can take this?
Thanks
--
GustavoQuoted 54 lines · Chuck Lever
Quoted 15 lines · Gustavo A. R. Silva
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 =
kzalloc(sizeof(struct foo) + count * sizeof(struct boo), GFP_KERNEL);Quoted 8 lines
Instead of leaving these open-coded and prone to type mistakes, we can now use the new
struct_size()helper:instance =
kzalloc(struct_size(instance, entry, count), GFP_KERNEL);This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>Reviewed-by Chuck Lever <[email protected]>Quoted 21 lines
---
net/sunrpc/xprtrdma/verbs.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)net/sunrpc/xprtrdma/verbs.c +1
-2@@ -811,8 +811,7 @@ static struct rpcrdma_sendctx *rpcrdma_sendctx_create(struct rpcrdma_ia *ia) {struct rpcrdma_sendctx *sc; - sc =kzalloc (sizeof (*sc) + - ia->ri_max_send_sges *sizeof (struct ib_sge ), + sc =kzalloc (struct_size (sc, sc_sges, ia->ri_max_send_sges),GFP_KERNEL );if (!sc)return NULL ;Signature · 1 line
2.20.1--
Chuck Lever
--
Chuck Lever
David Miller
maintainerFrom: "Gustavo A. R. Silva" <[email protected]>
Date: Thu, 23 May 2019 17:36:00 -0500
Quoted 3 lines
Hi Dave,
I wonder if you can take this patch.
The sunrpc/nfs maintainer should take this. I never take patches in that area.
Quoted 10 lines · David Miller
From: "Gustavo A. R. Silva" <[email protected]>
Date: Thu, 23 May 2019 17:36:00 -0500Quoted 3 lines
Hi Dave,
I wonder if you can take this patch.
The sunrpc/nfs maintainer should take this. I never take patches in that area.
Yep. Chuck just let me know that Anna is who take these patches.
Hopefully, she will take this one soon.
Thanks
--
Gustavo
Schumaker, Anna
AppliedQuoted 9 lines · Gustavo A. R. Silva
Quoted 7 lines · David Miller
From: "Gustavo A. R. Silva" <[email protected]>
Date: Thu, 23 May 2019 17:36:00 -0500Quoted 3 lines
Hi Dave,
I wonder if you can take this patch.
Quoted 7 lines
Quoted 3 lines
The sunrpc/nfs maintainer should take this. I never take patches in that area.
Yep. Chuck just let me know that Anna is who take these patches.
Hopefully, she will take this one soon.
I've applied this to push out later in the week. Thanks for pointing it out to me!
Anna
Quoted 4 lines
Thanks
--
Gustavo