net: phy: ncsi: Correct the endian of the checksum
Subsystems (2)
PATCH 1/1 net: phy: ncsi: Correct the endian of the checksum
There is no need to perform the endian twice here.
--- drivers/net/phy/ncsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/ncsi.c +1 -1
@@ -551,7 +551,7 @@ static int ncsi_send_command(unsigned int np, unsigned int nc, unsigned int cmd, checksum =ncsi_calculate_checksum ((unsigned char *)hdr,sizeof (*hdr) + len); pchecksum = (__be32 *)((void *)(hdr +1 ) + len); -put_unaligned_be32 (htonl (checksum), pchecksum); +put_unaligned_be32 (checksum, pchecksum);if (wait) {net_set_timeout_handler (1000UL , ncsi_timeout_handler);
Signature · 1 line
2.25.1
Quoted 3 lines · Jacky Chou
There is no need to perform the endian twice here.
Signed-off-by Jacky Chou <[email protected]>
How did this ever work? Was this always tested on big endian hardware or was nothing verifying the checksums?
regards,
dan carpenter
Jacky Chou
Reviewed-by Dan CarpenterHi Dan Carpenter,
I have verified it on the little-endian platform, such as ASPEED AST2600.
I think put_unaligned_be32() and htonl() functions have no effect on big-endian platforms. And keep put_unaligned_be32() to help access the unaligned memory, such as pchecksum variable.
Thanks,
Jacky
________________________________
寄件者: Dan Carpenter <[email protected]>
寄件日期: 2024年2月5日 下午 11:04
收件者: Jacky Chou <[email protected]>
副本: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; BMC-SW <[email protected]> 主旨: Re: [PATCH] net: phy: ncsi: Correct the endian of the checksum
Quoted 3 lines · Jacky Chou
There is no need to perform the endian twice here.
Signed-off-by Jacky Chou <[email protected]>
How did this ever work? Was this always tested on big endian hardware or was nothing verifying the checksums?
regards,
dan carpenter
Quoted 3 lines · Jacky Chou
Hi Dan Carpenter,
I have verified it on the little-endian platform, such as ASPEED AST2600.
Awesome. Thanks for this.
Quoted 2 lines
I think
put_unaligned_be32()andhtonl()functions have no effect on big-endian platforms. And keepput_unaligned_be32()to help access the unaligned memory, such as pchecksum variable.
Yes. I know that.
What I'm just puzzled by is how we ever merged this code when it doesn't work for little endian systems. How was it tested originally? How do the errors look like? Perhaps they're not as bad I assume from looking at the code...
regards,
dan carpenter
Quoted 9 lines · Jacky Chou
Quoted 3 lines
Hi Dan Carpenter,
I have verified it on the little-endian platform, such as ASPEED AST2600.
Awesome. Thanks for this.
Quoted 1 line
I think
put_unaligned_be32()andhtonl()functions have no effect onbig-endian platforms.
Quoted 8 lines
Quoted 1 line
And keep
put_unaligned_be32()to help access the unaligned memory, suchas pchecksum variable.
Yes. I know that.
What I'm just puzzled by is how we ever merged this code when it doesn't work for little endian systems. How was it tested originally? How do the errors look like? Perhaps they're not as bad I assume from looking at the code...
I am not sure how it was originally tested.
The first patch was based on Linux NC-SI driver.
I found the code in the Linux kernel where NC-SI calculates the checksum.
... /* Fill with calculated checksum */ checksum = ncsi_calculate_checksum((unsigned char *)h, sizeof(*h) + nca->payload); pchecksum = (__be32 *)((void *)h + sizeof(struct ncsi_pkt_hdr) + ALIGN(nca->payload, 4)); *pchecksum = htonl(checksum); ...
It gets the pointer of checksum field and call htonl() to do endian conversion. Linux NC-IS driver only performs endian conversion.
Thanks,
Jacky
Anyway, looks good! I already gave my reviewed by. Thanks for your work on this.
regards,
dan carpenter
Quoted 4 lines · Jacky Chou
There is no need to perform the endian twice here.
Signed-off-by Jacky Chou <[email protected]>Reviewed-by Dan Carpenter <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom