[PATCH v5] staging: rtl8723bs: replace alloc+memcpy with kmemdup

Alexandru Hossu posted 1 patch 1 month ago
drivers/staging/rtl8723bs/hal/sdio_ops.c          | 3 +--
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
[PATCH v5] staging: rtl8723bs: replace alloc+memcpy with kmemdup
Posted by Alexandru Hossu 1 month ago
Replace open-coded alloc+memcpy patterns with kmemdup().

This simplifies the code and avoids manual size/copy handling.

Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
---
v5:
  - Move version history below the --- line (per submitting-patches).

v4:
  - Drop unrelated DT binding changes from earlier attempts.
  - Include both rtl8723bs changes in one staging-only patch.
  - Wrap long line reported by checkpatch.

 drivers/staging/rtl8723bs/hal/sdio_ops.c          | 3 +--
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8723bs/hal/sdio_ops.c b/drivers/staging/rtl8723bs/hal/sdio_ops.c
index c9cb20c61..6e03d3d8a 100644
--- a/drivers/staging/rtl8723bs/hal/sdio_ops.c
+++ b/drivers/staging/rtl8723bs/hal/sdio_ops.c
@@ -583,11 +583,10 @@ s32 sdio_local_write(
 	)
 		return sd_cmd52_write(intfhdl, addr, cnt, buf);
 
-	tmpbuf = kmalloc(cnt, GFP_ATOMIC);
+	tmpbuf = kmemdup(buf, cnt, GFP_ATOMIC);
 	if (!tmpbuf)
 		return -ENOMEM;
 
-	memcpy(tmpbuf, buf, cnt);
 
 	err = sd_write(intfhdl, addr, cnt, tmpbuf);
 
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 7cb0c6f22..0ae7b6389 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -1430,13 +1430,12 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel
 		goto exit;
 	}
 
-	buf = kzalloc(ielen, GFP_KERNEL);
+	buf = kmemdup(pie, ielen, GFP_KERNEL);
 	if (!buf) {
 		ret =  -ENOMEM;
 		goto exit;
 	}
 
-	memcpy(buf, pie, ielen);
 
 	if (ielen < RSN_HEADER_LEN) {
 		ret  = -1;
-- 
2.43.0
Re: [PATCH v5] staging: rtl8723bs: replace alloc+memcpy with kmemdup
Posted by Dan Carpenter 1 month ago
On Thu, Mar 05, 2026 at 02:09:17AM +0100, Alexandru Hossu wrote:
> Replace open-coded alloc+memcpy patterns with kmemdup().
> 
> This simplifies the code and avoids manual size/copy handling.
> 
> Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
> ---
> v5:
>   - Move version history below the --- line (per submitting-patches).
> 
> v4:
>   - Drop unrelated DT binding changes from earlier attempts.
>   - Include both rtl8723bs changes in one staging-only patch.
>   - Wrap long line reported by checkpatch.
> 
>  drivers/staging/rtl8723bs/hal/sdio_ops.c          | 3 +--
>  drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 3 +--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/hal/sdio_ops.c b/drivers/staging/rtl8723bs/hal/sdio_ops.c
> index c9cb20c61..6e03d3d8a 100644
> --- a/drivers/staging/rtl8723bs/hal/sdio_ops.c
> +++ b/drivers/staging/rtl8723bs/hal/sdio_ops.c
> @@ -583,11 +583,10 @@ s32 sdio_local_write(
>  	)
>  		return sd_cmd52_write(intfhdl, addr, cnt, buf);
>  
> -	tmpbuf = kmalloc(cnt, GFP_ATOMIC);
> +	tmpbuf = kmemdup(buf, cnt, GFP_ATOMIC);
>  	if (!tmpbuf)
>  		return -ENOMEM;
>  
> -	memcpy(tmpbuf, buf, cnt);
>  

Delete the extra blank line.  Also this doesn't apply to linux-next
but I haven't investigated further.

>  	err = sd_write(intfhdl, addr, cnt, tmpbuf);
>  
> diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> index 7cb0c6f22..0ae7b6389 100644
> --- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> @@ -1430,13 +1430,12 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel
>  		goto exit;
>  	}
>  
> -	buf = kzalloc(ielen, GFP_KERNEL);
> +	buf = kmemdup(pie, ielen, GFP_KERNEL);
>  	if (!buf) {
>  		ret =  -ENOMEM;
>  		goto exit;
>  	}
>  
> -	memcpy(buf, pie, ielen);
>  

Extra blank line.

regards,
dan carpenter

>  	if (ielen < RSN_HEADER_LEN) {
>  		ret  = -1;
> -- 
> 2.43.0
>