diff mbox series

[2/3] wifi: rtl8xxxu: Use strscpy instead of sprintf

Message ID 1db11152-efc1-2027-565a-a0373cccd117@gmail.com
State Superseded
Headers show
Series [1/3] wifi: rtl8xxxu: Name some bits used in burst init | expand

Commit Message

Bitterblue Smith Nov. 8, 2022, 6:56 p.m. UTC
Fill priv->chip_name and priv->chip_vendor with strscpy instead of
sprintf. This is just to prevent future bugs in case the name of a
chip/vendor becomes longer than the size of chip_name/chip_vendor.

Suggested-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
This patch should be applied after my older patch:
"[PATCH v2 2/3] wifi: rtl8xxxu: Split up rtl8xxxu_identify_chip"
---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c   |  2 +-
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c   |  8 ++++----
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c   |  4 ++--
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c   |  2 +-
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c   |  2 +-
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c    | 12 ++++++------
 6 files changed, 15 insertions(+), 15 deletions(-)

Comments

Ping-Ke Shih Nov. 9, 2022, 12:43 a.m. UTC | #1
> -----Original Message-----
> From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> Sent: Wednesday, November 9, 2022 2:56 AM
> To: linux-wireless@vger.kernel.org
> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>; Ping-Ke Shih <pkshih@realtek.com>
> Subject: [PATCH 2/3] wifi: rtl8xxxu: Use strscpy instead of sprintf
> 
> Fill priv->chip_name and priv->chip_vendor with strscpy instead of
> sprintf. This is just to prevent future bugs in case the name of a
> chip/vendor becomes longer than the size of chip_name/chip_vendor.
> 
> Suggested-by: Ping-Ke Shih <pkshih@realtek.com>
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>

Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>

> ---
> This patch should be applied after my older patch:
> "[PATCH v2 2/3] wifi: rtl8xxxu: Split up rtl8xxxu_identify_chip"
> ---
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c   |  2 +-
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c   |  8 ++++----
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c   |  4 ++--
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c   |  2 +-
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c   |  2 +-
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c    | 12 ++++++------
>  6 files changed, 15 insertions(+), 15 deletions(-)
> 

[...]
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
index 0f77312dd0ca..ef38891ddbd1 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
@@ -327,7 +327,7 @@  static int rtl8188fu_identify_chip(struct rtl8xxxu_priv *priv)
 	u32 sys_cfg, vendor;
 	int ret = 0;
 
