Skip to contentSkip to conversation

Janz ICAN3 build warnings

DISCUSSION Applied Oliver Hartkopp 3 participants 4 messages Jan 29, 2014 CAN network drivers

lore
Share & tools
lore
#0 lore raw

Hello Ira,

while addressing an issue with the skb->sk handling here

	http://marc.info/?l=linux-netdev&m=139100313304453&w=2

I was enabling the Janz ICAN3 driver to be built as I did a small change there too.

Can you please fix these build warnings below?

Regards,
Oliver

CC [M] drivers/net/can/janz-ican3.o
drivers/net/can/janz-ican3.c:1086:43: warning: ‘msg.data[6]’ may be used uninitialized in this function [-Wmaybe-uninitialized]

   mod->termination_enabled = msg->data[6] & HWCONF_TERMINATE_ON;
                                           ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘msg.data[6]’ was declared here
   struct ican3_msg msg;
                    ^
drivers/net/can/janz-ican3.c:1067:15: warning: ‘msg.data[5]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   cf->data[6] = txerr;
               ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘msg.data[5]’ was declared here
   struct ican3_msg msg;
                    ^
drivers/net/can/janz-ican3.c:1068:15: warning: ‘msg.data[4]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   cf->data[7] = rxerr;
               ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘msg.data[4]’ was declared here
   struct ican3_msg msg;
                    ^
drivers/net/can/janz-ican3.c:1014:21: warning: ‘msg.data[3]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   } else if (status & SR_ES) {
                     ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘msg.data[3]’ was declared here
   struct ican3_msg msg;
                    ^
drivers/net/can/janz-ican3.c:1045:13: warning: ‘msg.data[2]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (!(ecc & ECC_DIR))
             ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘msg.data[2]’ was declared here
   struct ican3_msg msg;
                    ^
drivers/net/can/janz-ican3.c:940:5: warning: ‘msg.data[1]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  if (msg->data[1] != CEVTIND_CHIP_SJA1000) {
     ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘msg.data[1]’ was declared here
   struct ican3_msg msg;
                    ^
drivers/net/can/janz-ican3.c:1025:5: warning: ‘*((void *)&msg+4)’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  if (isrc == CEVTIND_BEI) {
     ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘*((void *)&msg+4)’ was declared here
   struct ican3_msg msg;
                    ^
drivers/net/can/janz-ican3.c:1098:10: warning: ‘msg.len’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  dev_warn(mod->dev, "received unknown message: spec 0x%.2x length %d\n",
          ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘msg.len’ was declared here
   struct ican3_msg msg;
                    ^
drivers/net/can/janz-ican3.c:900:5: warning: ‘msg.spec’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  if (msg->spec == MSG_MSGLOST) {
     ^
drivers/net/can/janz-ican3.c:1320:20: note: ‘msg.spec’ was declared here
   struct ican3_msg msg;
                    ^
#1 lore raw

From 90dd8d23b90d837d8d2bc5d53d0319b15f1db5a8 Mon Sep 17 00:00:00 2001
From: "Ira W. Snyder" <[email protected]>
Date: Wed, 29 Jan 2014 09:51:48 -0800
Subject: [PATCH] can: janz-ican3: fix uninitialized variable warnings

Analysis of the code shows that the struct ican3_msg variable cannot be used uninitialized. Error conditions are checked and the loop terminates before calling the ican3_handle_message() function with an uninitialized value.

---

Hi Oliver, it looks like GCC is being stupid here. The loop obviously terminates before calling ican3_handle_message(). Do you agree?

I can't reproduce these warnings. Can you apply this patch and see if it fixes the problem for your compiler version? If so, go ahead and apply it.

Thanks,
Ira

 drivers/net/can/janz-ican3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/janz-ican3.c +1 -1
index e24e6690d672..07f0ba03cd59 100644
@@ -1322,7 +1322,7 @@ static int ican3_napi(struct napi_struct *napi, int budget)
 
 	/* process all communication messages */
 	while (true) {
-		struct ican3_msg msg;
+		struct ican3_msg uninitialized_var(msg);
 		ret = ican3_recv_msg(mod, &msg);
 		if (ret)
 			break;
Signature · 1 line
1.8.3.2
author Acked-by
#2 lore raw
Quoted 11 lines · Ira W. Snyder

From 90dd8d23b90d837d8d2bc5d53d0319b15f1db5a8 Mon Sep 17 00:00:00 2001
From: "Ira W. Snyder" <[email protected]>
Date: Wed, 29 Jan 2014 09:51:48 -0800
Subject: [PATCH] can: janz-ican3: fix uninitialized variable warnings

Analysis of the code shows that the struct ican3_msg variable cannot be used uninitialized. Error conditions are checked and the loop terminates before calling the ican3_handle_message() function with an uninitialized value.

Yes, that fixed it!

Thanks for your fast response!

Quoted 29 lines

---

Hi Oliver, it looks like GCC is being stupid here. The loop obviously terminates before calling ican3_handle_message(). Do you agree?

I can't reproduce these warnings. Can you apply this patch and see if it fixes the problem for your compiler version? If so, go ahead and apply it.

Thanks,
Ira

 drivers/net/can/janz-ican3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/janz-ican3.c +1 -1
index e24e6690d672..07f0ba03cd59 100644
@@ -1322,7 +1322,7 @@ static int ican3_napi(struct napi_struct *napi, int budget)
 
 	/* process all communication messages */
 	while (true) {
-		struct ican3_msg msg;
+		struct ican3_msg uninitialized_var(msg);
 		ret = ican3_recv_msg(mod, &msg);
 		if (ret)
 			break;
maintainer Applied
#3 lore raw
In reply to Ira W. Snyder
Quoted 11 lines · Ira W. Snyder

From 90dd8d23b90d837d8d2bc5d53d0319b15f1db5a8 Mon Sep 17 00:00:00 2001
From: "Ira W. Snyder" <[email protected]>
Date: Wed, 29 Jan 2014 09:51:48 -0800
Subject: [PATCH] can: janz-ican3: fix uninitialized variable warnings

Analysis of the code shows that the struct ican3_msg variable cannot be used uninitialized. Error conditions are checked and the loop terminates before calling the ican3_handle_message() function with an uninitialized value.

Applied to can/master.

Tnx,
Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |