Skip to content

Commit 17d2ff4

Browse files
ArchitAnantgregkh
authored andcommitted
staging: rtl8723bs: use unaligned access macros in rtw_security.c
The driver defines custom functions secmicgetuint32() and secmicputuint32() to handle little-endian byte-to-integer conversion. This is redundant as the kernel provides optimized standard macros for this purpose in <linux/unaligned.h>. Replace the custom implementations with get_unaligned_le32() and put_unaligned_le32() and delete the now-unused local functions. Signed-off-by: Archit Anant <architanant5@gmail.com> Reviewed-by: Ethan Tidmore <ethantidmore06@gmail.com> Link: https://patch.msgid.link/20260130075113.34666-1-architanant5@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 02df7c6 commit 17d2ff4

1 file changed

Lines changed: 5 additions & 27 deletions

File tree

drivers/staging/rtl8723bs/core/rtw_security.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
******************************************************************************/
77
#include <linux/crc32.h>
8+
#include <linux/unaligned.h>
89
#include <drv_types.h>
910
#include <crypto/aes.h>
1011
#include <crypto/utils.h>
@@ -128,29 +129,6 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
128129

129130
/* 3 =====TKIP related ===== */
130131

131-
static u32 secmicgetuint32(u8 *p)
132-
/* Convert from Byte[] to Us3232 in a portable way */
133-
{
134-
s32 i;
135-
u32 res = 0;
136-
137-
for (i = 0; i < 4; i++)
138-
res |= ((u32)(*p++)) << (8 * i);
139-
140-
return res;
141-
}
142-
143-
static void secmicputuint32(u8 *p, u32 val)
144-
/* Convert from Us3232 to Byte[] in a portable way */
145-
{
146-
long i;
147-
148-
for (i = 0; i < 4; i++) {
149-
*p++ = (u8) (val & 0xff);
150-
val >>= 8;
151-
}
152-
}
153-
154132
static void secmicclear(struct mic_data *pmicdata)
155133
{
156134
/* Reset the state to the empty message. */
@@ -163,8 +141,8 @@ static void secmicclear(struct mic_data *pmicdata)
163141
void rtw_secmicsetkey(struct mic_data *pmicdata, u8 *key)
164142
{
165143
/* Set the key */
166-
pmicdata->K0 = secmicgetuint32(key);
167-
pmicdata->K1 = secmicgetuint32(key + 4);
144+
pmicdata->K0 = get_unaligned_le32(key);
145+
pmicdata->K1 = get_unaligned_le32(key + 4);
168146
/* and reset the message */
169147
secmicclear(pmicdata);
170148
}
@@ -212,8 +190,8 @@ void rtw_secgetmic(struct mic_data *pmicdata, u8 *dst)
212190
while (pmicdata->nBytesInM != 0)
213191
rtw_secmicappendbyte(pmicdata, 0);
214192
/* The appendByte function has already computed the result. */
215-
secmicputuint32(dst, pmicdata->L);
216-
secmicputuint32(dst + 4, pmicdata->R);
193+
put_unaligned_le32(pmicdata->L, dst);
194+
put_unaligned_le32(pmicdata->R, dst + 4);
217195
/* Reset to the empty message. */
218196
secmicclear(pmicdata);
219197
}

0 commit comments

Comments
 (0)