Skip to contentSkip to conversation

net: phy: ncsi: Correct the endian of the checksum

PATCH In review Jacky Chou 3 participants 7 messages Feb 5, 2024 – Mar 28, 2024

Subsystems (2)
lore
Share & tools
lore

Jacky Chou

author
#0 lore raw

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
index eb3fd65bb4..74c5386d2e 100644
@@ -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
author Reviewed-by Dan Carpenter
#2 lore raw

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

________________________________
寄件者: 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.

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

#3 lore raw
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() 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

author
#4 lore raw
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() and htonl() functions have no effect on

big-endian platforms.

Quoted 8 lines
Quoted 1 line

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

#5 lore raw

Anyway, looks good! I already gave my reviewed by. Thanks for your work on this.

regards,
dan carpenter