net: thunderbolt: Fix for sparse warnings and typo
Subsystems (3)
cover net: thunderbolt: Fix for sparse warnings and typo
Hi,
The first patch should get rid of the sparse reported warnings that still exist in the driver. The second one is trivial fix for typo.
Mika Westerberg (2):
net: thunderbolt: Fix sparse warnings
net: thunderbolt: Fix typo in comment
drivers/net/thunderbolt/main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/2 net: thunderbolt: Fix sparse warnings
Fixes the following warnings when the driver is built with sparse checks enabled:
drivers/net/thunderbolt/main.c:767:47: warning: restricted __le32 degrades to integer drivers/net/thunderbolt/main.c:775:47: warning: restricted __le16 degrades to integer drivers/net/thunderbolt/main.c:776:44: warning: restricted __le16 degrades to integer drivers/net/thunderbolt/main.c:876:40: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:876:40: expected restricted __le32 [usertype] frame_sizedrivers/net/thunderbolt/main.c:876:40: got unsigned int [assigned] [usertype] frame_sizedrivers/net/thunderbolt/main.c:877:41: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:877:41: expected restricted __le32 [usertype] frame_countdrivers/net/thunderbolt/main.c:877:41: got unsigned int [usertype]drivers/net/thunderbolt/main.c:878:41: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:878:41: expected restricted __le16 [usertype] frame_indexdrivers/net/thunderbolt/main.c:878:41: got unsigned short [usertype]drivers/net/thunderbolt/main.c:879:38: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:879:38: expected restricted __le16 [usertype] frame_iddrivers/net/thunderbolt/main.c:879:38: got unsigned short [usertype]drivers/net/thunderbolt/main.c:880:62: warning: restricted __le32 degrades to integer drivers/net/thunderbolt/main.c:880:35: warning: restricted __le16 degrades to integer drivers/net/thunderbolt/main.c:993:23: warning: incorrect type in initializer (different base types)drivers/net/thunderbolt/main.c:993:23: expected restricted __wsum [usertype] wsumdrivers/net/thunderbolt/main.c:993:23: got restricted __be32 [usertype]
No functional changes intended.
--- drivers/net/thunderbolt/main.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/net/thunderbolt/main.c +12 -9
@@ -764,7 +764,7 @@ static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf,*/ if (net->skb && net->rx_hdr.frame_count) {/* Check the frame count fits the count field */ -if (frame_count != net->rx_hdr.frame_count) { +if (frame_count !=le32_to_cpu (net->rx_hdr.frame_count)) { net->stats.rx_length_errors++;return false; }
@@ -772,8 +772,8 @@ static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf,/* Check the frame identifiers are incremented correctly, * and id is matching. */ -if (frame_index != net->rx_hdr.frame_index +1 || - frame_id != net->rx_hdr.frame_id) { +if (frame_index !=le16_to_cpu (net->rx_hdr.frame_index) +1 || + frame_id !=le16_to_cpu (net->rx_hdr.frame_id)) { net->stats.rx_missed_errors++;return false; }
@@ -873,11 +873,12 @@ static int tbnet_poll(struct napi_struct *napi, int budget) TBNET_RX_PAGE_SIZE - hdr_size); } - net->rx_hdr.frame_size = frame_size; - net->rx_hdr.frame_count =le32_to_cpu (hdr->frame_count); - net->rx_hdr.frame_index =le16_to_cpu (hdr->frame_index); - net->rx_hdr.frame_id =le16_to_cpu (hdr->frame_id); - last = net->rx_hdr.frame_index == net->rx_hdr.frame_count -1 ; + net->rx_hdr.frame_size = hdr->frame_size; + net->rx_hdr.frame_count = hdr->frame_count; + net->rx_hdr.frame_index = hdr->frame_index; + net->rx_hdr.frame_id = hdr->frame_id; + last =le16_to_cpu (net->rx_hdr.frame_index) == +le32_to_cpu (net->rx_hdr.frame_count) -1 ; rx_packets++; net->stats.rx_bytes += frame_size;
@@ -990,8 +991,10 @@ static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb, {struct thunderbolt_ip_frame_header *hdr =page_address (frames[0 ]->page);struct device *dma_dev =tb_ring_dma_device (net->tx_ring.ring); -__wsum wsum =htonl (skb->len -skb_transport_offset (skb));unsigned int i, len, offset =skb_transport_offset (skb); +/* Remove payload length from checksum */ +u32 paylen = skb->len -skb_transport_offset (skb); +__wsum wsum = (__force __wsum )htonl (paylen);__be16 protocol = skb->protocol;void *data = skb->data;void *dest = hdr +1 ;
Signature · 1 line
2.39.2
Re: [PATCH 1/2] net: thunderbolt: Fix sparse warnings
Quoted 24 lines · Mika Westerberg
Fixes the following warnings when the driver is built with sparse checks enabled:
drivers/net/thunderbolt/main.c:767:47: warning: restricted__le32degrades to integerdrivers/net/thunderbolt/main.c:775:47: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:776:44: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:876:40: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:876:40: expected restricted__le32[usertype]frame_sizedrivers/net/thunderbolt/main.c:876:40: got unsigned int [assigned] [usertype]frame_sizedrivers/net/thunderbolt/main.c:877:41: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:877:41: expected restricted__le32[usertype]frame_countdrivers/net/thunderbolt/main.c:877:41: got unsigned int [usertype]drivers/net/thunderbolt/main.c:878:41: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:878:41: expected restricted__le16[usertype]frame_indexdrivers/net/thunderbolt/main.c:878:41: got unsigned short [usertype]drivers/net/thunderbolt/main.c:879:38: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:879:38: expected restricted__le16[usertype]frame_iddrivers/net/thunderbolt/main.c:879:38: got unsigned short [usertype]drivers/net/thunderbolt/main.c:880:62: warning: restricted__le32degrades to integerdrivers/net/thunderbolt/main.c:880:35: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:993:23: warning: incorrect type in initializer (different base types)drivers/net/thunderbolt/main.c:993:23: expected restricted__wsum[usertype] wsumdrivers/net/thunderbolt/main.c:993:23: got restricted__be32[usertype]
Quoted 3 lines
No functional changes intended.
Signed-off-by Mika Westerberg <[email protected]>
Re: [PATCH 1/2] net: thunderbolt: Fix sparse warnings
In reply to Mika WesterbergQuoted 15 lines · Mika Westerberg
Fixes the following warnings when the driver is built with sparse checks enabled:
drivers/net/thunderbolt/main.c:767:47: warning: restricted__le32degrades to integerdrivers/net/thunderbolt/main.c:775:47: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:776:44: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:876:40: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:876:40: expected restricted__le32[usertype]frame_sizedrivers/net/thunderbolt/main.c:876:40: got unsigned int [assigned] [usertype]frame_sizedrivers/net/thunderbolt/main.c:877:41: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:877:41: expected restricted__le32[usertype]frame_countdrivers/net/thunderbolt/main.c:877:41: got unsigned int [usertype]drivers/net/thunderbolt/main.c:878:41: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:878:41: expected restricted__le16[usertype]frame_indexdrivers/net/thunderbolt/main.c:878:41: got unsigned short [usertype]
Quoted 8 lines
drivers/net/thunderbolt/main.c:879:38: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:879:38: expected restricted__le16[usertype]frame_iddrivers/net/thunderbolt/main.c:879:38: got unsigned short [usertype]drivers/net/thunderbolt/main.c:880:62: warning: restricted__le32degrades to integerdrivers/net/thunderbolt/main.c:880:35: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:993:23: warning: incorrect type in initializer (different base types)drivers/net/thunderbolt/main.c:993:23: expected restricted__wsum[usertype] wsumdrivers/net/thunderbolt/main.c:993:23: got restricted__be32[usertype]
You can drop the whole part with file name and line numbers to make the above neater.
Quoted 51 lines
No functional changes intended.
Signed-off-by Mika Westerberg <[email protected]>--- drivers/net/thunderbolt/main.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)drivers/net/thunderbolt/main.c +9
-8@@ -764,7 +764,7 @@ static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf,*/ if (net->skb && net->rx_hdr.frame_count) {/* Check the frame count fits the count field */ -if (frame_count != net->rx_hdr.frame_count) { +if (frame_count !=le32_to_cpu (net->rx_hdr.frame_count)) { net->stats.rx_length_errors++;return false; }@@ -772,8 +772,8 @@ static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf,/* Check the frame identifiers are incremented correctly, * and id is matching. */ -if (frame_index != net->rx_hdr.frame_index +1 || - frame_id != net->rx_hdr.frame_id) { +if (frame_index !=le16_to_cpu (net->rx_hdr.frame_index) +1 || + frame_id !=le16_to_cpu (net->rx_hdr.frame_id)) { net->stats.rx_missed_errors++;return false; }@@ -873,11 +873,12 @@ static int tbnet_poll(struct napi_struct *napi, int budget) TBNET_RX_PAGE_SIZE - hdr_size); } - net->rx_hdr.frame_size = frame_size; - net->rx_hdr.frame_count =le32_to_cpu (hdr->frame_count); - net->rx_hdr.frame_index =le16_to_cpu (hdr->frame_index); - net->rx_hdr.frame_id =le16_to_cpu (hdr->frame_id); - last = net->rx_hdr.frame_index == net->rx_hdr.frame_count -1 ; + net->rx_hdr.frame_size = hdr->frame_size; + net->rx_hdr.frame_count = hdr->frame_count; + net->rx_hdr.frame_index = hdr->frame_index; + net->rx_hdr.frame_id = hdr->frame_id; + last =le16_to_cpu (net->rx_hdr.frame_index) == +le32_to_cpu (net->rx_hdr.frame_count) -1 ; rx_packets++; net->stats.rx_bytes += frame_size;@@ -990,8 +991,10 @@ static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb, {
drivers/net/thunderbolt/main.c static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb, · line 1000
Quoted 10 lines
drivers/net/thunderbolt/main.c +3
-1struct thunderbolt_ip_frame_header *hdr =page_address (frames[0 ]->page);struct device *dma_dev =tb_ring_dma_device (net->tx_ring.ring); -__wsum wsum =htonl (skb->len -skb_transport_offset (skb));unsigned int i, len, offset =skb_transport_offset (skb); +/* Remove payload length from checksum */ +u32 paylen = skb->len -skb_transport_offset (skb); +__wsum wsum = (__force __wsum )htonl (paylen);__be16 protocol = skb->protocol;void *data = skb->data;void *dest = hdr +1 ;
I would split wsum fix from the above as they are of different nature.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/2] net: thunderbolt: Fix sparse warnings
Hi Andy,
Quoted 25 lines · Andy Shevchenko
Quoted 15 lines · Mika Westerberg
Fixes the following warnings when the driver is built with sparse checks enabled:
drivers/net/thunderbolt/main.c:767:47: warning: restricted__le32degrades to integerdrivers/net/thunderbolt/main.c:775:47: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:776:44: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:876:40: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:876:40: expected restricted__le32[usertype]frame_sizedrivers/net/thunderbolt/main.c:876:40: got unsigned int [assigned] [usertype]frame_sizedrivers/net/thunderbolt/main.c:877:41: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:877:41: expected restricted__le32[usertype]frame_countdrivers/net/thunderbolt/main.c:877:41: got unsigned int [usertype]drivers/net/thunderbolt/main.c:878:41: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:878:41: expected restricted__le16[usertype]frame_indexdrivers/net/thunderbolt/main.c:878:41: got unsigned short [usertype]Quoted 8 lines
drivers/net/thunderbolt/main.c:879:38: warning: incorrect type in assignment (different base types)drivers/net/thunderbolt/main.c:879:38: expected restricted__le16[usertype]frame_iddrivers/net/thunderbolt/main.c:879:38: got unsigned short [usertype]drivers/net/thunderbolt/main.c:880:62: warning: restricted__le32degrades to integerdrivers/net/thunderbolt/main.c:880:35: warning: restricted__le16degrades to integerdrivers/net/thunderbolt/main.c:993:23: warning: incorrect type in initializer (different base types)drivers/net/thunderbolt/main.c:993:23: expected restricted__wsum[usertype] wsumdrivers/net/thunderbolt/main.c:993:23: got restricted__be32[usertype]
Quoted 2 lines
You can drop the whole part with file name and line numbers to make the above neater.
I guess it is good to leave the filename, there like this, no?
main.c:993:23: expected restricted __wsum [usertype] wsum
main.c:993:23: got restricted __be32 [usertype]
Quoted 47 lines
Quoted 47 lines
No functional changes intended.
Signed-off-by Mika Westerberg <[email protected]>--- drivers/net/thunderbolt/main.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)drivers/net/thunderbolt/main.c +9
-8@@ -764,7 +764,7 @@ static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf,*/ if (net->skb && net->rx_hdr.frame_count) {/* Check the frame count fits the count field */ -if (frame_count != net->rx_hdr.frame_count) { +if (frame_count !=le32_to_cpu (net->rx_hdr.frame_count)) { net->stats.rx_length_errors++;return false; }@@ -772,8 +772,8 @@ static bool tbnet_check_frame(struct tbnet *net, const struct tbnet_frame *tf,/* Check the frame identifiers are incremented correctly, * and id is matching. */ -if (frame_index != net->rx_hdr.frame_index +1 || - frame_id != net->rx_hdr.frame_id) { +if (frame_index !=le16_to_cpu (net->rx_hdr.frame_index) +1 || + frame_id !=le16_to_cpu (net->rx_hdr.frame_id)) { net->stats.rx_missed_errors++;return false; }@@ -873,11 +873,12 @@ static int tbnet_poll(struct napi_struct *napi, int budget) TBNET_RX_PAGE_SIZE - hdr_size); } - net->rx_hdr.frame_size = frame_size; - net->rx_hdr.frame_count =le32_to_cpu (hdr->frame_count); - net->rx_hdr.frame_index =le16_to_cpu (hdr->frame_index); - net->rx_hdr.frame_id =le16_to_cpu (hdr->frame_id); - last = net->rx_hdr.frame_index == net->rx_hdr.frame_count -1 ; + net->rx_hdr.frame_size = hdr->frame_size; + net->rx_hdr.frame_count = hdr->frame_count; + net->rx_hdr.frame_index = hdr->frame_index; + net->rx_hdr.frame_id = hdr->frame_id; + last =le16_to_cpu (net->rx_hdr.frame_index) == +le32_to_cpu (net->rx_hdr.frame_count) -1 ;
Quoted 16 lines
Quoted 4 lines
drivers/net/thunderbolt/main.c +0
-0rx_packets++; net->stats.rx_bytes += frame_size;@@ -990,8 +991,10 @@ static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb, {drivers/net/thunderbolt/main.c static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb, · line 1000
Quoted 10 lines
drivers/net/thunderbolt/main.c +3
-1struct thunderbolt_ip_frame_header *hdr =page_address (frames[0 ]->page);struct device *dma_dev =tb_ring_dma_device (net->tx_ring.ring); -__wsum wsum =htonl (skb->len -skb_transport_offset (skb));unsigned int i, len, offset =skb_transport_offset (skb); +/* Remove payload length from checksum */ +u32 paylen = skb->len -skb_transport_offset (skb); +__wsum wsum = (__force __wsum )htonl (paylen);__be16 protocol = skb->protocol;void *data = skb->data;void *dest = hdr +1 ;I would split wsum fix from the above as they are of different nature.
How they are different? The complain is pretty much the same for all these AFAICT:
expected restricted xxx [usertype] yyy
got restricted zzz [usertype]
Re: [PATCH 1/2] net: thunderbolt: Fix sparse warnings
Quoted 2 lines · Mika Westerberg
Quoted 1 line · Andy Shevchenko
On Tue, Apr 04, 2023 at 08:36:35AM +0300, Mika Westerberg wrote:
...
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
drivers/net/thunderbolt/main.c:993:23: expected restricted__wsum[usertype] wsumdrivers/net/thunderbolt/main.c:993:23: got restricted__be32[usertype]You can drop the whole part with file name and line numbers to make the above neater.
I guess it is good to leave the filename, there like this, no?
main.c:993:23: expected restricted
__wsum[usertype] wsum
main.c:993:23: got restricted__be32[usertype]
Fine by me.
...
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/thunderbolt/main.c +6
-0+ net->rx_hdr.frame_size = hdr->frame_size; + net->rx_hdr.frame_count = hdr->frame_count; + net->rx_hdr.frame_index = hdr->frame_index; + net->rx_hdr.frame_id = hdr->frame_id; + last =le16_to_cpu (net->rx_hdr.frame_index) == +le32_to_cpu (net->rx_hdr.frame_count) -1 ;
...
Quoted 7 lines
Quoted 6 lines
drivers/net/thunderbolt/main.c static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb, · line 997
Quoted 4 lines
drivers/net/thunderbolt/main.c +3
-1-__wsum wsum =htonl (skb->len -skb_transport_offset (skb)); +/* Remove payload length from checksum */ +u32 paylen = skb->len -skb_transport_offset (skb); +__wsum wsum = (__force __wsum )htonl (paylen);I would split wsum fix from the above as they are of different nature.
Quoted 5 lines
How they are different? The complain is pretty much the same for all these AFAICT:
expected restricted xxx [usertype] yyy
got restricted zzz [usertype]
While the main part is about header data type and endianess conversion between protocol and CPU (with cpu_*() and *_cpu() macros) this one is completely network related stuff as it's using hton*() and ntoh*() conversion macros. Yes, underneeth it may be the same, but semantically these two parts are not of the same thing.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/2] net: thunderbolt: Fix sparse warnings
Quoted 10 lines · Andy Shevchenko
Quoted 5 lines
How they are different? The complain is pretty much the same for all these AFAICT:
expected restricted xxx [usertype] yyy
got restricted zzz [usertype]While the main part is about header data type and endianess conversion between protocol and CPU (with cpu_*() and
*_cpu()macros) this one is completely network related stuff as it's using hton*() and ntoh*() conversion macros. Yes, underneeth it may be the same, but semantically these two parts are not of the same thing.
Okay, fair enough :) I'll make this split in v2.
PATCH 2/2 net: thunderbolt: Fix typo in comment
In reply to Mika WesterbergShould be UDP not UPD. No functional changes.
--- drivers/net/thunderbolt/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/thunderbolt/main.c +1 -1
@@ -1030,7 +1030,7 @@ static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb,/* Data points on the beginning of packet. * Check is the checksum absolute place in the packet. * ipcso will update IP checksum. -* tucso will update TCP/UPD checksum. +* tucso will update TCP/UDP checksum. */ if (protocol ==htons (ETH_P_IP )) {__sum16 *ipcso = dest + ((void *)&(ip_hdr (skb)->check) - data);
Signature · 1 line
2.39.2
Re: [PATCH 2/2] net: thunderbolt: Fix typo in comment
Quoted 3 lines · Mika Westerberg
Should be UDP not UPD. No functional changes.
Signed-off-by Mika Westerberg <[email protected]>
Looks good,
codespell tells me you also may want to consider:
$ codespell drivers/net/thunderbolt/main.c drivers/net/thunderbolt/main.c:151: blongs ==> belongs
Quoted 20 lines
--- drivers/net/thunderbolt/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/thunderbolt/main.c +1
-1@@ -1030,7 +1030,7 @@ static bool tbnet_xmit_csum_and_map(struct tbnet *net, struct sk_buff *skb,/* Data points on the beginning of packet. * Check is the checksum absolute place in the packet. * ipcso will update IP checksum. -* tucso will update TCP/UPD checksum. +* tucso will update TCP/UDP checksum. */ if (protocol ==htons (ETH_P_IP )) {__sum16 *ipcso = dest + ((void *)&(ip_hdr (skb)->check) - data);Signature · 1 line
2.39.2
Quoted 4 lines · Mika Westerberg
Hi,
The first patch should get rid of the sparse reported warnings that still exist in the driver. The second one is trivial fix for typo.
Thank you, I believe v2 is needed which will look good with addressed Simon's and my comments. Taking this into account,
Quoted 3 lines
Mika Westerberg (2):
net: thunderbolt: Fix sparse warnings
net: thunderbolt: Fix typo in comment
Signature · 2 lines
With Best Regards, Andy Shevchenko