[PATCH v2 2/3] staging: rtl8188eu: substitute custom hex2bin()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of using custom code to convert hexdecinal strings to their binary
represantation let's use kernel's library function.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
 drivers/staging/rtl8188eu/core/rtw_ieee80211.c  |  5 ---
 drivers/staging/rtl8188eu/include/wlan_bssdef.h |  1 -
 drivers/staging/rtl8188eu/os_dep/ioctl_linux.c  | 46 +++++++++++++++++--------
 3 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
index 3eeab2c..02bd3b0 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
@@ -1084,11 +1084,6 @@ u8 str_2char2num(u8 hch, u8 lch)
     return (key_char2num(hch) * 10) + key_char2num(lch);
 }
 
-u8 key_2char2num(u8 hch, u8 lch)
-{
-    return (key_char2num(hch) << 4) | key_char2num(lch);
-}
-
 void rtw_macaddr_cfg(u8 *mac_addr)
 {
 	u8 mac[ETH_ALEN];
diff --git a/drivers/staging/rtl8188eu/include/wlan_bssdef.h b/drivers/staging/rtl8188eu/include/wlan_bssdef.h
index e70075d..85e4b92 100644
--- a/drivers/staging/rtl8188eu/include/wlan_bssdef.h
+++ b/drivers/staging/rtl8188eu/include/wlan_bssdef.h
@@ -340,7 +340,6 @@ struct ndis_802_11_cap {
 	struct ndis_802_11_auth_encrypt AuthenticationEncryptionSupported[1];
 };
 
-u8 key_2char2num(u8 hch, u8 lch);
 u8 key_char2num(u8 ch);
 u8 str_2char2num(u8 hch, u8 lch);
 
diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
index 7629206..6402f48 100644
--- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
@@ -5855,7 +5855,7 @@ static int rtw_mp_efuse_set(struct net_device *dev,
 	struct efuse_hal *pEfuseHal;
 
 	u8 ips_mode = 0, lps_mode = 0;
-	u32 i, jj, kk;
+	u32 i;
 	u8 *setdata = NULL;
 	u8 *ShadowMapBT = NULL;
 	u8 *ShadowMapWiFi = NULL;
@@ -5933,8 +5933,11 @@ static int rtw_mp_efuse_set(struct net_device *dev,
 		DBG_88E("%s: cnts =%d\n", __func__, cnts);
 		DBG_88E("%s: map data =%s\n", __func__, tmp[2]);
 
-		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
-			setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
+		if (hex2bin(setdata, tmp[2], cnts) < 0) {
+			err = -EINVAL;
+			goto exit;
+		}
+
 		/* Change to check TYPE_EFUSE_MAP_LEN, because 8188E raw 256, logic map over 256. */
 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_size);
 		if ((addr+cnts) > max_available_size) {
@@ -5972,8 +5975,10 @@ static int rtw_mp_efuse_set(struct net_device *dev,
 		DBG_88E("%s: cnts =%d\n", __func__, cnts);
 		DBG_88E("%s: raw data =%s\n", __func__, tmp[2]);
 
-		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
-			setrawdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
+		if (hex2bin(setrawdata, tmp[2], cnts) < 0) {
+			err = -EINVAL;
+			goto exit;
+		}
 
 		if (rtw_efuse_access(padapter, true, addr, cnts, setrawdata) == _FAIL) {
 			DBG_88E("%s: rtw_efuse_access error!!\n", __func__);
@@ -6008,8 +6013,11 @@ static int rtw_mp_efuse_set(struct net_device *dev,
 		DBG_88E("%s: cnts =%d\n", __func__, cnts);
 		DBG_88E("%s: MAC address =%s\n", __func__, tmp[1]);
 
-		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
-			setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
+		if (hex2bin(setdata, tmp[1], cnts) < 0) {
+			err = -EINVAL;
+			goto exit;
+		}
+
 		/* Change to check TYPE_EFUSE_MAP_LEN, because 8188E raw 256, logic map over 256. */
 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_size);
 		if ((addr+cnts) > max_available_size) {
@@ -6046,8 +6054,10 @@ static int rtw_mp_efuse_set(struct net_device *dev,
 		DBG_88E("%s: cnts =%d\n", __func__, cnts);
 		DBG_88E("%s: VID/PID =%s\n", __func__, tmp[1]);
 
-		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
-			setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
+		if (hex2bin(setdata, tmp[1], cnts) < 0) {
+			err = -EINVAL;
+			goto exit;
+		}
 
 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size);
 		if ((addr+cnts) > max_available_size) {
@@ -6085,8 +6095,10 @@ static int rtw_mp_efuse_set(struct net_device *dev,
 		DBG_88E("%s: cnts =%d\n", __func__, cnts);
 		DBG_88E("%s: BT data =%s\n", __func__, tmp[2]);
 
-		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
-			setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
+		if (hex2bin(setdata, tmp[2], cnts) < 0) {
+			err = -EINVAL;
+			goto exit;
+		}
 
 		EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size);
 		if ((addr+cnts) > max_available_size) {
@@ -6119,8 +6131,10 @@ static int rtw_mp_efuse_set(struct net_device *dev,
 		DBG_88E("%s: cnts =%d\n", __func__, cnts);
 		DBG_88E("%s: BT tmp data =%s\n", __func__, tmp[2]);
 
-		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
-			pEfuseHal->fakeBTEfuseModifiedMap[addr+jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
+		if (hex2bin(pEfuseHal->fakeBTEfuseModifiedMap + addr, tmp[2], cnts) < 0) {
+			err = -EINVAL;
+			goto exit;
+		}
 	} else if (strcmp(tmp[0], "wldumpfake") == 0) {
 		if (rtw_efuse_map_read(padapter, 0, EFUSE_BT_MAX_MAP_LEN,  pEfuseHal->fakeEfuseModifiedMap) == _SUCCESS) {
 			DBG_88E("%s: BT read all map success\n", __func__);
@@ -6173,8 +6187,10 @@ static int rtw_mp_efuse_set(struct net_device *dev,
 		DBG_88E("%s: cnts =%d\n", __func__, cnts);
 		DBG_88E("%s: map tmp data =%s\n", __func__, tmp[2]);
 
-		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
-			pEfuseHal->fakeEfuseModifiedMap[addr+jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
+		if (hex2bin(pEfuseHal->fakeEfuseModifiedMap + addr, tmp[2], cnts) < 0) {
+			err = -EINVAL;
+			goto exit;
+		}
 	}
 
 exit:
-- 
2.0.0

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux