netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net_sched: force endianness annotation
@ 2019-04-28  5:54 Nicholas Mc Guire
  2019-04-28 18:17 ` Cong Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nicholas Mc Guire @ 2019-04-28  5:54 UTC (permalink / raw)
  To: Jamal Hadi Salim
  Cc: Cong Wang, Jiri Pirko, David S. Miller, netdev, linux-kernel,
	Nicholas Mc Guire

While the endiannes is being handled correctly sparse was unhappy with
the missing annotation as be16_to_cpu()/be32_to_cpu() expects a __be16
respectively __be32. To mitigate this annotation issue forced annotation
is introduced. Note that this patch has no impact on the generated binary.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---

Problem located by an experimental cocci script to locate sparse annontation isues.
net/sched/em_cmp.c:44:31: warning: cast to restricted __be16
net/sched/em_cmp.c:44:31: warning: cast to restricted __be16
net/sched/em_cmp.c:44:31: warning: cast to restricted __be16
net/sched/em_cmp.c:44:31: warning: cast to restricted __be16
net/sched/em_cmp.c:54:31: warning: cast to restricted __be32
net/sched/em_cmp.c:54:31: warning: cast to restricted __be32
net/sched/em_cmp.c:54:31: warning: cast to restricted __be32
net/sched/em_cmp.c:54:31: warning: cast to restricted __be32
net/sched/em_cmp.c:54:31: warning: cast to restricted __be32
net/sched/em_cmp.c:54:31: warning: cast to restricted __be32

This is due to the variable being converted and thus the type is the
teget system type and it must be caset to __be16/__be32 here for sparse
to understand that endianness is adequately handled.

Patch was compile-tested with: x86_64_defconfig

Verification that the patch has no impact on the binary being generated
was done by diff on the binary before and after applying the patch.

Patch is against 5.1-rc6 (localversion-next is next-20190426)

 net/sched/em_cmp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/sched/em_cmp.c b/net/sched/em_cmp.c
index 1c8360a..3045ee1 100644
--- a/net/sched/em_cmp.c
+++ b/net/sched/em_cmp.c
@@ -41,7 +41,7 @@ static int em_cmp_match(struct sk_buff *skb, struct tcf_ematch *em,
 		val = get_unaligned_be16(ptr);
 
 		if (cmp_needs_transformation(cmp))
-			val = be16_to_cpu(val);
+			val = be16_to_cpu((__force __be16)val);
 		break;
 
 	case TCF_EM_ALIGN_U32:
@@ -51,7 +51,7 @@ static int em_cmp_match(struct sk_buff *skb, struct tcf_ematch *em,
 		val = get_unaligned_be32(ptr);
 
 		if (cmp_needs_transformation(cmp))
-			val = be32_to_cpu(val);
+			val = be32_to_cpu((__force __be32)val);
 		break;
 
 	default:
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-04-29 12:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-28  5:54 [PATCH] net_sched: force endianness annotation Nicholas Mc Guire
2019-04-28 18:17 ` Cong Wang
2019-04-29 10:11 ` Edward Cree
2019-04-29 10:44   ` Nicholas Mc Guire
2019-04-29 11:11     ` Edward Cree
2019-04-29 11:29       ` Nicholas Mc Guire
2019-04-29 12:09 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).