linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: bluetooth: Replaced kzalloc and memcpy with kmemdup
@ 2013-03-16 14:07 Alexandru Gheorghiu
  2013-03-18 14:56 ` Gustavo Padovan
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-16 14:07 UTC (permalink / raw)
  To: Marcel Holtmann
  Cc: Gustavo Padovan, Johan Hedberg, linux-bluetooth, linux-kernel,
	Alexandru Gheorghiu

Replaced calls to kzalloc followed by memcpy with a single call to kmemdup.
Patch found using coccinelle.

Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
 net/bluetooth/a2mp.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index eb0f4b1..140e81c 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -397,13 +397,12 @@ static int a2mp_getampassoc_rsp(struct amp_mgr *mgr, struct sk_buff *skb,
 	if (ctrl) {
 		u8 *assoc;
 
-		assoc = kzalloc(assoc_len, GFP_KERNEL);
+		assoc = kmemdup(rsp->amp_assoc, assoc_len, GFP_KERNEL);
 		if (!assoc) {
 			amp_ctrl_put(ctrl);
 			return -ENOMEM;
 		}
 
-		memcpy(assoc, rsp->amp_assoc, assoc_len);
 		ctrl->assoc = assoc;
 		ctrl->assoc_len = assoc_len;
 		ctrl->assoc_rem_len = assoc_len;
@@ -472,13 +471,12 @@ static int a2mp_createphyslink_req(struct amp_mgr *mgr, struct sk_buff *skb,
 		size_t assoc_len = le16_to_cpu(hdr->len) - sizeof(*req);
 		u8 *assoc;
 
-		assoc = kzalloc(assoc_len, GFP_KERNEL);
+		assoc = kmemdup(rep->amp_assoc, assoc_len, GFP_KERNEL);
 		if (!assoc) {
 			amp_ctrl_put(ctrl);
 			return -ENOMEM;
 		}
 
-		memcpy(assoc, req->amp_assoc, assoc_len);
 		ctrl->assoc = assoc;
 		ctrl->assoc_len = assoc_len;
 		ctrl->assoc_rem_len = assoc_len;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: bluetooth: Replaced kzalloc and memcpy with kmemdup
  2013-03-16 14:07 [PATCH] net: bluetooth: Replaced kzalloc and memcpy with kmemdup Alexandru Gheorghiu
@ 2013-03-18 14:56 ` Gustavo Padovan
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo Padovan @ 2013-03-18 14:56 UTC (permalink / raw)
  To: Alexandru Gheorghiu
  Cc: Marcel Holtmann, Johan Hedberg, linux-bluetooth, linux-kernel

Hi Alexandru,

* Alexandru Gheorghiu <gheorghiuandru@gmail.com> [2013-03-16 16:07:10 +0200]:

