Skip to contentSkip to conversation

mach-snapdragon: Fix overwriting last digit of serial number

PATCH New Jan-Christoph Tebbe 2 participants 4 messages Mar 16, 2020 – Apr 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mach-snapdragon: Fix overwriting last digit of serial number

When generating the MAC address based on the boards serial number the last digit was overwritten with the null termination. That way boards with serial numbers close to each other would use the same MAC address.

---
 arch/arm/mach-snapdragon/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-snapdragon/misc.c +1 -1
index f6c87866c0..aaa561c2c6 100644
@@ -41,7 +41,7 @@ void msm_generate_mac_addr(u8 *mac)
  int i;
  char sn[9];
 
- snprintf(sn, 8, "%08x", msm_board_serial());
+ snprintf(sn, 9, "%08x", msm_board_serial());
 
  /* fill in the mac with serialno, use locally adminstrated pool */
  mac[0] = 0x02;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 mach-snapdragon: Fix overwriting last digit of serial number

Quoted 15 lines · Jan-Christoph Tebbe

When generating the MAC address based on the boards serial number the last digit was overwritten with the null termination. That way boards with serial numbers close to each other would use the same MAC address.

---
 arch/arm/mach-snapdragon/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-snapdragon/misc.c +0 -0
index f6c87866c0..aaa561c2c6 100644

arch/arm/mach-snapdragon/misc.c void msm_generate_mac_addr(u8 *mac) · line 47

Quoted 8 lines
arch/arm/mach-snapdragon/misc.c +1 -1
@@ -41,7 +41,7 @@ void msm_generate_mac_addr(u8 *mac)
  int i;
  char sn[9];
 
- snprintf(sn, 8, "%08x", msm_board_serial());
+ snprintf(sn, 9, "%08x", msm_board_serial());
 
  /* fill in the mac with serialno, use locally adminstrated pool */
  mac[0] = 0x02;

OK, so sn is size 9 and now you're filling the whole thing. Why don't we need to increase sn to size 10? Am I missing something? Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200320/5b24283c/attachment.sig>
#2 lore raw

PATCH 1/1 mach-snapdragon: Fix overwriting last digit of serial number

Hello Tom,

the buffer has to hold 8 hex digits and a trailing \0, therefore 9 bytes should be enough. The problem was, that snprintf was told sn were only 8 characters long, making snprintf to only write 7 digits followed by the trailing \0.

Jan-Christoph

Am Fr., 20. M?rz 2020 um 18:31 Uhr schrieb Tom Rini <[email protected]>:

Quoted 32 lines · Jan-Christoph Tebbe
Quoted 16 lines

When generating the MAC address based on the boards serial number the last digit was overwritten with the null termination. That way boards with serial numbers close to each other would use the same MAC address.

---
 arch/arm/mach-snapdragon/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-snapdragon/misc.c +0 -0
index f6c87866c0..aaa561c2c6 100644

arch/arm/mach-snapdragon/misc.c void msm_generate_mac_addr(u8 *mac) · line 47

Quoted 8 lines
arch/arm/mach-snapdragon/misc.c +1 -1
@@ -41,7 +41,7 @@ void msm_generate_mac_addr(u8 *mac)
  int i;
  char sn[9];
 
- snprintf(sn, 8, "%08x", msm_board_serial());
+ snprintf(sn, 9, "%08x", msm_board_serial());
 
  /* fill in the mac with serialno, use locally adminstrated pool */
  mac[0] = 0x02;

OK, so sn is size 9 and now you're filling the whole thing. Why don't we need to increase sn to size 10? Am I missing something? Thanks!

--
Tom

#3 lore raw

PATCH 1/1 mach-snapdragon: Fix overwriting last digit of serial number

In reply to Jan-Christoph Tebbe
Quoted 6 lines · Jan-Christoph Tebbe

When generating the MAC address based on the boards serial number the last digit was overwritten with the null termination. That way boards with serial numbers close to each other would use the same MAC address.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200405/d1578cd3/attachment.sig>