netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: broadcom: replace strcpy with strscpy
@ 2025-11-13  8:25 Shi Hao
  2025-11-13 19:22 ` David Laight
  0 siblings, 1 reply; 3+ messages in thread
From: Shi Hao @ 2025-11-13  8:25 UTC (permalink / raw)
  To: pavan.chebbi
  Cc: mchan, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, Shi Hao

Replace strcpy function calls with strscpy to ensure bounds checking
in the destination buffer, preventing buffer overflows and improving
security. This change aligns with current kernel coding guidelines
and best practices.

Signed-off-by: Shi Hao <i.shihao.999@gmail.com>
---
 drivers/net/ethernet/broadcom/tg3.c | 36 ++++++++++++++---------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index d78cafdb2094..1a1673842a35 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -15765,53 +15765,53 @@ static void tg3_read_vpd(struct tg3 *tp)
 	if (tg3_asic_rev(tp) == ASIC_REV_5717) {
 		if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 ||
 		    tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C)
-			strcpy(tp->board_part_number, "BCM5717");
+			strscpy(tp->board_part_number, "BCM5717", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718)
-			strcpy(tp->board_part_number, "BCM5718");
+			strscpy(tp->board_part_number, "BCM5718", TG3_BPN_SIZE);
 		else
 			goto nomatch;
 	} else if (tg3_asic_rev(tp) == ASIC_REV_57780) {
 		if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780)
-			strcpy(tp->board_part_number, "BCM57780");
+			strscpy(tp->board_part_number, "BCM57780", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760)
-			strcpy(tp->board_part_number, "BCM57760");
+			strscpy(tp->board_part_number, "BCM57760", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790)
-			strcpy(tp->board_part_number, "BCM57790");
+			strscpy(tp->board_part_number, "BCM57790", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788)
-			strcpy(tp->board_part_number, "BCM57788");
+			strscpy(tp->board_part_number, "BCM57788", TG3_BPN_SIZE);
 		else
 			goto nomatch;
 	} else if (tg3_asic_rev(tp) == ASIC_REV_57765) {
 		if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761)
-			strcpy(tp->board_part_number, "BCM57761");
+			strscpy(tp->board_part_number, "BCM57761", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765)
-			strcpy(tp->board_part_number, "BCM57765");
+			strscpy(tp->board_part_number, "BCM57765", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781)
-			strcpy(tp->board_part_number, "BCM57781");
+			strscpy(tp->board_part_number, "BCM57781", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785)
-			strcpy(tp->board_part_number, "BCM57785");
+			strscpy(tp->board_part_number, "BCM57785", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791)
-			strcpy(tp->board_part_number, "BCM57791");
+			strscpy(tp->board_part_number, "BCM57791", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795)
-			strcpy(tp->board_part_number, "BCM57795");
+			strscpy(tp->board_part_number, "BCM57795", TG3_BPN_SIZE);
 		else
 			goto nomatch;
 	} else if (tg3_asic_rev(tp) == ASIC_REV_57766) {
 		if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762)
-			strcpy(tp->board_part_number, "BCM57762");
+			strscpy(tp->board_part_number, "BCM57762", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766)
-			strcpy(tp->board_part_number, "BCM57766");
+			strscpy(tp->board_part_number, "BCM57766", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782)
-			strcpy(tp->board_part_number, "BCM57782");
+			strscpy(tp->board_part_number, "BCM57782", TG3_BPN_SIZE);
 		else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786)
-			strcpy(tp->board_part_number, "BCM57786");
+			strscpy(tp->board_part_number, "BCM57786", TG3_BPN_SIZE);
 		else
 			goto nomatch;
 	} else if (tg3_asic_rev(tp) == ASIC_REV_5906) {
-		strcpy(tp->board_part_number, "BCM95906");
+		strscpy(tp->board_part_number, "BCM95906", TG3_BPN_SIZE);
 	} else {
 nomatch:
-		strcpy(tp->board_part_number, "none");
+		strscpy(tp->board_part_number, "none", TG3_BPN_SIZE);
 	}
 }

--
2.51.0


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

end of thread, other threads:[~2025-11-14  9:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-13  8:25 [PATCH] net: ethernet: broadcom: replace strcpy with strscpy Shi Hao
2025-11-13 19:22 ` David Laight
2025-11-14  9:07   ` ShiHao

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