Message ID | 20240205080228.140001-1-jacky_chou@aspeedtech.com |
---|---|
State | Accepted |
Commit | 60d77b6f91f08d3be3b03d188c30c9b47e800a62 |
Delegated to: | Ramon Fried |
Headers | show |
Series | net: phy: ncsi: Correct the endian of the checksum | expand |
On Mon, Feb 05, 2024 at 04:02:28PM +0800, Jacky Chou wrote: > There is no need to perform the endian twice here. > > Signed-off-by: Jacky Chou <jacky_chou@aspeedtech.com> Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Fixes: f641a8ac93e0 ("phy: Add support for the NC-SI protocol") How did this ever work? Was this always tested on big endian hardware or was nothing verifying the checksums? regards, dan carpenter
Hi 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
On Sun, Mar 03, 2024 at 02:14:43AM +0000, Jacky Chou wrote: > Hi Dan Carpenter, > > I have verified it on the little-endian platform, such as ASPEED AST2600. Awesome. Thanks for this. > 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. 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
> On Sun, Mar 03, 2024 at 02:14:43AM +0000, Jacky Chou wrote: > > Hi Dan Carpenter, > > > > I have verified it on the little-endian platform, such as ASPEED AST2600. > > Awesome. Thanks for this. > > > 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. > > 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
On Mon, Feb 05, 2024 at 04:02:28PM +0800, Jacky Chou wrote: > There is no need to perform the endian twice here. > > Signed-off-by: Jacky Chou <jacky_chou@aspeedtech.com> > Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Applied to u-boot/next, thanks!
diff --git a/drivers/net/phy/ncsi.c b/drivers/net/phy/ncsi.c index eb3fd65bb4..74c5386d2e 100644 --- a/drivers/net/phy/ncsi.c +++ b/drivers/net/phy/ncsi.c @@ -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);
There is no need to perform the endian twice here. Signed-off-by: Jacky Chou <jacky_chou@aspeedtech.com> --- drivers/net/phy/ncsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)