[net-next] brcm80211: use strscpy() to instead of strncpy()

Message ID 202212231037210142246@zte.com.cn
State New
Headers
Series [net-next] brcm80211: use strscpy() to instead of strncpy() |

Commit Message

Yang Yang Dec. 23, 2022, 2:37 a.m. UTC
  From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL-terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
 drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Kalle Valo Jan. 16, 2023, 1:08 p.m. UTC | #1
<yang.yang29@zte.com.cn> wrote:

> From: Xu Panda <xu.panda@zte.com.cn>
> 
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL-terminated strings.
> 
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>

Mismatch email in From and Signed-off-by lines:

From: <yang.yang29@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>

Patch set to Changes Requested.
  
Leon Romanovsky Jan. 16, 2023, 1:31 p.m. UTC | #2
On Mon, Jan 16, 2023 at 01:08:36PM +0000, Kalle Valo wrote:
> <yang.yang29@zte.com.cn> wrote:
> 
> > From: Xu Panda <xu.panda@zte.com.cn>
> > 
> > The implementation of strscpy() is more robust and safer.
> > That's now the recommended way to copy NUL-terminated strings.
> > 
> > Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> > Signed-off-by: Yang Yang <yang.yang29@zte.com>
> 
> Mismatch email in From and Signed-off-by lines:
> 
> From: <yang.yang29@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>
> 
> Patch set to Changes Requested.

Kalle, please be aware of this response
https://lore.kernel.org/netdev/20230113112817.623f58fa@kernel.org/

"I don't trust that you know what you're doing. So please don't send
any more strncpy() -> strscpy() conversions for networking."

Thanks

> 
> -- 
> https://patchwork.kernel.org/project/linux-wireless/patch/202212231037210142246@zte.com.cn/
> 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
>
  
Kalle Valo Jan. 16, 2023, 3:18 p.m. UTC | #3
Leon Romanovsky <leon@kernel.org> writes:

> On Mon, Jan 16, 2023 at 01:08:36PM +0000, Kalle Valo wrote:
>> <yang.yang29@zte.com.cn> wrote:
>> 
>> > From: Xu Panda <xu.panda@zte.com.cn>
>> > 
>> > The implementation of strscpy() is more robust and safer.
>> > That's now the recommended way to copy NUL-terminated strings.
>> > 
>> > Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
>> > Signed-off-by: Yang Yang <yang.yang29@zte.com>
>> 
>> Mismatch email in From and Signed-off-by lines:
>> 
>> From: <yang.yang29@zte.com.cn>
>> Signed-off-by: Yang Yang <yang.yang29@zte.com>
>> 
>> Patch set to Changes Requested.
>
> Kalle, please be aware of this response
> https://lore.kernel.org/netdev/20230113112817.623f58fa@kernel.org/
>
> "I don't trust that you know what you're doing. So please don't send
> any more strncpy() -> strscpy() conversions for networking."

Good to know, thanks.
  

Patch

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c
index b7df576bb84d..66336c87b0d9 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c
@@ -584,8 +584,7 @@  struct dma_pub *dma_attach(char *name, struct brcms_c_info *wlc,
 		      rxextheadroom, nrxpost, rxoffset, txregbase, rxregbase);

 	/* make a private copy of our callers name */
-	strncpy(di->name, name, MAXNAMEL);
-	di->name[MAXNAMEL - 1] = '\0';
+	strscpy(di->name, name, MAXNAMEL);

 	di->dmadev = core->dma_dev;