-	sprintf(priv->chip_name, "8188FU");
+	strscpy(priv->chip_name, "8188FU", sizeof(priv->chip_name));
 	priv->rtl_chip = RTL8188F;
 	priv->rf_paths = 1;
 	priv->rx_paths = 1;
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c
index 815c1e278e4e..6c443e4822d8 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c
@@ -345,12 +345,12 @@  int rtl8192cu_identify_chip(struct rtl8xxxu_priv *priv)
 		bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
 		bonding &= HPON_FSM_BONDING_MASK;
 		if (bonding == HPON_FSM_BONDING_1T2R) {
-			sprintf(priv->chip_name, "8191CU");
+			strscpy(priv->chip_name, "8191CU", sizeof(priv->chip_name));
 			priv->tx_paths = 1;
 			priv->usb_interrupts = 1;
 			priv->rtl_chip = RTL8191C;
 		} else {
-			sprintf(priv->chip_name, "8192CU");
+			strscpy(priv->chip_name, "8192CU", sizeof(priv->chip_name));
 			priv->tx_paths = 2;
 			priv->usb_interrupts = 0;
 			priv->rtl_chip = RTL8192C;
@@ -358,7 +358,7 @@  int rtl8192cu_identify_chip(struct rtl8xxxu_priv *priv)
 		priv->rf_paths = 2;
 		priv->rx_paths = 2;
 	} else {
-		sprintf(priv->chip_name, "8188CU");
+		strscpy(priv->chip_name, "8188CU", sizeof(priv->chip_name));
 		priv->rf_paths = 1;
 		priv->rx_paths = 1;
 		priv->tx_paths = 1;
@@ -451,7 +451,7 @@  static int rtl8192cu_parse_efuse(struct rtl8xxxu_priv *priv)
 	priv->power_base = &rtl8192c_power_base;
 
 	if (efuse->rf_regulatory & 0x20) {
-		sprintf(priv->chip_name, "8188RU");
+		strscpy(priv->chip_name, "8188RU", sizeof(priv->chip_name));
 		priv->rtl_chip = RTL8188R;
 		priv->hi_pa = 1;
 		priv->no_pape = 1;
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
index 7a182073832b..fc3336f18892 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
@@ -496,11 +496,11 @@  int rtl8192eu_identify_chip(struct rtl8xxxu_priv *priv)
 	bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
 	bonding &= HPON_FSM_BONDING_MASK;
 	if (bonding == HPON_FSM_BONDING_1T2R) {
-		sprintf(priv->chip_name, "8191EU");
+		strscpy(priv->chip_name, "8191EU", sizeof(priv->chip_name));
 		priv->tx_paths = 1;
 		priv->rtl_chip = RTL8191E;
 	} else {
-		sprintf(priv->chip_name, "8192EU");
+		strscpy(priv->chip_name, "8192EU", sizeof(priv->chip_name));
 		priv->tx_paths = 2;
 		priv->rtl_chip = RTL8192E;
 	}
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
index 33a1114a5853..c8ab71ed4ff4 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
@@ -144,7 +144,7 @@  static int rtl8723au_identify_chip(struct rtl8xxxu_priv *priv)
 		goto out;
 	}
 
-	sprintf(priv->chip_name, "8723AU");
+	strscpy(priv->chip_name, "8723AU", sizeof(priv->chip_name));
 	priv->usb_interrupts = 1;
 	priv->rtl_chip = RTL8723A;
 
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
index 558572bdd2c8..ece82e613bf0 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
@@ -319,7 +319,7 @@  static int rtl8723bu_identify_chip(struct rtl8xxxu_priv *priv)
 		goto out;
 	}
 
-	sprintf(priv->chip_name, "8723BU");
+	strscpy(priv->chip_name, "8723BU", sizeof(priv->chip_name));
 	priv->rtl_chip = RTL8723B;
 	priv->rf_paths = 1;
 	priv->rx_paths = 1;
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
index e4eb17d03cd7..e8fcd531c437 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
@@ -1592,10 +1592,10 @@  static void rtl8xxxu_print_chipinfo(struct rtl8xxxu_priv *priv)
 void rtl8xxxu_identify_vendor_1bit(struct rtl8xxxu_priv *priv, u32 vendor)
 {
 	if (vendor) {
-		sprintf(priv->chip_vendor, "UMC");
+		strscpy(priv->chip_vendor, "UMC", sizeof(priv->chip_vendor));
 		priv->vendor_umc = 1;
 	} else {
-		sprintf(priv->chip_vendor, "TSMC");
+		strscpy(priv->chip_vendor, "TSMC", sizeof(priv->chip_vendor));
 	}
 }
 
@@ -1603,18 +1603,18 @@  void rtl8xxxu_identify_vendor_2bits(struct rtl8xxxu_priv *priv, u32 vendor)
 {
 	switch (vendor) {
 	case SYS_CFG_VENDOR_ID_TSMC:
-		sprintf(priv->chip_vendor, "TSMC");
+		strscpy(priv->chip_vendor, "TSMC", sizeof(priv->chip_vendor));
 		break;
 	case SYS_CFG_VENDOR_ID_SMIC:
-		sprintf(priv->chip_vendor, "SMIC");
+		strscpy(priv->chip_vendor, "SMIC", sizeof(priv->chip_vendor));
 		priv->vendor_smic = 1;
 		break;
 	case SYS_CFG_VENDOR_ID_UMC:
-		sprintf(priv->chip_vendor, "UMC");
+		strscpy(priv->chip_vendor, "UMC", sizeof(priv->chip_vendor));
 		priv->vendor_umc = 1;
 		break;
 	default:
-		sprintf(priv->chip_vendor, "unknown");
+		strscpy(priv->chip_vendor, "unknown", sizeof(priv->chip_vendor));
 	}
 }