> Replaced calls to kzalloc followed by memcpy with a single call to kmemdup.
> Patch found using coccinelle.
> 
> Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> ---
>  net/bluetooth/a2mp.c |    6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
> index eb0f4b1..140e81c 100644
> --- a/net/bluetooth/a2mp.c
> +++ b/net/bluetooth/a2mp.c
> @@ -397,13 +397,12 @@ static int a2mp_getampassoc_rsp(struct amp_mgr *mgr, struct sk_buff *skb,
>  	if (ctrl) {
>  		u8 *assoc;
>  
> -		assoc = kzalloc(assoc_len, GFP_KERNEL);
> +		assoc = kmemdup(rsp->amp_assoc, assoc_len, GFP_KERNEL);
>  		if (!assoc) {
>  			amp_ctrl_put(ctrl);
>  			return -ENOMEM;
>  		}
>  
> -		memcpy(assoc, rsp->amp_assoc, assoc_len);
>  		ctrl->assoc = assoc;
>  		ctrl->assoc_len = assoc_len;
>  		ctrl->assoc_rem_len = assoc_len;
> @@ -472,13 +471,12 @@ static int a2mp_createphyslink_req(struct amp_mgr *mgr, struct sk_buff *skb,
>  		size_t assoc_len = le16_to_cpu(hdr->len) - sizeof(*req);
>  		u8 *assoc;
>  
> -		assoc = kzalloc(assoc_len, GFP_KERNEL);
> +		assoc = kmemdup(rep->amp_assoc, assoc_len, GFP_KERNEL);

Please get into the habit of build your patches before sending them upstream:

  CC [M]  net/bluetooth/a2mp.o
net/bluetooth/a2mp.c: In function ‘a2mp_createphyslink_req’:
net/bluetooth/a2mp.c:474:19: error: ‘rep’ undeclared (first use in this function)
net/bluetooth/a2mp.c:474:19: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [net/bluetooth/a2mp.o] Error 1
make[1]: *** [net/bluetooth] Error 2


	Gustavo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: bluetooth: Replaced kzalloc and memcpy with kmemdup
  2013-03-17  5:16 Alexandru Gheorghiu
@ 2013-03-18 15:17 ` Gustavo Padovan
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo Padovan @ 2013-03-18 15:17 UTC (permalink / raw)
  To: Alexandru Gheorghiu; +Cc: Marcel Holtmann, linux-bluetooth, linux-kernel

Hi Alexandru,

* Alexandru Gheorghiu <gheorghiuandru@gmail.com> [2013-03-17 07:16:50 +0200]:

> Replaced calls to kzalloc followed by memcpy with a single call to kmemdup.
> 
> Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> ---
>  net/bluetooth/a2mp.c |    6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

Patch has been applied to bluetooth-next. Thanks.

	Gustavo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] net: bluetooth: Replaced kzalloc and memcpy with kmemdup
@ 2013-03-17  5:16 Alexandru Gheorghiu
  2013-03-18 15:17 ` Gustavo Padovan
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-17  5:16 UTC (permalink / raw)
  To: Gustavo Padovan
  Cc: Marcel Holtmann, linux-bluetooth, linux-kernel, Alexandru Gheorghiu

Replaced calls to kzalloc followed by memcpy with a single call to kmemdup.

Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
 net/bluetooth/a2mp.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index eb0f4b1..17f33a6 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -397,13 +397,12 @@ static int a2mp_getampassoc_rsp(struct amp_mgr *mgr, struct sk_buff *skb,
 	if (ctrl) {
 		u8 *assoc;
 
-		assoc = kzalloc(assoc_len, GFP_KERNEL);
+		assoc = kmemdup(rsp->amp_assoc, assoc_len, GFP_KERNEL);
 		if (!assoc) {
 			amp_ctrl_put(ctrl);
 			return -ENOMEM;
 		}
 
-		memcpy(assoc, rsp->amp_assoc, assoc_len);
 		ctrl->assoc = assoc;
 		ctrl->assoc_len = assoc_len;
 		ctrl->assoc_rem_len = assoc_len;
@@ -472,13 +471,12 @@ static int a2mp_createphyslink_req(struct amp_mgr *mgr, struct sk_buff *skb,
 		size_t assoc_len = le16_to_cpu(hdr->len) - sizeof(*req);
 		u8 *assoc;
 
-		assoc = kzalloc(assoc_len, GFP_KERNEL);
+		assoc = kmemdup(req->amp_assoc, assoc_len, GFP_KERNEL);
 		if (!assoc) {
 			amp_ctrl_put(ctrl);
 			return -ENOMEM;
 		}
 
-		memcpy(assoc, req->amp_assoc, assoc_len);
 		ctrl->assoc = assoc;
 		ctrl->assoc_len = assoc_len;
 		ctrl->assoc_rem_len = assoc_len;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-03-18 15:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-16 14:07 [PATCH] net: bluetooth: Replaced kzalloc and memcpy with kmemdup Alexandru Gheorghiu
2013-03-18 14:56 ` Gustavo Padovan
2013-03-17  5:16 Alexandru Gheorghiu
2013-03-18 15:17 ` Gustavo Padovan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).