* [PATCH] staging: rtl8192e: Make use kmemdup
@ 2019-08-03 17:40 Hariprasad Kelam
2019-08-03 17:52 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Hariprasad Kelam @ 2019-08-03 17:40 UTC (permalink / raw)
To: Greg Kroah-Hartman, Himadri Pandya, Larry Finger,
Michiel Schuurmans, Hariprasad Kelam, devel, linux-kernel
As kmemdup API does kmalloc + memcpy . We can make use of it instead of
calling kmalloc and memcpy independetly.
Signed-off-by: Hariprasad Kelam <hariprasad.kelam@gmail.com>
---
drivers/staging/rtl8192e/rtllib_softmac.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index e29e8d6..9b8b301 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -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__);
--
2.7.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: rtl8192e: Make use kmemdup
2019-08-03 17:40 [PATCH] staging: rtl8192e: Make use kmemdup Hariprasad Kelam
@ 2019-08-03 17:52 ` Joe Perches
2019-08-04 2:38 ` Hariprasad Kelam
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2019-08-03 17:52 UTC (permalink / raw)
To: Hariprasad Kelam, Greg Kroah-Hartman, Himadri Pandya,
Larry Finger, Michiel Schuurmans, devel, linux-kernel
On Sat, 2019-08-03 at 23:10 +0530, Hariprasad Kelam wrote:
> As kmemdup API does kmalloc + memcpy . We can make use of it instead of
> calling kmalloc and memcpy independetly.
[]
> diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
[]
> @@ -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__);
Could also remove the netdev_info() uses for allocation failures.
These are redundant as a dump_stack() is already done when OOM.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: rtl8192e: Make use kmemdup
2019-08-03 17:52 ` Joe Perches
@ 2019-08-04 2:38 ` Hariprasad Kelam
0 siblings, 0 replies; 3+ messages in thread
From: Hariprasad Kelam @ 2019-08-04 2:38 UTC (permalink / raw)
To: Joe Perches, Greg Kroah-Hartman, Himadri Pandya,
Michiel Schuurmans, Larry Finger, Hariprasad Kelam, devel,
linux-kernel
On Sat, Aug 03, 2019 at 10:52:04AM -0700, Joe Perches wrote:
> On Sat, 2019-08-03 at 23:10 +0530, Hariprasad Kelam wrote:
> > As kmemdup API does kmalloc + memcpy . We can make use of it instead of
> > calling kmalloc and memcpy independetly.
> []
> > diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
> []
> > @@ -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__);
>
> Could also remove the netdev_info() uses for allocation failures.
> These are redundant as a dump_stack() is already done when OOM.
>
Sure will do.
Thanks,
Hariprasad k
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-04 2:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-03 17:40 [PATCH] staging: rtl8192e: Make use kmemdup Hariprasad Kelam
2019-08-03 17:52 ` Joe Perches
2019-08-04 2:38 ` Hariprasad Kelam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®