linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch v2] staging: rtl8723bs: os_dep: ioctl_linux: make use of kzalloc
@ 2019-06-18  1:44 Hariprasad Kelam
  2019-06-18  6:57 ` Greg Kroah-Hartman
  2019-06-18  8:55 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Hariprasad Kelam @ 2019-06-18  1:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Michael Straube, Mamta Shukla,
	Nishka Dasgupta, Hariprasad Kelam, Emanuel Bennici,
	Puranjay Mohan, Shobhit Kukreti, devel, linux-kernel

kmalloc with memset can be replaced with kzalloc.

Signed-off-by: Hariprasad Kelam <hariprasad.kelam@gmail.com>
-----
changes in v2: Replace rtw_zmalloc with kzalloc
---
---
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index ea50ec424..e050f20 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -477,14 +477,12 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
 		if (wep_key_len > 0) {
 			wep_key_len = wep_key_len <= 5 ? 5 : 13;
 			wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
-			pwep = rtw_malloc(wep_total_len);
+			pwep = kzalloc(wep_total_len, GFP_KERNEL);
 			if (pwep == NULL) {
 				RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, (" wpa_set_encryption: pwep allocate fail !!!\n"));
 				goto exit;
 			}
 
-			memset(pwep, 0, wep_total_len);
-
 			pwep->KeyLength = wep_key_len;
 			pwep->Length = wep_total_len;
 
@@ -2142,12 +2140,10 @@ static int rtw_wx_set_enc_ext(struct net_device *dev,
 	int ret = 0;
 
 	param_len = sizeof(struct ieee_param) + pext->key_len;
-	param = rtw_malloc(param_len);
+	param = kzalloc(param_len, GFP_KERNEL);
 	if (param == NULL)
 		return -1;
 
-	memset(param, 0, param_len);
-
 	param->cmd = IEEE_CMD_SET_ENCRYPTION;
 	memset(param->sta_addr, 0xff, ETH_ALEN);
 
@@ -3513,14 +3509,12 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
 		if (wep_key_len > 0) {
 			wep_key_len = wep_key_len <= 5 ? 5 : 13;
 			wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
-			pwep = rtw_malloc(wep_total_len);
+			pwep = kzalloc(wep_total_len, GFP_KERNEL);
 			if (pwep == NULL) {
 				DBG_871X(" r871x_set_encryption: pwep allocate fail !!!\n");
 				goto exit;
 			}
 
-			memset(pwep, 0, wep_total_len);
-
 			pwep->KeyLength = wep_key_len;
 			pwep->Length = wep_total_len;
 
-- 
2.7.4


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

* Re: [Patch v2] staging: rtl8723bs: os_dep: ioctl_linux: make use of kzalloc
  2019-06-18  1:44 [Patch v2] staging: rtl8723bs: os_dep: ioctl_linux: make use of kzalloc Hariprasad Kelam
@ 2019-06-18  6:57 ` Greg Kroah-Hartman
  2019-06-18  8:55 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-18  6:57 UTC (permalink / raw)
  To: Hariprasad Kelam
  Cc: Michael Straube, Mamta Shukla, Nishka Dasgupta, Emanuel Bennici,
	Puranjay Mohan, Shobhit Kukreti, devel, linux-kernel

On Tue, Jun 18, 2019 at 07:14:10AM +0530, Hariprasad Kelam wrote:
> kmalloc with memset can be replaced with kzalloc.

Yes, but did you audit the call-paths of this to ensure that GFP_KERNEL
is the correct value for kzalloc() here?  If so, please document that in
the changelog.

thanks,

greg k-h

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

* Re: [Patch v2] staging: rtl8723bs: os_dep: ioctl_linux: make use of kzalloc
  2019-06-18  1:44 [Patch v2] staging: rtl8723bs: os_dep: ioctl_linux: make use of kzalloc Hariprasad Kelam
  2019-06-18  6:57 ` Greg Kroah-Hartman
@ 2019-06-18  8:55 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2019-06-18  8:55 UTC (permalink / raw)
  To: Hariprasad Kelam
  Cc: Greg Kroah-Hartman, Michael Straube, Mamta Shukla,
	Nishka Dasgupta, Emanuel Bennici, Puranjay Mohan,
	Shobhit Kukreti, devel, linux-kernel

On Tue, Jun 18, 2019 at 07:14:10AM +0530, Hariprasad Kelam wrote:
> kmalloc with memset can be replaced with kzalloc.
> 
> Signed-off-by: Hariprasad Kelam <hariprasad.kelam@gmail.com>
> -----
> changes in v2: Replace rtw_zmalloc with kzalloc
> ---
> ---


The changelog should say something like:

    This patch is a cleanup which replaces rtw_malloc(wep_total_len)
    with kzalloc() and removes the memset().

    The rtw_malloc() does GFP_ATOMIC allocations when in_atomic() is true.
    But as the comments for in_atomic() describe, the in_atomic() check
    should not be used in driver code.  The in_atomic() check is not
    accurate when preempt is disabled.

    In this code we are not in IRQ context and we are not holding any
    spin_locks so GFP_KERNEL is safe.

regards,
dan carpenter


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

end of thread, other threads:[~2019-06-18  8:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18  1:44 [Patch v2] staging: rtl8723bs: os_dep: ioctl_linux: make use of kzalloc Hariprasad Kelam
2019-06-18  6:57 ` Greg Kroah-Hartman
2019-06-18  8:55 ` Dan Carpenter

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).