Search Linux Wireless

[PATCH] staging: wilc1000: use helper API to pack data for firmware

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

 



From: Ajay Singh <ajay.kathat@xxxxxxxxxxxxx>

As discussed in [1] use put_unaligned_le16() & put_unaligned_le32()
helper to pack the data before sending to firmware.

[1]. https://lore.kernel.org/linux-wireless/86bc79ccd379497d56bade79ec8f717603110ef7.camel@xxxxxxxxxxxxxxxx/

Signed-off-by: Ajay Singh <ajay.kathat@xxxxxxxxxxxxx>
---
 drivers/staging/wilc1000/wilc_wlan_cfg.c | 74 ++++++------------------
 1 file changed, 18 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index f4144f93e4a9..3f53807cee0f 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -52,57 +52,35 @@ static const struct wilc_cfg_str g_cfg_str[] = {
 
 static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8)
 {
-	u8 *buf;
-
 	if ((offset + 4) >= WILC_MAX_CFG_FRAME_SIZE)
 		return 0;
 
-	buf = &frame[offset];
-
-	buf[0] = (u8)id;
-	buf[1] = (u8)(id >> 8);
-	buf[2] = 1;
-	buf[3] = 0;
-	buf[4] = val8;
+	put_unaligned_le16(id, &frame[offset]);
+	put_unaligned_le16(1, &frame[offset + 2]);
+	frame[offset + 4] = val8;
 	return 5;
 }
 
 static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16)
 {
-	u8 *buf;
-
 	if ((offset + 5) >= WILC_MAX_CFG_FRAME_SIZE)
 		return 0;
 
-	buf = &frame[offset];
-
-	buf[0] = (u8)id;
-	buf[1] = (u8)(id >> 8);
-	buf[2] = 2;
-	buf[3] = 0;
-	buf[4] = (u8)val16;
-	buf[5] = (u8)(val16 >> 8);
+	put_unaligned_le16(id, &frame[offset]);
+	put_unaligned_le16(2, &frame[offset + 2]);
+	put_unaligned_le16(val16, &frame[offset + 4]);
 
 	return 6;
 }
 
 static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
 {
-	u8 *buf;
-
 	if ((offset + 7) >= WILC_MAX_CFG_FRAME_SIZE)
 		return 0;
 
-	buf = &frame[offset];
-
-	buf[0] = (u8)id;
-	buf[1] = (u8)(id >> 8);
-	buf[2] = 4;
-	buf[3] = 0;
-	buf[4] = (u8)val32;
-	buf[5] = (u8)(val32 >> 8);
-	buf[6] = (u8)(val32 >> 16);
-	buf[7] = (u8)(val32 >> 24);
+	put_unaligned_le16(id, &frame[offset]);
+	put_unaligned_le16(4, &frame[offset + 2]);
+	put_unaligned_le32(val32, &frame[offset + 4]);
 
 	return 8;
 }
@@ -110,46 +88,35 @@ static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
 static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str,
 				 u32 size)
 {
-	u8 *buf;
-
 	if ((offset + size + 4) >= WILC_MAX_CFG_FRAME_SIZE)
 		return 0;
 
-	buf = &frame[offset];
-
-	buf[0] = (u8)id;
-	buf[1] = (u8)(id >> 8);
-	buf[2] = (u8)size;
-	buf[3] = (u8)(size >> 8);
-
+	put_unaligned_le16(id, &frame[offset]);
+	put_unaligned_le16(size, &frame[offset + 2]);
 	if (str && size != 0)
-		memcpy(&buf[4], str, size);
+		memcpy(&frame[offset + 4], str, size);
 
 	return (size + 4);
 }
 
 static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
 {
-	u8 *buf;
 	u32 i;
 	u8 checksum = 0;
 
 	if ((offset + size + 5) >= WILC_MAX_CFG_FRAME_SIZE)
 		return 0;
 
-	buf = &frame[offset];
-	buf[0] = (u8)id;
-	buf[1] = (u8)(id >> 8);
-	buf[2] = (u8)size;
-	buf[3] = (u8)(size >> 8);
+	put_unaligned_le16(id, &frame[offset]);
+	put_unaligned_le16(size, &frame[offset + 2]);
 
 	if ((b) && size != 0) {
-		memcpy(&buf[4], b, size);
+		memcpy(&frame[offset + 4], b, size);
 		for (i = 0; i < size; i++)
-			checksum += buf[i + 4];
+			checksum += frame[offset + i + 4];
 	}
 
-	buf[size + 4] = checksum;
+	frame[offset + size + 4] = checksum;
 
 	return (size + 5);
 }
@@ -307,15 +274,10 @@ int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size)
 
 int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
 {
-	u8 *buf;
-
 	if ((offset + 2) >= WILC_MAX_CFG_FRAME_SIZE)
 		return 0;
 
-	buf = &frame[offset];
-
-	buf[0] = (u8)id;
-	buf[1] = (u8)(id >> 8);
+	put_unaligned_le16(id, &frame[offset]);
 
 	return 2;
 }
-- 
2.22.0





[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux