From 15dd9412027e06f8ce0046e7d8de84489a7f34cb Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Tue, 3 Aug 2021 12:12:38 +0200 Subject: [PATCH] arm: mach-snapdrgon: misc: Simplify msm_generate_mac_addr() The logic in msm_generate_mac_addr() was originally taken from the LK bootloader where the serial number is a string and must be parsed first. However, in U-Boot msm_board_serial() returns an u32 and msm_generate_mac_addr() has quite complicated code that will first print it as a hex string and then immediately parse it again. What this function actually does at the end is to put the serial number encoded as big endian (the order used for the hex string) into the u8 *mac. Use put_unaligned_be32() to do that with bit shifts instead of going through the string format. This should be slightly more efficient and cleaner but does not result in any functional difference. Cc: Ramon Fried Signed-off-by: Stephan Gerhold Reviewed-by: Ramon Fried --- arch/arm/mach-snapdragon/misc.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/arm/mach-snapdragon/misc.c b/arch/arm/mach-snapdragon/misc.c index fbd5f4d051..7d452f4529 100644 --- a/arch/arm/mach-snapdragon/misc.c +++ b/arch/arm/mach-snapdragon/misc.c @@ -9,6 +9,7 @@ #include #include #include +#include /* UNSTUFF_BITS macro taken from Linux Kernel: drivers/mmc/core/sd.c */ #define UNSTUFF_BITS(resp, start, size) \ @@ -41,16 +42,14 @@ u32 msm_board_serial(void) void msm_generate_mac_addr(u8 *mac) { - int i; - char sn[9]; - - snprintf(sn, 9, "%08x", msm_board_serial()); - - /* fill in the mac with serialno, use locally adminstrated pool */ + /* use locally adminstrated pool */ mac[0] = 0x02; - mac[1] = 00; - for (i = 3; i >= 0; i--) { - mac[i + 2] = hextoul(&sn[2 * i], NULL); - sn[2 * i] = 0; - } + mac[1] = 0x00; + + /* + * Put the 32-bit serial number in the last 32-bit of the MAC address. + * Use big endian order so it is consistent with the serial number + * written as a hexadecimal string, e.g. 0x1234abcd -> 02:00:12:34:ab:cd + */ + put_unaligned_be32(msm_board_serial(), &mac[2]); } -- 2.39.5