net: Fix the displayed value of bytes transferred
PATCH 1/1 net: Fix the displayed value of bytes transferred
In the case of NETLOOP_SUCCESS, the decimal value of the u32 variable "net_boot_file_size" is printed using "%d", resulting in negative values being reported for large file sizes. Fix this by using "%lu" to print the decimal value corresponding to the bytes transferred.
--- net/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/net.c +1 -1
@@ -716,7 +716,7 @@ restart:case NETLOOP_SUCCESS :net_cleanup_loop ();if (net_boot_file_size >0 ) { -printf ("Bytes transferred = %d (%x hex)\n" , +printf ("Bytes transferred = %lu (%x hex)\n" , net_boot_file_size, net_boot_file_size);env_set_hex ("filesize" , net_boot_file_size);env_set_hex ("fileaddr" , image_load_addr);
Signature · 1 line
2.34.1
Siddharth,
Quoted 16 lines · Siddharth Vadapalli
In the case of
NETLOOP_SUCCESS, the decimal value of the u32 variable "net_boot_file_size" is printed using "%d", resulting in negative values being reported for large file sizes. Fix this by using "%lu" to print the decimal value corresponding to the bytes transferred.Fixes 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")Signed-off-by Siddharth Vadapalli <[email protected]>--- net/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/net.c +0
-0
net/net.c restart: · line 719
Quoted 5 lines
net/net.c +1
-1@@ -716,7 +716,7 @@ restart:case NETLOOP_SUCCESS :net_cleanup_loop ();if (net_boot_file_size >0 ) { - printf("Bytes transferred = %d (%x hex)\n", + printf("Bytes transferred = %lu (%x hex)\n",
'net_boot_file_size' is of type u32. Using "%lu" will throw a warning for this. As per [0], format specifier for 'unsigned int' is "%d, %x'.
You could perhaps change the data type of 'net_boot_file_size' to 'ulong' as well.
[0] - https://u-boot.readthedocs.io/en/latest/develop/printf.html
Quoted 3 lines
net/net.c +0
-0net_boot_file_size, net_boot_file_size);env_set_hex ("filesize" , net_boot_file_size);env_set_hex ("fileaddr" , image_load_addr);
Signature · 2 lines
Regards, Ravi
Ravi,
Quoted 28 lines · Ravi Gunasekaran
Siddharth,
Quoted 16 lines · Siddharth Vadapalli
In the case of
NETLOOP_SUCCESS, the decimal value of the u32 variable "net_boot_file_size" is printed using "%d", resulting in negative values being reported for large file sizes. Fix this by using "%lu" to print the decimal value corresponding to the bytes transferred.Fixes 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")Signed-off-by Siddharth Vadapalli <[email protected]>--- net/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/net.c +0
-0net/net.c restart: · line 719
Quoted 5 lines
net/net.c +1
-1@@ -716,7 +716,7 @@ restart:case NETLOOP_SUCCESS :net_cleanup_loop ();if (net_boot_file_size >0 ) { - printf("Bytes transferred = %d (%x hex)\n", + printf("Bytes transferred = %lu (%x hex)\n",'
net_boot_file_size' is of type u32. Using "%lu" will throw a warning for this. As per [0], format specifier for 'unsigned int' is "%d, %x'.
Quoted 1 line
You could perhaps change the data type of '
net_boot_file_size' to 'ulong' as well.
The issue here isn't the size of the variable itself, but the format specifier. For large file sizes, the hex value printed for the variable is correct, but the decimal value is negative.
Quoted 7 lines
[0] - https://u-boot.readthedocs.io/en/latest/develop/printf.html
Quoted 3 lines
net/net.c +0
-0net_boot_file_size, net_boot_file_size);env_set_hex ("filesize" , net_boot_file_size);env_set_hex ("fileaddr" , image_load_addr);
Signature · 2 lines
Regards, Siddharth.
Quoted 31 lines · Siddharth Vadapalli
Ravi,
Quoted 28 lines · Ravi Gunasekaran
Siddharth,
Quoted 16 lines · Siddharth Vadapalli
In the case of
NETLOOP_SUCCESS, the decimal value of the u32 variable "net_boot_file_size" is printed using "%d", resulting in negative values being reported for large file sizes. Fix this by using "%lu" to print the decimal value corresponding to the bytes transferred.Fixes 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")Signed-off-by Siddharth Vadapalli <[email protected]>--- net/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/net.c +0
-0net/net.c restart: · line 719
Quoted 5 lines
net/net.c +1
-1@@ -716,7 +716,7 @@ restart:case NETLOOP_SUCCESS :net_cleanup_loop ();if (net_boot_file_size >0 ) { - printf("Bytes transferred = %d (%x hex)\n", + printf("Bytes transferred = %lu (%x hex)\n",'
net_boot_file_size' is of type u32. Using "%lu" will throw a warning for this. As per [0], format specifier for 'unsigned int' is "%d, %x'.
Quoted 8 lines
Quoted 1 line
You could perhaps change the data type of '
net_boot_file_size' to 'ulong' as well.The issue here isn't the size of the variable itself, but the format specifier. For large file sizes, the hex value printed for the variable is correct, but the decimal value is negative.
Quoted 2 lines
[0] - https://u-boot.readthedocs.io/en/latest/develop/printf.html
Uh, maybe I'm just missing something, but I think there's two things. First, this should be "%u" for "unsigned decimal". Second, doc/develop/printf.rst needs to be fixed since:
int %d, %x
unsigned int %d, %x
Should is wrong and should say %u, %x, because, well, that's what would be correct, yes?
Signature · 1 line
Tom
Hello Tom,
Quoted 41 lines · Tom Rini
Quoted 31 lines · Siddharth Vadapalli
Ravi,
Quoted 28 lines · Ravi Gunasekaran
Siddharth,
Quoted 16 lines · Siddharth Vadapalli
In the case of
NETLOOP_SUCCESS, the decimal value of the u32 variable "net_boot_file_size" is printed using "%d", resulting in negative values being reported for large file sizes. Fix this by using "%lu" to print the decimal value corresponding to the bytes transferred.Fixes 1411157d8578 ("net: cosmetic: Fixup var names related to boot file")Signed-off-by Siddharth Vadapalli <[email protected]>--- net/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/net.c +0
-0net/net.c restart: · line 719
Quoted 5 lines
net/net.c +1
-1@@ -716,7 +716,7 @@ restart:case NETLOOP_SUCCESS :net_cleanup_loop ();if (net_boot_file_size >0 ) { - printf("Bytes transferred = %d (%x hex)\n", + printf("Bytes transferred = %lu (%x hex)\n",'
net_boot_file_size' is of type u32. Using "%lu" will throw a warning for this. As per [0], format specifier for 'unsigned int' is "%d, %x'.Quoted 8 lines
Quoted 1 line
You could perhaps change the data type of '
net_boot_file_size' to 'ulong' as well.The issue here isn't the size of the variable itself, but the format specifier. For large file sizes, the hex value printed for the variable is correct, but the decimal value is negative.
Quoted 2 lines
[0] - https://u-boot.readthedocs.io/en/latest/develop/printf.html
Quoted 8 lines
Uh, maybe I'm just missing something, but I think there's two things. First, this should be "%u" for "unsigned decimal". Second,
doc/develop/printf.rstneeds to be fixed since:
int %d, %x
unsigned int %d, %xShould is wrong and should say %u, %x, because, well, that's what would be correct, yes?
Thank you for reviewing the patch. Yes, %u works well and can print u32 variable accurately. I tested it for 0xffffffff. %d prints -1 for the same. So, %lu isn't necessary and %u is sufficient. I will replace %lu with %u and post the v2 patch. Additionally, I will include a patch in the v2 series to update the Documentation as pointed out by you.
Quoted 1 line
Signature · 2 lines
Regards, Siddharth.
Quoted 7 lines · Siddharth Vadapalli
Hello Tom,
Quoted 4 lines · Tom Rini
Quoted 3 lines · Siddharth Vadapalli
Ravi,
On 10/08/23 17:00, Ravi Gunasekaran wrote:
...
Quoted 7 lines
Quoted 7 lines
Uh, maybe I'm just missing something, but I think there's two things. First, this should be "%u" for "unsigned decimal". Second,
doc/develop/printf.rstneeds to be fixed since:
int %d, %x
unsigned int %d, %x
Quoted 8 lines
Quoted 2 lines
Should is wrong and should say %u, %x, because, well, that's what would be correct, yes?
Thank you for reviewing the patch. Yes, %u works well and can print u32 variable accurately. I tested it for
0xffffffff. %d prints -1 for the same. So, %lu isn't necessary and %u is sufficient. I will replace %lu with %u and post the v2 patch. Additionally, I will include a patch in the v2 series to update the Documentation as pointed out by you.
I have posted the v2 series at:
https://patchwork.ozlabs.org/project/uboot/list/?series=368661&state=%2A&archive=both
Quoted 3 lines
Quoted 2 lines
Signature · 2 lines
Regards, Siddharth.