linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] net: qrtr: use protocol endiannes variable
@ 2019-05-11  0:56 Nicholas Mc Guire
  2019-05-11 17:02 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2019-05-11  0:56 UTC (permalink / raw)
  To: David S. Miller
  Cc: Arun Kumar Neelakantam, Greg Kroah-Hartman, Anshuman Khandual,
	David Hildenbrand, Arnd Bergmann, Johannes Berg, netdev,
	linux-kernel, Nicholas Mc Guire

sparse was unable to verify endiannes correctness due to reassignment
from le32_to_cpu to the same variable - fix this warning up by providing
a proper __le32 type and initializing it. This is not actually fixing
any bug - rather just addressing the sparse warning.

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

Problem located by an experimental coccinelle script to locate
patters that make sparse unhappy (false positives):

V2: Reorder variables to preserve reverse christmas tree ordering
    as requested by David Miller <davem@davemloft.net>.

sparse was unhappy about:
net/qrtr/qrtr.c:811:24: warning: cast to restricted __le32

The patch does change the binary - from inspection of the .lst files
it seems that the additional variable as well instruction reordering
constraints change the code even if the code-logic is the same.

Patch was compile-tested with: qcom_defconfig + QRTR=m
(with some unrelated warnings about not implemented system calls)

Patch is against 5.1 (localversion-next is next-20190510)

 net/qrtr/qrtr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index dd0e97f..801872a 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -728,12 +728,13 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 	DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
 	int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int,
 			  struct sockaddr_qrtr *, struct sockaddr_qrtr *);
+	__le32 qrtr_type = cpu_to_le32(QRTR_TYPE_DATA);
 	struct qrtr_sock *ipc = qrtr_sk(sock->sk);
 	struct sock *sk = sock->sk;
 	struct qrtr_node *node;
 	struct sk_buff *skb;
+	u32 type = 0;
 	size_t plen;
-	u32 type = QRTR_TYPE_DATA;
 	int rc;
 
 	if (msg->msg_flags & ~(MSG_DONTWAIT))
@@ -807,8 +808,8 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 		}
 
 		/* control messages already require the type as 'command' */
-		skb_copy_bits(skb, 0, &type, 4);
-		type = le32_to_cpu(type);
+		skb_copy_bits(skb, 0, &qrtr_type, 4);
+		type = le32_to_cpu(qrtr_type);
 	}
 
 	rc = enqueue_fn(node, skb, type, &ipc->us, addr);
-- 
2.1.4


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

* Re: [PATCH V2] net: qrtr: use protocol endiannes variable
  2019-05-11  0:56 [PATCH V2] net: qrtr: use protocol endiannes variable Nicholas Mc Guire
@ 2019-05-11 17:02 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-05-11 17:02 UTC (permalink / raw)
  To: hofrat
  Cc: aneela, gregkh, anshuman.khandual, david, arnd, johannes.berg,
	netdev, linux-kernel

From: Nicholas Mc Guire <hofrat@osadl.org>
Date: Sat, 11 May 2019 02:56:33 +0200

> sparse was unable to verify endiannes correctness due to reassignment
> from le32_to_cpu to the same variable - fix this warning up by providing
> a proper __le32 type and initializing it. This is not actually fixing
> any bug - rather just addressing the sparse warning.
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>

Applied.

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

end of thread, other threads:[~2019-05-11 17:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-11  0:56 [PATCH V2] net: qrtr: use protocol endiannes variable Nicholas Mc Guire
2019-05-11 17:02 ` David Miller

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).