staging: rtl8192e: Make use kmemdup
PATCH 1/1 staging: rtl8192e: Make use kmemdup
As kmemdup API does kmalloc + memcpy . We can make use of it instead of calling kmalloc and memcpy independetly.
--- drivers/staging/rtl8192e/rtllib_softmac.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtllib_softmac.c +5 -9
@@ -1382,10 +1382,8 @@ rtllib_association_req(struct rtllib_network *beacon, ieee->assocreq_ies =NULL ; ies = &(hdr->info_element[0 ].id); ieee->assocreq_ies_len = (skb->data + skb->len) - ies; - ieee->assocreq_ies =kmalloc (ieee->assocreq_ies_len,GFP_ATOMIC ); -if (ieee->assocreq_ies) -memcpy (ieee->assocreq_ies, ies, ieee->assocreq_ies_len); -else { + ieee->assocreq_ies =kmemdup (ies, ieee->assocreq_ies_len,GFP_ATOMIC ); +if (!ieee->assocreq_ies) {netdev_info (ieee->dev,"%s()Warning: can't alloc memory for assocreq_ies\n" , __func__);
@@ -2259,12 +2257,10 @@ rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb, ieee->assocresp_ies =NULL ; ies = &(assoc_resp->info_element[0 ].id); ieee->assocresp_ies_len = (skb->data + skb->len) - ies; - ieee->assocresp_ies =kmalloc (ieee->assocresp_ies_len, + ieee->assocresp_ies =kmemdup (ies, + ieee->assocresp_ies_len,GFP_ATOMIC ); -if (ieee->assocresp_ies) -memcpy (ieee->assocresp_ies, ies, - ieee->assocresp_ies_len); -else { +if (!ieee->assocresp_ies) {netdev_info (ieee->dev,"%s()Warning: can't alloc memory for assocresp_ies\n" , __func__);
Signature · 1 line
2.7.4
Quoted 2 lines · Hariprasad Kelam
As kmemdup API does kmalloc + memcpy . We can make use of it instead of calling kmalloc and memcpy independetly.
[]
drivers/staging/rtl8192e/rtllib_softmac.c
Quoted 1 line
drivers/staging/rtl8192e/rtllib_softmac.c +0
-0
[]
Quoted 19 lines
drivers/staging/rtl8192e/rtllib_softmac.c +3
-5@@ -1382,10 +1382,8 @@ rtllib_association_req(struct rtllib_network *beacon, ieee->assocreq_ies =NULL ; ies = &(hdr->info_element[0 ].id); ieee->assocreq_ies_len = (skb->data + skb->len) - ies; - ieee->assocreq_ies =kmalloc (ieee->assocreq_ies_len,GFP_ATOMIC ); -if (ieee->assocreq_ies) -memcpy (ieee->assocreq_ies, ies, ieee->assocreq_ies_len); -else { + ieee->assocreq_ies =kmemdup (ies, ieee->assocreq_ies_len,GFP_ATOMIC ); +if (!ieee->assocreq_ies) {netdev_info (ieee->dev,"%s()Warning: can't alloc memory for assocreq_ies\n" , __func__);@@ -2259,12 +2257,10 @@ rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb, ieee->assocresp_ies =NULL ; ies = &(assoc_resp->info_element[0 ].id); ieee->assocresp_ies_len = (skb->data + skb->len) - ies; - ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len, + ieee->assocresp_ies = kmemdup(ies,
drivers/staging/rtl8192e/rtllib_softmac.c rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb, · line 2266
Quoted 10 lines
drivers/staging/rtl8192e/rtllib_softmac.c +2
-4+ ieee->assocresp_ies_len, GFP_ATOMIC); -if (ieee->assocresp_ies) -memcpy (ieee->assocresp_ies, ies, - ieee->assocresp_ies_len); -else { +if (!ieee->assocresp_ies) {netdev_info (ieee->dev,"%s()Warning: can't alloc memory for assocresp_ies\n" , __func__);
Could also remove the netdev_info() uses for allocation failures. These are redundant as a dump_stack() is already done when OOM.
Quoted 30 lines · Joe Perches
Quoted 2 lines · Hariprasad Kelam
As kmemdup API does kmalloc + memcpy . We can make use of it instead of calling kmalloc and memcpy independetly.
[]
drivers/staging/rtl8192e/rtllib_softmac.c
Quoted 1 line
drivers/staging/rtl8192e/rtllib_softmac.c +0
-0[]
Quoted 24 lines
drivers/staging/rtl8192e/rtllib_softmac.c +4
-8@@ -1382,10 +1382,8 @@ rtllib_association_req(struct rtllib_network *beacon, ieee->assocreq_ies =NULL ; ies = &(hdr->info_element[0 ].id); ieee->assocreq_ies_len = (skb->data + skb->len) - ies; - ieee->assocreq_ies =kmalloc (ieee->assocreq_ies_len,GFP_ATOMIC ); -if (ieee->assocreq_ies) -memcpy (ieee->assocreq_ies, ies, ieee->assocreq_ies_len); -else { + ieee->assocreq_ies =kmemdup (ies, ieee->assocreq_ies_len,GFP_ATOMIC ); +if (!ieee->assocreq_ies) {netdev_info (ieee->dev,"%s()Warning: can't alloc memory for assocreq_ies\n" , __func__);@@ -2259,12 +2257,10 @@ rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb, ieee->assocresp_ies =NULL ; ies = &(assoc_resp->info_element[0 ].id); ieee->assocresp_ies_len = (skb->data + skb->len) - ies; - ieee->assocresp_ies =kmalloc (ieee->assocresp_ies_len, + ieee->assocresp_ies =kmemdup (ies, + ieee->assocresp_ies_len,GFP_ATOMIC ); -if (ieee->assocresp_ies) -memcpy (ieee->assocresp_ies, ies, - ieee->assocresp_ies_len);
Quoted 9 lines
drivers/staging/rtl8192e/rtllib_softmac.c rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb, · line 2266
Quoted 5 lines
drivers/staging/rtl8192e/rtllib_softmac.c +1
-1-else { +if (!ieee->assocresp_ies) {netdev_info (ieee->dev,"%s()Warning: can't alloc memory for assocresp_ies\n" , __func__);Could also remove the
netdev_info()uses for allocation failures. These are redundant as adump_stack()is already done when OOM.
Sure will do.
Thanks,
Hariprasad k